Report diagnostics at the actually actionable site
This commit is contained in:
parent
e237aaef25
commit
59e285ff34
5 changed files with 43 additions and 21 deletions
|
@ -2314,7 +2314,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
&self,
|
||||
generic_param_scope: LocalDefId,
|
||||
span: Span,
|
||||
mut origin: Option<SubregionOrigin<'tcx>>,
|
||||
origin: Option<SubregionOrigin<'tcx>>,
|
||||
bound_kind: GenericKind<'tcx>,
|
||||
sub: Region<'tcx>,
|
||||
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
|
||||
|
@ -2349,14 +2349,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
None
|
||||
}
|
||||
}
|
||||
GenericKind::Opaque(def_id, _substs) => {
|
||||
// Avoid emitting a `... so that the type` message at the error site.
|
||||
// It would be out of order for return position impl trait
|
||||
origin = None;
|
||||
// Make sure the lifetime suggestion is on the RPIT instead of proposing
|
||||
// to add a bound for opaque types (which isn't possible)
|
||||
Some((self.tcx.def_span(def_id).shrink_to_hi(), true))
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
|
||||
|
|
|
@ -336,6 +336,7 @@ where
|
|||
GenericKind::Opaque(def_id, substs),
|
||||
def_id,
|
||||
substs,
|
||||
true,
|
||||
|ty| match *ty.kind() {
|
||||
ty::Opaque(def_id, substs) => (def_id, substs),
|
||||
_ => bug!("expected only projection types from env, not {:?}", ty),
|
||||
|
@ -356,6 +357,7 @@ where
|
|||
GenericKind::Projection(projection_ty),
|
||||
projection_ty.item_def_id,
|
||||
projection_ty.substs,
|
||||
false,
|
||||
|ty| match ty.kind() {
|
||||
ty::Projection(projection_ty) => (projection_ty.item_def_id, projection_ty.substs),
|
||||
_ => bug!("expected only projection types from env, not {:?}", ty),
|
||||
|
@ -371,6 +373,7 @@ where
|
|||
generic: GenericKind<'tcx>,
|
||||
def_id: DefId,
|
||||
substs: SubstsRef<'tcx>,
|
||||
is_opaque: bool,
|
||||
filter: impl Fn(Ty<'tcx>) -> (DefId, SubstsRef<'tcx>),
|
||||
) {
|
||||
// An optimization for a common case with opaque types.
|
||||
|
@ -437,7 +440,7 @@ where
|
|||
// inference variables, we use a verify constraint instead of adding
|
||||
// edges, which winds up enforcing the same condition.
|
||||
let needs_infer = substs.needs_infer();
|
||||
if approx_env_bounds.is_empty() && trait_bounds.is_empty() && needs_infer {
|
||||
if approx_env_bounds.is_empty() && trait_bounds.is_empty() && (needs_infer || is_opaque) {
|
||||
debug!("no declared bounds");
|
||||
|
||||
self.substs_must_outlive(substs, origin, region);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue