- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyArea: Name/path resolution done by `rustc_resolve` specificallyA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A diagnostic that is giving misleading or incorrect information.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Code
fn abs<'a, T>(x: &'a T) -> T
where
    &'a T: Ord + core::ops::Neg<Output = &T>,
    T: Clone,
{
    x.max(-x).clone()
}Current output
Compiling playground v0.0.1 (/playground)
error[E0637]: `&` without an explicit lifetime name cannot be used here
 --> src/lib.rs:3:42
  |
3 |     &'a T: Ord + core::ops::Neg<Output = &T>,
  |                                          ^ explicit lifetime name needed here
  |
help: consider introducing a higher-ranked lifetime here
  |
3 |     &'a T: Ord + for<'a> core::ops::Neg<Output = &'a T>,
  |                  +++++++                          ++
For more information about this error, try `rustc --explain E0637`.
error: could not compile `playground` (lib) due to 1 previous errorDesired output
Compiling playground v0.0.1 (/playground)
error[E0637]: `&` without an explicit lifetime name cannot be used here
 --> src/lib.rs:3:42
  |
3 |     &'a T: Ord + core::ops::Neg<Output = &T>,
  |                                          ^ explicit lifetime name needed here
  |
help: consider introducing a higher-ranked lifetime here
  |
3 |     &'a T: Ord + core::ops::Neg<Output = &'a T>,
  |                                           ++
For more information about this error, try `rustc --explain E0637`.
error: could not compile `playground` (lib) due to 1 previous errorRationale and extra context
Following the compiler's suggestion:
   Compiling playground v0.0.1 (/playground)
error[E0496]: lifetime name `'a` shadows a lifetime name that is already in scope
 --> src/lib.rs:3:22
  |
1 | fn abs<'a, T>(x: &'a T) -> T
  |        -- first declared here
2 | where
3 |     &'a T: Ord + for<'a> core::ops::Neg<Output = &'a T>,
  |                      ^^ lifetime `'a` already in scope
For more information about this error, try `rustc --explain E0496`.
error: could not compile `playground` (lib) due to 1 previous errorOther cases
No response
Rust Version
From playground:
1.79.0-nightly
(2024-04-08 ab5bda1aa70f707014e2)Anything else?
No response
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyArea: Name/path resolution done by `rustc_resolve` specificallyA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A diagnostic that is giving misleading or incorrect information.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.