Skip to content

E0106: incorrect suggestion for async function #86667

Closed
@zmill

Description

@zmill

Given the following code: playground

async fn a(s1: &str, s2: &str) -> &str {
    s1
}

fn b(s1: &str, s2: &str) -> &str {
    s1
}

fn main() {}

The current output is:

error[E0106]: missing lifetime specifier
 --> src/main.rs:1:35
  |
1 | async fn a(s1: &str, s2: &str) -> &str {
  |                ----      ----     ^ expected named lifetime parameter
  |
  = help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from `s1` or `s2`
help: consider introducing a named lifetime parameter
  |
1 | async fn a(s1: 'a, &'a str, s2: &'a str) -> &'a str {
  |                ^^^^^^^          ^^^^^^^     ^^^

error[E0106]: missing lifetime specifier
 --> src/main.rs:5:29
  |
5 | fn b(s1: &str, s2: &str) -> &str {
  |          ----      ----     ^ expected named lifetime parameter
  |
  = help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from `s1` or `s2`
help: consider introducing a named lifetime parameter
  |
5 | fn b<'a>(s1: &'a str, s2: &'a str) -> &'a str {
  |     ^^^^     ^^^^^^^      ^^^^^^^     ^^^

The suggestion for the async function is missing the lifetime declaration and has garbled s1's lifetime, so using the suggestion verbatim doesn't compile.

The suggestion for the non-async function is fine, so I'd have expected essentially the same for the async function:

error[E0106]: missing lifetime specifier
 --> src/main.rs:1:35
  |
1 | async fn a(s1: &str, s2: &str) -> &str {
  |                ----      ----     ^ expected named lifetime parameter
  |
  = help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from `s1` or `s2`
help: consider introducing a named lifetime parameter
  |
1 | async fn a<'a>(s1: &'a str, s2: &'a str) -> &'a str {
  |           ^^^^     ^^^^^^^      ^^^^^^^     ^^^

The incorrect suggestion is the same on both current stable and nightly:

rustc 1.53.0 (53cb7b09b 2021-06-17)
binary: rustc
commit-hash: 53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b
commit-date: 2021-06-17
host: x86_64-apple-darwin
release: 1.53.0
LLVM version: 12.0.1
rustc 1.55.0-nightly (a1411de9d 2021-06-26)
binary: rustc
commit-hash: a1411de9de38e0fed728874580218338160eb185
commit-date: 2021-06-26
host: x86_64-apple-darwin
release: 1.55.0-nightly
LLVM version: 12.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-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

    Issue actions