-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Closed
Copy link
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-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
pub struct Test<'a>(pub &'a str);
pub fn test(input: &str) -> Test {
Test(input)
}
Current output
warning: hiding a lifetime that's elided elsewhere is confusing
--> src/lib.rs:3:20
|
3 | pub fn test(input: &str) -> Test {
| ^^^^ ---- the same lifetime is hidden here
| |
| the lifetime is elided here
|
= help: the same lifetime is referred to in inconsistent ways, making the signature confusing
= note: `#[warn(mismatched_lifetime_syntaxes)]` on by default
help: use `'_` for type paths
|
3 | pub fn test(input: &str) -> Test<'_> {
| ++++
Desired output
warning: hiding a lifetime that's elided elsewhere is confusing
--> src/lib.rs:3:29
|
3 | pub fn test(input: &str) -> Test {
| ---- ^^^^ the lifetime is elided here
| |
| the same lifetime is hidden here
|
= help: the same lifetime is referred to in inconsistent ways, making the signature confusing
= note: `#[warn(mismatched_lifetime_syntaxes)]` on by default
help: use `'_` for type paths
|
3 | pub fn test(input: &str) -> Test<'_> {
| ++++
Rationale and extra context
Resolving these issues in the IDE highlights the reference, which is already in the canonical form. Unless I expand the diagnostic, or apply its fix-it without looking, I can't see where the hidden lifetime needs to be expanded (it may not be at the top level of the return type).
Other cases
Rust Version
rustc 1.91.0-nightly (6ba0ce409 2025-08-21)
binary: rustc
commit-hash: 6ba0ce40941eee1ca02e9ba49c791ada5158747a
commit-date: 2025-08-21
host: aarch64-apple-darwin
release: 1.91.0-nightly
LLVM version: 21.1.0
(and also 1.89 stable in the playground)
Anything else?
No response
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-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.