Skip to content

Commit 4f2cf4b

Browse files
committed
RawLifetimeOrLabel reprocessing: reject some keywords
This mirrors the changes from rust-lang/rust#132363 "Enforce that raw lifetimes must be valid raw identifiers" which have been backported to appear in Rust 1.83
1 parent 93b3775 commit 4f2cf4b

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/lexlucid/reprocessing.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,7 @@ pub fn reprocess(pretoken: &Pretoken) -> Result<FineToken, Error> {
161161
PretokenData::LifetimeOrLabel { name } => {
162162
FineTokenData::LifetimeOrLabel { name: name.clone() }
163163
}
164-
PretokenData::RawLifetimeOrLabel { name } => {
165-
FineTokenData::RawLifetimeOrLabel { name: name.clone() }
166-
}
164+
PretokenData::RawLifetimeOrLabel { name } => lex_raw_lifetime_or_label(name)?,
167165
PretokenData::SingleQuoteLiteral {
168166
prefix,
169167
literal_content,
@@ -280,6 +278,15 @@ fn lex_raw_identifier(identifier: &Charseq) -> Result<FineTokenData, Error> {
280278
})
281279
}
282280

281+
/// Validates and interprets a `r#...` raw identifier.
282+
fn lex_raw_lifetime_or_label(name: &Charseq) -> Result<FineTokenData, Error> {
283+
let s = name.to_string();
284+
if s == "_" || s == "crate" || s == "self" || s == "super" || s == "Self" {
285+
return Err(rejected("forbidden raw lifetime or label"));
286+
}
287+
Ok(FineTokenData::RawLifetimeOrLabel { name: name.clone() })
288+
}
289+
283290
/// Validates and interprets a single-quoted (character or byte) literal.
284291
fn lex_single_quote_literal(
285292
prefix: &Charseq,

writeup/reprocessing_cases.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,14 @@ A `LifetimeOrLabel` pretoken is always accepted.
169169
Fine-grained token kind produced:
170170
`RawLifetimeOrLabel`
171171

172-
A `RawLifetimeOrLabel` pretoken is always accepted.
172+
The pretoken is rejected if (and only if) the <var>name</var> is one of the following sequences of characters:
173+
174+
- <b>_</b>
175+
- <b>crate</b>
176+
- <b>self</b>
177+
- <b>super</b>
178+
- <b>Self</b>
179+
173180

174181
##### Attributes
175182
<var>name</var>: copied

0 commit comments

Comments
 (0)