Open
Description
This happens in a lot of tests, but from src/test/ui/traits/trait-upcasting/type-checking-test-4.rs:
before
error[E0308]: mismatched types
--> $DIR/type-checking-test-4.rs:20:13
|
LL | let _ = x as &dyn Bar<'static, 'a>; // Error
| ^ lifetime mismatch
|
= note: expected trait object `dyn Bar<'static, 'a>`
found trait object `dyn Bar<'static, 'static>`
note: the lifetime `'a` as defined here...
--> $DIR/type-checking-test-4.rs:19:16
|
LL | fn test_wrong1<'a>(x: &dyn Foo<'static>, y: &'a u32) {
| ^^
= note: ...does not necessarily outlive the static lifetime
after
error: lifetime may not live long enough
--> $DIR/type-checking-test-4.rs:20:13
|
LL | fn test_wrong1<'a>(x: &dyn Foo<'static>, y: &'a u32) {
| -- lifetime `'a` defined here
LL | let _ = x as &dyn Bar<'static, 'a>; // Error
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static`
Being able to compare the expected and found types in full make it clear what's wrong.