Skip to content

Commit

Permalink
Remove FIXME after rebase and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Mar 20, 2024
1 parent 014daaa commit 8766658
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
6 changes: 0 additions & 6 deletions compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,12 +675,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
if self.to_error_region(outlived_fr) != Some(tcx.lifetimes.re_static) {
return;
}
// FIXME: there's a case that's yet to be handled: `impl dyn Trait + '_ where Self: '_`
// causes *two* errors to be produded, one about `where Self: '_` not being allowed,
// and the regular error with no additional information about "lifetime may not live
// long enough for `'static`" without mentioning where it came from. This is because
// our error recovery fallback is indeed `ReStatic`. We should at some point introduce
// a `ReError` instead to avoid this and other similar issues.

// Look for `'static` bounds in the generics of the method and the `impl`.
// ```
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/lifetimes/static-impl-obligation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,16 @@ mod w {
y.hello(); //~ ERROR lifetime may not live long enough
}
}
mod x {
trait Foo {}
impl<'a> Foo for &'a u32 {}
impl dyn Foo + '_ where Self: '_ { //~ ERROR `'_` cannot be used here
fn hello(&self) {}

}
fn convert<'a>(x: &'a &'a u32) {
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough
y.hello();
}
}
fn main() {}
18 changes: 16 additions & 2 deletions tests/ui/lifetimes/static-impl-obligation.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
error[E0637]: `'_` cannot be used here
--> $DIR/static-impl-obligation.rs:282:35
|
LL | impl dyn Foo + '_ where Self: '_ {
| ^^ `'_` is a reserved lifetime name

error[E0478]: lifetime bound not satisfied
--> $DIR/static-impl-obligation.rs:222:10
|
Expand Down Expand Up @@ -453,7 +459,15 @@ note: the `impl` on `dyn w::Foo` has a `'static` lifetime requirement
LL | trait Trait where Self: 'static { fn hello(&self) {} }
| ^^^^^^^

error: aborting due to 25 previous errors
error: lifetime may not live long enough
--> $DIR/static-impl-obligation.rs:287:27
|
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`

error: aborting due to 27 previous errors

Some errors have detailed explanations: E0478, E0521.
Some errors have detailed explanations: E0478, E0521, E0637.
For more information about an error, try `rustc --explain E0478`.

0 comments on commit 8766658

Please sign in to comment.