Open
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 error
Desired 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 error
Rationale 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 error
Other cases
No response
Rust Version
From playground:
1.79.0-nightly
(2024-04-08 ab5bda1aa70f707014e2)
Anything else?
No response
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Lifetimes / regionsArea: Name/path resolution done by `rustc_resolve` specificallyArea: Suggestions generated by the compiler applied by `cargo fix`Diagnostics: A diagnostic that is giving misleading or incorrect information.Relevant to the compiler team, which will review and decide on the PR/issue.