diff --git a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs index f0331c006d05..98d287513b90 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs @@ -640,7 +640,9 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { let mut parent = tcx.parent(def_id); debug!(?def_id, ?parent); let trait_preds = match tcx.def_kind(parent) { - hir::def::DefKind::Impl { .. } => &[], + hir::def::DefKind::Impl { .. } => { + tcx.trait_id_of_impl(parent).map_or(&[][..], |id| tcx.predicates_of(id).predicates) + } hir::def::DefKind::Trait => { let Some(ty) = args.get(0).and_then(|arg| arg.as_type()) else { return; diff --git a/tests/ui/lifetimes/static-impl-obligation.rs b/tests/ui/lifetimes/static-impl-obligation.rs index 585a6328ca8c..69178a7375f6 100644 --- a/tests/ui/lifetimes/static-impl-obligation.rs +++ b/tests/ui/lifetimes/static-impl-obligation.rs @@ -272,8 +272,8 @@ mod w { } fn convert<'a>(x: &'a &'a u32) { - let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough - y.hello(); + let y: &dyn Foo = x; + y.hello(); //~ ERROR lifetime may not live long enough } } fn main() {} diff --git a/tests/ui/lifetimes/static-impl-obligation.stderr b/tests/ui/lifetimes/static-impl-obligation.stderr index a84956b08b3a..0eba240eb51d 100644 --- a/tests/ui/lifetimes/static-impl-obligation.stderr +++ b/tests/ui/lifetimes/static-impl-obligation.stderr @@ -438,12 +438,20 @@ LL | impl Trait for dyn Foo + '_ { | ++++ error: lifetime may not live long enough - --> $DIR/static-impl-obligation.rs:275:27 + --> $DIR/static-impl-obligation.rs:276:9 | LL | fn convert<'a>(x: &'a &'a u32) { | -- lifetime `'a` defined here LL | let y: &dyn Foo = x; - | ^ cast requires that `'a` must outlive `'static` + | - cast requires that `'a` must outlive `'static` +LL | y.hello(); + | ^^^^^^^^^ calling this method introduces a `'static` lifetime requirement + | +note: the `impl` on `dyn w::Foo` has a `'static` lifetime requirement + --> $DIR/static-impl-obligation.rs:268:29 + | +LL | trait Trait where Self: 'static { fn hello(&self) {} } + | ^^^^^^^ error: aborting due to 25 previous errors