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

Error diagnostic suggests syntactically invalid code #64388

Closed
cdisselkoen opened this issue Sep 11, 2019 · 2 comments
Closed

Error diagnostic suggests syntactically invalid code #64388

cdisselkoen opened this issue Sep 11, 2019 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@cdisselkoen
Copy link

For the following code (Playground link):

fn foo<'a>(u: &'a usize) -> impl IntoIterator<Item = usize> + 'a {
    std::thread::spawn(move || {
        println!("{}", u);
    });
    vec![]
}

rustc provides the following error and suggestion:

error: cannot infer an appropriate lifetime
 --> src/lib.rs:2:24
  |
2 |       std::thread::spawn(move || {
  |  _____------------------_^
  | |     |
  | |     this return type evaluates to the `'static` lifetime...
3 | |         println!("{}", u);
4 | |     });
  | |_____^ ...but this borrow...
  |
note: ...can't outlive the lifetime 'a as defined on the function body at 1:8
 --> src/lib.rs:1:8
  |
1 | fn foo<'a>(u: &'a usize) -> impl IntoIterator<Item = usize> + 'a {
  |        ^^
help: you can add a constraint to the return type to make it last less than `'static` and match the lifetime 'a as defined on the function body at 1:8
  |
2 |     std::thread::spawn + 'a(move || {
  |     ^^^^^^^^^^^^^^^^^^^^^^^

But applying this suggestion results in a syntax error:

error: expected `:`, found `(`
 --> src/lib.rs:2:28
  |
2 |     std::thread::spawn + 'a(move || {
  |                            ^ expected `:`

Using the Playground link, I reproduced this invalid suggestion on Rust 1.37.0 stable, 1.38.0-beta.2, and 1.39.0-nightly 2019-08-23.

@Centril Centril added A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 11, 2019
@estebank estebank added the D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. label Oct 5, 2019
@jbg
Copy link

jbg commented Oct 27, 2019

appears to be a duplicate of #62097

@csmoe
Copy link
Member

csmoe commented Oct 29, 2019

Close as duplicate.

@csmoe csmoe closed this as completed Oct 29, 2019
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-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. 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

5 participants