Skip to content

Commit 8cabd61

Browse files
authored
Rollup merge of #145751 - epage:infostring, r=joshtriplett
fix(lexer): Allow '-' in the frontmatter infostring continue set This more closely matches the RFC and what our T-lang contact has asked for, see #136889 (comment) Tracking issue: #136889
2 parents d3c9908 + f43f974 commit 8cabd61

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

compiler/rustc_lexer/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,11 +540,11 @@ impl Cursor<'_> {
540540
// whitespace between the opening and the infostring.
541541
self.eat_while(|ch| ch != '\n' && is_whitespace(ch));
542542

543-
// copied from `eat_identifier`, but allows `.` in infostring to allow something like
543+
// copied from `eat_identifier`, but allows `-` and `.` in infostring to allow something like
544544
// `---Cargo.toml` as a valid opener
545545
if is_id_start(self.first()) {
546546
self.bump();
547-
self.eat_while(|c| is_id_continue(c) || c == '.');
547+
self.eat_while(|c| is_id_continue(c) || c == '-' || c == '.');
548548
}
549549

550550
self.eat_while(|ch| ch != '\n' && is_whitespace(ch));
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--- -toml
2+
//~^ ERROR: invalid infostring for frontmatter
3+
---
4+
5+
// infostrings cannot have leading hyphens
6+
7+
#![feature(frontmatter)]
8+
9+
fn main() {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: invalid infostring for frontmatter
2+
--> $DIR/hyphen-in-infostring-leading.rs:1:4
3+
|
4+
LL | --- -toml
5+
| ^^^^^^
6+
|
7+
= note: frontmatter infostrings must be a single identifier immediately following the opening
8+
9+
error: aborting due to 1 previous error
10+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--- Cargo-toml
2+
---
3+
4+
// infostrings can contain hyphens as long as a hyphen isn't the first character.
5+
//@ check-pass
6+
7+
#![feature(frontmatter)]
8+
9+
fn main() {}

0 commit comments

Comments
 (0)