Other errors suppress `deny(mismatched_lifetime_syntaxes)`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
//#![deny(elided_lifetimes_in_paths)]
#![deny(mismatched_lifetime_syntaxes)]
struct Wrap<'a>(&'a str);
fn foo(s: &str) -> Wrap {
Wrap(&s.to_owned())
}
Current output
error[E0515]: cannot return value referencing temporary value
--> src/lib.rs:7:5
|
7 | Wrap(&s.to_owned())
| ^^^^^^------------^
| | |
| | temporary value created here
| returns a value referencing data owned by the current function
Desired output
error: hiding a lifetime that's elided elsewhere is confusing
--> src/lib.rs:6:11
|
6 | fn foo(s: &str) -> Wrap {
| ^^^^ ^^^^ 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: the lint level is defined here
--> src/lib.rs:2:9
|
2 | #![deny(mismatched_lifetime_syntaxes)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: use `'_` for type paths
|
6 | fn foo(s: &str) -> Wrap<'_> {
| ++++
error[E0515]: cannot return value referencing temporary value
--> src/lib.rs:7:5
|
7 | Wrap(&s.to_owned())
| ^^^^^^------------^
| | |
| | temporary value created here
| returns a value referencing data owned by the current function
Rationale and extra context
When solving nontrivial borrow checker errors, one of the first tools I reach for is deny(elided_lifetimes_in_paths). Not only does it make the signatures more clear, but the source of the borrow checker error is quite often related to one of the lint error sites.
It would be nice if the more precise mismatched_lifetime_syntaxes lint could be used instead, but because it is suppressed by other errors, it cannot easily help find the source of said errors.
Personally I'd be fine if the lint were suppressed by other errors when it is just a warning but not when it is deny (but I don't know if that's possible).
Other cases
Output with deny(elided_lifetimes_in_paths):
error: hidden lifetime parameters in types are deprecated
--> src/lib.rs:6:20
|
6 | fn foo(s: &str) -> Wrap {
| ^^^^ expected lifetime parameter
|
note: the lint level is defined here
--> src/lib.rs:1:9
|
1 | #![deny(elided_lifetimes_in_paths)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
help: indicate the anonymous lifetime
|
6 | fn foo(s: &str) -> Wrap<'_> {
| ++++
error[E0515]: cannot return value referencing temporary value
--> src/lib.rs:7:5
|
7 | Wrap(&s.to_owned())
| ^^^^^^------------^
| | |
| | temporary value created here
| returns a value referencing data owned by the current function
Rust Version
Playground versions
- 1.91.0
- 1.92.0-beta.2 (2025-10-31 0a411606e9cc00588c83)
- 1.93.0-nightly (2025-11-07 843f8ce2ebc01d35a304)
Anything else?
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Rust Playground reproducer and the src/lib.rs example, comparing diagnostics with mismatched_lifetime_syntaxes and elided_lifetimes_in_paths enabled. Trace how the compiler suppresses the lint when the borrow-checker error is emitted. Done means the lifetime lint appears alongside the existing E0515 diagnostic as shown in the desired output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100