Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong compiler error description #69314

Closed
nkbai opened this issue Feb 20, 2020 · 2 comments
Closed

Wrong compiler error description #69314

nkbai opened this issue Feb 20, 2020 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@nkbai
Copy link

nkbai commented Feb 20, 2020

I tried this code:

 struct A {}
struct Msg<'a> {
    s: &'a [i32],
}
impl A {
    async fn g(buf: &[i32]) -> Msg<'_> {
        Msg { s: &buf[0..1] }
    }
    async fn f() {
        let mut buf = [0; 512];
        let m2 = &buf[..];
        let m = Self::g(m2).await;
        Self::f2(m).await;
    }
    async fn f2(m: Msg /*<'_>*/) {}
}

I expected to report error on function f2 only,

error[E0726]: implicit elided lifetime not allowed here
  --> src/lib.rs:15:20
   |
15 |     async fn f2(m: Msg /*<'_>*/) {}
   |                    ^^^- help: indicate the anonymous lifetime: `<'_>`

Instead, it has error following:

  Compiling playground v0.0.1 (/playground)
error[E0726]: implicit elided lifetime not allowed here
  --> src/lib.rs:15:20
   |
15 |     async fn f2(m: Msg /*<'_>*/) {}
   |                    ^^^- help: indicate the anonymous lifetime: `<'_>`

warning: variable does not need to be mutable
  --> src/lib.rs:10:13
   |
10 |         let mut buf = [0; 512];
   |             ----^^^
   |             |
   |             help: remove this `mut`
   |
   = note: `#[warn(unused_mut)]` on by default

error[E0597]: `buf` does not live long enough
  --> src/lib.rs:11:19
   |
11 |         let m2 = &buf[..];
   |                   ^^^
   |                   |
   |                   borrowed value does not live long enough
   |                   cast requires that `buf` is borrowed for `'static`
...
14 |     }
   |     - `buf` dropped here while still borrowed

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0597`.
error: could not compile `playground`.

To learn more, run the command again with --verbose.

there should be no error E0597.

you can test on playground

Meta

rustc --version --verbose:

rustc 1.43.0-nightly (0176a9eef 2020-02-17)
binary: rustc
commit-hash: 0176a9eef845e7421b7e2f7ef015333a41a7c027
commit-date: 2020-02-17
host: x86_64-apple-darwin
release: 1.43.0-nightly
LLVM version: 9.0

@nkbai nkbai added the C-bug Category: This is a bug. label Feb 20, 2020
@nkbai nkbai changed the title Wrong Error Report for compiler Wrong Compiler Error Description Feb 20, 2020
@nkbai nkbai changed the title Wrong Compiler Error Description Wrong compiler error description Feb 20, 2020
@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 20, 2020
@nkbai
Copy link
Author

nkbai commented Feb 20, 2020

error description is right on stable and beta version.

estebank added a commit to estebank/rust that referenced this issue Feb 9, 2023
bors added a commit to rust-lang-ci/rust that referenced this issue Feb 10, 2023
@Dylan-DPC
Copy link
Member

The code now returns the expected error instead of the reported one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants