Skip to content

Other errors suppress deny(mismatched_lifetime_syntaxes) #148705

@QuineDot

Description

@QuineDot

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 0a41160)
  • 1.93.0-nightly (2025-11-07 843f8ce)

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions