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

E0106: incorrect suggestion for async function #86667

Closed
zmill opened this issue Jun 27, 2021 · 0 comments · Fixed by #86678
Closed

E0106: incorrect suggestion for async function #86667

zmill opened this issue Jun 27, 2021 · 0 comments · Fixed by #86678
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@zmill
Copy link

zmill commented Jun 27, 2021

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
@zmill zmill added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 27, 2021
@bors bors closed this as completed in a89c6be Jun 29, 2021
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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant