Other errors suppress `deny(mismatched_lifetime_syntaxes)`
Opened this issue · 3 comments
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 functionDesired 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 functionRationale 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 functionRust Version
Playground versions
Anything else?
No response
E0515 is emitted during borrow checking, while mismatched_lifetime_syntaxes is a lint that runs after borrow checking.
When does elided_lifetimes_in_paths run?
It is emitted during resolving, before borrow checking.