diff options
| author | jackh726 <jack.huey@umassmed.edu> | 2021-07-15 10:03:39 -0400 |
|---|---|---|
| committer | jackh726 <jack.huey@umassmed.edu> | 2021-07-19 18:20:21 -0400 |
| commit | 3cd5ad5cd7d85fc36c3696e3022bef5c5af088d2 (patch) | |
| tree | 3805568e3732371815a571964fbb0b57b1c823c5 /src | |
| parent | 77d155973c6c22a0e1af49a4a9bac024f697851d (diff) | |
| download | rust-3cd5ad5cd7d85fc36c3696e3022bef5c5af088d2.tar.gz rust-3cd5ad5cd7d85fc36c3696e3022bef5c5af088d2.zip | |
Better diagnostics when mismatched types due to implict static lifetime
Diffstat (limited to 'src')
4 files changed, 56 insertions, 8 deletions
diff --git a/src/test/ui/generic-associated-types/issue-78113-lifetime-mismatch-dyn-trait-box.rs b/src/test/ui/generic-associated-types/issue-78113-lifetime-mismatch-dyn-trait-box.rs new file mode 100644 index 00000000000..8f40a03ae6f --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-78113-lifetime-mismatch-dyn-trait-box.rs @@ -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() {} diff --git a/src/test/ui/generic-associated-types/issue-78113-lifetime-mismatch-dyn-trait-box.stderr b/src/test/ui/generic-associated-types/issue-78113-lifetime-mismatch-dyn-trait-box.stderr new file mode 100644 index 00000000000..b77b58284ee --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-78113-lifetime-mismatch-dyn-trait-box.stderr @@ -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 + diff --git a/src/test/ui/wf/wf-in-foreign-fn-decls-issue-80468.rs b/src/test/ui/wf/wf-in-foreign-fn-decls-issue-80468.rs index 8386959cfb3..4fcf8f403bb 100644 --- a/src/test/ui/wf/wf-in-foreign-fn-decls-issue-80468.rs +++ b/src/test/ui/wf/wf-in-foreign-fn-decls-issue-80468.rs @@ -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 } diff --git a/src/test/ui/wf/wf-in-foreign-fn-decls-issue-80468.stderr b/src/test/ui/wf/wf-in-foreign-fn-decls-issue-80468.stderr index bb839d0a5ec..48c9f362fe2 100644 --- a/src/test/ui/wf/wf-in-foreign-fn-decls-issue-80468.stderr +++ b/src/test/ui/wf/wf-in-foreign-fn-decls-issue-80468.stderr @@ -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`. |
