Skip to content

Wrong compiler error description #69314

@nkbai

Description

@nkbai

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

Activity

changed the title [-]Wrong Error Report for compiler[/-] [+]Wrong Compiler Error Description[/+] on Feb 20, 2020
changed the title [-]Wrong Compiler Error Description[/-] [+]Wrong compiler error description[/+] on Feb 20, 2020
added
A-diagnosticsArea: Messages for errors, warnings, and lints
A-lifetimesArea: Lifetimes / regions
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Feb 20, 2020
nkbai

nkbai commented on Feb 20, 2020

@nkbai
Author

error description is right on stable and beta version.

added a commit that references this issue on Feb 10, 2023
Dylan-DPC

Dylan-DPC commented on Mar 27, 2023

@Dylan-DPC
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jonas-schievink@nkbai@Dylan-DPC

        Issue actions

          Wrong compiler error description · Issue #69314 · rust-lang/rust