Skip to content

Commit

Permalink
RawLifetimeOrLabel reprocessing: reject some keywords
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mattheww committed Nov 25, 2024
1 parent 93b3775 commit 4f2cf4b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/lexlucid/reprocessing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ pub fn reprocess(pretoken: &Pretoken) -> Result<FineToken, Error> {
PretokenData::LifetimeOrLabel { name } => {
FineTokenData::LifetimeOrLabel { name: name.clone() }
}
PretokenData::RawLifetimeOrLabel { name } => {
FineTokenData::RawLifetimeOrLabel { name: name.clone() }
}
PretokenData::RawLifetimeOrLabel { name } => lex_raw_lifetime_or_label(name)?,
PretokenData::SingleQuoteLiteral {
prefix,
literal_content,
Expand Down Expand Up @@ -280,6 +278,15 @@ fn lex_raw_identifier(identifier: &Charseq) -> Result<FineTokenData, Error> {
})
}

/// Validates and interprets a `r#...` raw identifier.
fn lex_raw_lifetime_or_label(name: &Charseq) -> Result<FineTokenData, Error> {
let s = name.to_string();
if s == "_" || s == "crate" || s == "self" || s == "super" || s == "Self" {
return Err(rejected("forbidden raw lifetime or label"));
}
Ok(FineTokenData::RawLifetimeOrLabel { name: name.clone() })
}

/// Validates and interprets a single-quoted (character or byte) literal.
fn lex_single_quote_literal(
prefix: &Charseq,
Expand Down
9 changes: 8 additions & 1 deletion writeup/reprocessing_cases.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,14 @@ A `LifetimeOrLabel` pretoken is always accepted.
Fine-grained token kind produced:
`RawLifetimeOrLabel`

A `RawLifetimeOrLabel` pretoken is always accepted.
The pretoken is rejected if (and only if) the <var>name</var> is one of the following sequences of characters:

- <b>_</b>
- <b>crate</b>
- <b>self</b>
- <b>super</b>
- <b>Self</b>


##### Attributes
<var>name</var>: copied
Expand Down

0 comments on commit 4f2cf4b

Please sign in to comment.