about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser/path.rs
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-04-17 00:16:22 +0200
committerGitHub <noreply@github.com>2025-04-17 00:16:22 +0200
commit7ab385e2e1ab9f6cb45cfc8ee4fbe754e2f52486 (patch)
treec274070331ca87384103c3fe3be7ee655e218882 /compiler/rustc_parse/src/parser/path.rs
parentc594a88f4353766e2474163f7f8cf68840682a67 (diff)
parent6242335fdb7444876abf1c3669b6aab1649a0a64 (diff)
downloadrust-7ab385e2e1ab9f6cb45cfc8ee4fbe754e2f52486.tar.gz
rust-7ab385e2e1ab9f6cb45cfc8ee4fbe754e2f52486.zip
Rollup merge of #139854 - fmease:modern-diag-for-lt-in-ty, r=davidtwco
Improve parse errors for stray lifetimes in type position

While technically & syntactically speaking lifetimes do begin[^1] types in type contexts (this essentially excludes generic argument lists) and require a following `+` to form a complete type (`'a +` denotes a bare trait object type), the likelihood that a user meant to write a lifetime-prefixed bare trait object type in *modern* editions (Rust ≥2021) when placing a lifetime into a type context is incredibly low (they would need to add at least three tokens to turn it into a *semantically* well-formed TOT: `'a` → `dyn 'a + Trait`).

Therefore let's *lie* in modern editions (just like in PR https://github.com/rust-lang/rust/pull/131239, a precedent if you will) by stating "*expected type, found lifetime*" in such cases which is a lot more a approachable, digestible and friendly compared to "*lifetime in trait object type must be followed by `+`*" (as added in PR https://github.com/rust-lang/rust/pull/69760).

I've also added recovery for "ampersand-less" reference types (e.g., `'a ()`, `'a mut Ty`) in modern editions because it was trivial to do and I think it's not unlikely to occur in practice.

Fixes #133413.

[^1]: For example, in the context of decl macros, this implies that a lone `'a` always matches syntax fragment `ty` ("even if" there's a later macro matcher expecting syntax fragment `lifetime`). Rephrased, lifetimes (in type contexts) *commit* to the type parser.
Diffstat (limited to 'compiler/rustc_parse/src/parser/path.rs')
0 files changed, 0 insertions, 0 deletions