Skip to content

Commit 8766658

Browse files
committed
Remove FIXME after rebase and add test
1 parent 014daaa commit 8766658

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

-6
Original file line numberDiff line numberDiff line change
@@ -675,12 +675,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
675675
if self.to_error_region(outlived_fr) != Some(tcx.lifetimes.re_static) {
676676
return;
677677
}
678-
// FIXME: there's a case that's yet to be handled: `impl dyn Trait + '_ where Self: '_`
679-
// causes *two* errors to be produded, one about `where Self: '_` not being allowed,
680-
// and the regular error with no additional information about "lifetime may not live
681-
// long enough for `'static`" without mentioning where it came from. This is because
682-
// our error recovery fallback is indeed `ReStatic`. We should at some point introduce
683-
// a `ReError` instead to avoid this and other similar issues.
684678

685679
// Look for `'static` bounds in the generics of the method and the `impl`.
686680
// ```

tests/ui/lifetimes/static-impl-obligation.rs

+12
Original file line numberDiff line numberDiff line change
@@ -276,4 +276,16 @@ mod w {
276276
y.hello(); //~ ERROR lifetime may not live long enough
277277
}
278278
}
279+
mod x {
280+
trait Foo {}
281+
impl<'a> Foo for &'a u32 {}
282+
impl dyn Foo + '_ where Self: '_ { //~ ERROR `'_` cannot be used here
283+
fn hello(&self) {}
284+
285+
}
286+
fn convert<'a>(x: &'a &'a u32) {
287+
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough
288+
y.hello();
289+
}
290+
}
279291
fn main() {}

tests/ui/lifetimes/static-impl-obligation.stderr

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
error[E0637]: `'_` cannot be used here
2+
--> $DIR/static-impl-obligation.rs:282:35
3+
|
4+
LL | impl dyn Foo + '_ where Self: '_ {
5+
| ^^ `'_` is a reserved lifetime name
6+
17
error[E0478]: lifetime bound not satisfied
28
--> $DIR/static-impl-obligation.rs:222:10
39
|
@@ -453,7 +459,15 @@ note: the `impl` on `dyn w::Foo` has a `'static` lifetime requirement
453459
LL | trait Trait where Self: 'static { fn hello(&self) {} }
454460
| ^^^^^^^
455461

456-
error: aborting due to 25 previous errors
462+
error: lifetime may not live long enough
463+
--> $DIR/static-impl-obligation.rs:287:27
464+
|
465+
LL | fn convert<'a>(x: &'a &'a u32) {
466+
| -- lifetime `'a` defined here
467+
LL | let y: &dyn Foo = x;
468+
| ^ cast requires that `'a` must outlive `'static`
469+
470+
error: aborting due to 27 previous errors
457471

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

0 commit comments

Comments
 (0)