Better diagnostics when mismatched types due to implict static lifetime
This commit is contained in:
parent
77d155973c
commit
3cd5ad5cd7
11 changed files with 168 additions and 24 deletions
|
|
@ -0,0 +1,19 @@
|
|||
// Test for diagnostics when we have mismatched lifetime due to implict 'static lifetime in GATs
|
||||
|
||||
// check-fail
|
||||
|
||||
#![feature(generic_associated_types)]
|
||||
|
||||
pub trait A {}
|
||||
impl A for &dyn A {}
|
||||
impl A for Box<dyn A> {}
|
||||
|
||||
pub trait B {
|
||||
type T<'a>: A;
|
||||
}
|
||||
|
||||
impl B for () {
|
||||
type T<'a> = Box<dyn A + 'a>; //~ incompatible lifetime on type
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
error: incompatible lifetime on type
|
||||
--> $DIR/issue-78113-lifetime-mismatch-dyn-trait-box.rs:16:5
|
||||
|
|
||||
LL | type T<'a> = Box<dyn A + 'a>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: because this has an unmet lifetime requirement
|
||||
--> $DIR/issue-78113-lifetime-mismatch-dyn-trait-box.rs:12:17
|
||||
|
|
||||
LL | type T<'a>: A;
|
||||
| ^ introduces a `'static` lifetime requirement
|
||||
note: ...the lifetime `'a` as defined on the associated item at 16:12...
|
||||
--> $DIR/issue-78113-lifetime-mismatch-dyn-trait-box.rs:16:12
|
||||
|
|
||||
LL | type T<'a> = Box<dyn A + 'a>;
|
||||
| ^^
|
||||
note: ...does not necessarily outlive the static lifetime introduced by the compatible `impl`
|
||||
--> $DIR/issue-78113-lifetime-mismatch-dyn-trait-box.rs:9:20
|
||||
|
|
||||
LL | impl A for Box<dyn A> {}
|
||||
| ^ this has an implicit `'static` lifetime requirement
|
||||
help: consider relaxing the implicit `'static` requirement
|
||||
|
|
||||
LL | impl A for Box<dyn A + '_> {}
|
||||
| ^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -13,5 +13,5 @@ pub struct Ref<'a>(&'a u8);
|
|||
impl Trait for Ref {} //~ ERROR: implicit elided lifetime not allowed here
|
||||
|
||||
extern "C" {
|
||||
pub fn repro(_: Wrapper<Ref>); //~ ERROR: mismatched types
|
||||
pub fn repro(_: Wrapper<Ref>); //~ ERROR: incompatible lifetime on type
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,21 +4,22 @@ error[E0726]: implicit elided lifetime not allowed here
|
|||
LL | impl Trait for Ref {}
|
||||
| ^^^- help: indicate the anonymous lifetime: `<'_>`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
error: incompatible lifetime on type
|
||||
--> $DIR/wf-in-foreign-fn-decls-issue-80468.rs:16:21
|
||||
|
|
||||
LL | pub fn repro(_: Wrapper<Ref>);
|
||||
| ^^^^^^^^^^^^ lifetime mismatch
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
= note: expected trait `Trait`
|
||||
found trait `Trait`
|
||||
note: the anonymous lifetime #1 defined on the method body at 16:5...
|
||||
note: because this has an unmet lifetime requirement
|
||||
--> $DIR/wf-in-foreign-fn-decls-issue-80468.rs:8:23
|
||||
|
|
||||
LL | pub struct Wrapper<T: Trait>(T);
|
||||
| ^^^^^ introduces a `'static` lifetime requirement
|
||||
note: ...the anonymous lifetime #1 defined on the method body at 16:5...
|
||||
--> $DIR/wf-in-foreign-fn-decls-issue-80468.rs:16:5
|
||||
|
|
||||
LL | pub fn repro(_: Wrapper<Ref>);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: ...does not necessarily outlive the static lifetime
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue