diff --git a/compiler/rustc_trait_selection/src/traits/outlives_bounds.rs b/compiler/rustc_trait_selection/src/traits/outlives_bounds.rs index 64be4a55708..5b8d9e7f0f7 100644 --- a/compiler/rustc_trait_selection/src/traits/outlives_bounds.rs +++ b/compiler/rustc_trait_selection/src/traits/outlives_bounds.rs @@ -56,11 +56,12 @@ impl<'a, 'tcx: 'a> InferCtxtExt<'a, 'tcx> for InferCtxt<'tcx> { let ty = self.resolve_vars_if_possible(ty); let ty = OpportunisticRegionResolver::new(self).fold_ty(ty); - // We must avoid processing constrained lifetime variables in implied + // We must avoid processing unconstrained lifetime variables in implied // bounds. See #110161 for context. + assert!(!ty.has_non_region_infer()); if ty.needs_infer() { self.tcx.sess.delay_span_bug( - self.tcx.source_span_untracked(body_id), + self.tcx.def_span(body_id), "skipped implied_outlives_bounds due to unconstrained lifetimes", ); return vec![]; diff --git a/tests/ui/implied-bounds/issue-110161.rs b/tests/ui/implied-bounds/issue-110161.rs index ca75026ffe8..e52c8356b52 100644 --- a/tests/ui/implied-bounds/issue-110161.rs +++ b/tests/ui/implied-bounds/issue-110161.rs @@ -3,22 +3,24 @@ // compile-flags: --crate-type=lib -trait Trait { +trait LtTrait { type Ty; } // erroneous `Ty` impl -impl Trait for () { +impl LtTrait for () { //~^ ERROR not all trait items implemented, missing: `Ty` [E0046] } // `'lt` is not constrained by the erroneous `Ty` -impl<'lt, T> Trait for Box +impl<'lt, T> LtTrait for Box where - T: Trait, + T: LtTrait, { type Ty = &'lt (); } // unconstrained lifetime appears in implied bounds -fn test(_: as Trait>::Ty) {} +fn test(_: as LtTrait>::Ty) {} + +fn test2<'x>(_: &'x as LtTrait>::Ty) {} diff --git a/tests/ui/implied-bounds/issue-110161.stderr b/tests/ui/implied-bounds/issue-110161.stderr index c76b4737626..9e0188694ed 100644 --- a/tests/ui/implied-bounds/issue-110161.stderr +++ b/tests/ui/implied-bounds/issue-110161.stderr @@ -4,8 +4,8 @@ error[E0046]: not all trait items implemented, missing: `Ty` LL | type Ty; | ------- `Ty` from trait ... -LL | impl Trait for () { - | ^^^^^^^^^^^^^^^^^ missing `Ty` in implementation +LL | impl LtTrait for () { + | ^^^^^^^^^^^^^^^^^^^ missing `Ty` in implementation error: aborting due to previous error