Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_lexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,11 +540,11 @@ impl Cursor<'_> {
// whitespace between the opening and the infostring.
self.eat_while(|ch| ch != '\n' && is_whitespace(ch));

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

self.eat_while(|ch| ch != '\n' && is_whitespace(ch));
Expand Down
9 changes: 9 additions & 0 deletions tests/ui/frontmatter/hyphen-in-infostring-leading.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
--- -toml
//~^ ERROR: invalid infostring for frontmatter
---

// infostrings cannot have leading hyphens

#![feature(frontmatter)]

fn main() {}
10 changes: 10 additions & 0 deletions tests/ui/frontmatter/hyphen-in-infostring-leading.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: invalid infostring for frontmatter
--> $DIR/hyphen-in-infostring-leading.rs:1:4
|
LL | --- -toml
| ^^^^^^
|
= note: frontmatter infostrings must be a single identifier immediately following the opening

error: aborting due to 1 previous error

9 changes: 9 additions & 0 deletions tests/ui/frontmatter/hyphen-in-infostring-non-leading.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
--- Cargo-toml
---

// infostrings can contain hyphens as long as a hyphen isn't the first character.
//@ check-pass

#![feature(frontmatter)]

fn main() {}
Loading