Skip to content

Help Diagnostic For explicit lifetime name needed here #89824

Open

Description

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`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

    Issue actions