Skip to content

Commit

Permalink
Always look at the trait bounds (not just when looking at a trait `De…
Browse files Browse the repository at this point in the history
…fId`)
  • Loading branch information
estebank committed Feb 21, 2024
1 parent 6192d40 commit 2a75eb8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
4 changes: 3 additions & 1 deletion compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/lifetimes/static-impl-obligation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
12 changes: 10 additions & 2 deletions tests/ui/lifetimes/static-impl-obligation.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 2a75eb8

Please sign in to comment.