rust/compiler/rustc_ast_lowering/src
bors ccf3198de3 Auto merge of #138677 - shepmaster:consistent-elided-lifetime-syntax, r=traviscross,jieyouxu
Add a new `mismatched-lifetime-syntaxes` lint

The lang-team [discussed this](https://hackmd.io/nf4ZUYd7Rp6rq-1svJZSaQ) and I attempted to [summarize](https://github.com/rust-lang/rust/pull/120808#issuecomment-2701863833) their decision. The summary-of-the-summary is:

- Using two different kinds of syntax for elided lifetimes is confusing. In rare cases, it may even [lead to unsound code](https://github.com/rust-lang/rust/issues/48686)! Some examples:

    ```rust
    // Lint will warn about these
    fn(v: ContainsLifetime) -> ContainsLifetime<'_>;
    fn(&'static u8) -> &u8;
    ```

- Matching up references with no lifetime syntax, references with anonymous lifetime syntax, and paths with anonymous lifetime syntax is an exception to the simplest possible rule:

    ```rust
    // Lint will not warn about these
    fn(&u8) -> &'_ u8;
    fn(&'_ u8) -> &u8;
    fn(&u8) -> ContainsLifetime<'_>;
    ```

- Having a lint for consistent syntax of elided lifetimes will make the [future goal](https://github.com/rust-lang/rust/issues/91639) of warning-by-default for paths participating in elision much simpler.

---

This new lint attempts to accomplish the goal of enforcing consistent syntax. In the process, it supersedes and replaces the existing `elided-named-lifetimes` lint, which means it starts out life as warn-by-default.
2025-06-05 19:49:30 +00:00
..
asm.rs Stabilize asm_goto 2025-03-17 11:12:10 +00:00
block.rs Implement super let. 2025-04-04 09:44:19 +02:00
delegation.rs Add visit_id to ast Visitor 2025-06-01 02:38:24 +00:00
errors.rs Stabilize precise_capturing_in_traits 2025-03-23 14:11:04 +00:00
expr.rs Add iter macro 2025-06-03 10:52:32 -07:00
format.rs Rename kw::Empty as sym::empty. 2025-05-22 11:55:22 +10:00
index.rs Reorder fields in hir::ItemKind variants. 2025-05-30 02:23:20 +10:00
item.rs Overhaul UsePath. 2025-06-03 08:23:21 +10:00
lib.rs Rename LifetimeSyntax variants to lang-team-approved names 2025-06-03 09:06:08 -04:00
pat.rs Auto merge of #140453 - Zoxc:next-disambiguator, r=oli-obk 2025-05-05 11:50:43 +00:00
path.rs Overhaul UsePath. 2025-06-03 08:23:21 +10:00
stability.rs remove compiler support for extern "rust-intrinsic" blocks 2025-04-06 21:32:58 +02:00