diff options
| author | bors <bors@rust-lang.org> | 2021-07-20 10:56:08 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-07-20 10:56:08 +0000 |
| commit | da7d405357600a76f2b93b8aa41fe5ee5da7885d (patch) | |
| tree | 9763cf30603b2489abef4a9fefe570465c287b29 /src/test/ui/wf | |
| parent | 718d53b0cb7dde93499cb92950d60b412f5a3d05 (diff) | |
| parent | ae024919845a44473c22b8c3f1dfa075c9c5c75d (diff) | |
| download | rust-da7d405357600a76f2b93b8aa41fe5ee5da7885d.tar.gz rust-da7d405357600a76f2b93b8aa41fe5ee5da7885d.zip | |
Auto merge of #87244 - jackh726:issue-71883, r=estebank
Better diagnostics with mismatched types due to implicit static lifetime Fixes #78113 I think this is my first diagnostics PR...definitely happy to hear thoughts on the direction/implementation here. I was originally just trying to solve the error above, where the lifetime on a GAT was causing a cryptic "mismatched types" error. But as I was writing this, I realized that this (unintentionally) also applied to a different case: `wf-in-foreign-fn-decls-issue-80468.rs`. I'm not sure if this diagnostic should get a new error code, or even reuse an existing one. And, there might be some ways to make this even more generalized. Also, the error is a bit more lengthy and verbose than probably needed. So thoughts there are welcome too. This PR essentially ended up adding a new nice region error pass that triggers if a type doesn't match the self type of an impl which is selected because of a predicate because of an implicit static bound on that self type. r? `@estebank`
Diffstat (limited to 'src/test/ui/wf')
| -rw-r--r-- | src/test/ui/wf/wf-in-foreign-fn-decls-issue-80468.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/wf/wf-in-foreign-fn-decls-issue-80468.stderr | 20 |
2 files changed, 15 insertions, 7 deletions
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..4e927cd983d 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 @@ -3,22 +3,30 @@ error[E0726]: implicit elided lifetime not allowed here | LL | impl Trait for Ref {} | ^^^- help: indicate the anonymous lifetime: `<'_>` + | + = note: assuming a `'static` 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: because this has an unmet lifetime requirement + --> $DIR/wf-in-foreign-fn-decls-issue-80468.rs:8:23 | - = note: expected trait `Trait` - found trait `Trait` +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 +note: ...does not necessarily outlive the static lifetime introduced by the compatible `impl` + --> $DIR/wf-in-foreign-fn-decls-issue-80468.rs:13:1 + | +LL | impl Trait for Ref {} + | ^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0308`. |
