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

Help Diagnostic For explicit lifetime name needed here #89824

Open
JosephTLyons opened this issue Oct 12, 2021 · 1 comment
Open

Help Diagnostic For explicit lifetime name needed here #89824

JosephTLyons opened this issue Oct 12, 2021 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@JosephTLyons
Copy link
Contributor

Using rustc 1.55.0

Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=deaf96d3f30f20986ce469e1b49664ff

use std::iter::Sum;

fn main() {
    println!("Hello, world!");
}

fn add<T: 'static + Sum<&T>>(values: &[T]) -> T {
    values.iter().sum()
}

The current output is:

❯ cargo run
   Compiling lifetimes v0.1.0 (/Users/josephlyons/Desktop/lifetimes)
error[E0637]: `&` without an explicit lifetime name cannot be used here
  --> src/main.rs:52:25
   |
52 | fn add<T: 'static + Sum<&T>>(values: &[T]) -> T {
   |                         ^ explicit lifetime name needed here

error[E0621]: explicit lifetime required in the type of `values`
  --> src/main.rs:53:19
   |
53 |     values.iter().sum()
   |                   ^^^ lifetime `'static` required

Some errors have detailed explanations: E0621, E0637.
For more information about an error, try `rustc --explain E0621`.
error: could not compile `lifetimes` due to 2 previous errors

Not sure what the proposed output would be, but some sort of help / suggestion could help to make this easier for beginners

@JosephTLyons JosephTLyons 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 Oct 12, 2021
@oli-obk oli-obk added the A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. label Oct 12, 2021
@pierwill
Copy link
Member

pierwill commented Oct 12, 2021

In addition, "error[E0637]: & without an explicit lifetime name cannot be used here" does not look like the right error here. The playground links to E0637, which is specifically about _ used as a lifetime identifier.

JohnTitor added a commit to JohnTitor/rust that referenced this issue Oct 21, 2021
Update E0637 description to mention `&` w/o an explicit lifetime name

Deal with rust-lang#89824 (comment). Another solution would be splitting the error code into two as (I think) it's a bit unclear to users why they have the same error code.
JohnTitor added a commit to JohnTitor/rust that referenced this issue Oct 22, 2021
Update E0637 description to mention `&` w/o an explicit lifetime name

Deal with rust-lang#89824 (comment). Another solution would be splitting the error code into two as (I think) it's a bit unclear to users why they have the same error code.
JohnTitor added a commit to JohnTitor/rust that referenced this issue Oct 22, 2021
Update E0637 description to mention `&` w/o an explicit lifetime name

Deal with rust-lang#89824 (comment). Another solution would be splitting the error code into two as (I think) it's a bit unclear to users why they have the same error code.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 22, 2021
Update E0637 description to mention `&` w/o an explicit lifetime name

Deal with rust-lang#89824 (comment). Another solution would be splitting the error code into two as (I think) it's a bit unclear to users why they have the same error code.
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`. 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