Auto merge of #89862 - lcnr:path-generics-diagnostics, r=estebank
rewrite error handling for unresolved inference vars Pretty much completely rewrites `fn emit_inference_failure_err`. This new setup should hopefully be easier to extend and is already a lot better when looking for generic arguments. Because this is a rewrite there are still some parts which are lacking, these are tracked in #94483 and will be fixed in later PRs. r? `@estebank` `@petrochenkov`
This commit is contained in:
commit
e40d5e83dc
124 changed files with 2139 additions and 1488 deletions
|
@ -983,7 +983,11 @@ impl<'hir> Map<'hir> {
|
|||
Node::AnonConst(constant) => self.body(constant.body).value.span,
|
||||
Node::Expr(expr) => expr.span,
|
||||
Node::Stmt(stmt) => stmt.span,
|
||||
Node::PathSegment(seg) => seg.ident.span,
|
||||
Node::PathSegment(seg) => {
|
||||
let ident_span = seg.ident.span;
|
||||
ident_span
|
||||
.with_hi(seg.args.map_or_else(|| ident_span.hi(), |args| args.span_ext.hi()))
|
||||
}
|
||||
Node::Ty(ty) => ty.span,
|
||||
Node::TraitRef(tr) => tr.path.span,
|
||||
Node::Binding(pat) => pat.span,
|
||||
|
|
|
@ -63,6 +63,29 @@ impl GenericParamDef {
|
|||
bug!("cannot convert a non-lifetime parameter def to an early bound region")
|
||||
}
|
||||
}
|
||||
|
||||
pub fn has_default(&self) -> bool {
|
||||
match self.kind {
|
||||
GenericParamDefKind::Type { has_default, .. }
|
||||
| GenericParamDefKind::Const { has_default } => has_default,
|
||||
GenericParamDefKind::Lifetime => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn default_value<'tcx>(
|
||||
&self,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
) -> Option<EarlyBinder<ty::GenericArg<'tcx>>> {
|
||||
match self.kind {
|
||||
GenericParamDefKind::Type { has_default, .. } if has_default => {
|
||||
Some(EarlyBinder(tcx.type_of(self.def_id).into()))
|
||||
}
|
||||
GenericParamDefKind::Const { has_default } if has_default => {
|
||||
Some(EarlyBinder(tcx.const_param_default(self.def_id).into()))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
@ -204,6 +227,12 @@ impl<'tcx> Generics {
|
|||
matches!(param.kind, ty::GenericParamDefKind::Type { synthetic: true, .. })
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns the substs corresponding to the generic parameters of this item, excluding `Self`.
|
||||
pub fn own_substs(&'tcx self, substs: SubstsRef<'tcx>) -> &'tcx [ty::GenericArg<'tcx>] {
|
||||
let own = &substs[self.parent_count..][..self.params.len()];
|
||||
if self.has_self && self.parent.is_none() { &own[1..] } else { &own }
|
||||
}
|
||||
}
|
||||
|
||||
/// Bounds on generics.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue