From 9b0ddec2a8f3ed9a72df14921b3aa164993dd83b Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 22 Aug 2025 09:17:41 -0500 Subject: [PATCH 1/2] test(frontmatter): Show current hyphen behavior --- tests/ui/frontmatter/hyphen-in-infostring-leading.rs | 9 +++++++++ .../ui/frontmatter/hyphen-in-infostring-leading.stderr | 10 ++++++++++ .../ui/frontmatter/hyphen-in-infostring-non-leading.rs | 9 +++++++++ .../hyphen-in-infostring-non-leading.stderr | 10 ++++++++++ 4 files changed, 38 insertions(+) create mode 100644 tests/ui/frontmatter/hyphen-in-infostring-leading.rs create mode 100644 tests/ui/frontmatter/hyphen-in-infostring-leading.stderr create mode 100644 tests/ui/frontmatter/hyphen-in-infostring-non-leading.rs create mode 100644 tests/ui/frontmatter/hyphen-in-infostring-non-leading.stderr diff --git a/tests/ui/frontmatter/hyphen-in-infostring-leading.rs b/tests/ui/frontmatter/hyphen-in-infostring-leading.rs new file mode 100644 index 0000000000000..8652fd76ad5ce --- /dev/null +++ b/tests/ui/frontmatter/hyphen-in-infostring-leading.rs @@ -0,0 +1,9 @@ +--- -toml +//~^ ERROR: invalid infostring for frontmatter +--- + +// infostrings cannot have leading hyphens + +#![feature(frontmatter)] + +fn main() {} diff --git a/tests/ui/frontmatter/hyphen-in-infostring-leading.stderr b/tests/ui/frontmatter/hyphen-in-infostring-leading.stderr new file mode 100644 index 0000000000000..167b537d62be2 --- /dev/null +++ b/tests/ui/frontmatter/hyphen-in-infostring-leading.stderr @@ -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 + diff --git a/tests/ui/frontmatter/hyphen-in-infostring-non-leading.rs b/tests/ui/frontmatter/hyphen-in-infostring-non-leading.rs new file mode 100644 index 0000000000000..ccb80d8799a63 --- /dev/null +++ b/tests/ui/frontmatter/hyphen-in-infostring-non-leading.rs @@ -0,0 +1,9 @@ +--- Cargo-toml +//~^ ERROR: invalid infostring for frontmatter +--- + +// infostrings cannot have hyphens + +#![feature(frontmatter)] + +fn main() {} diff --git a/tests/ui/frontmatter/hyphen-in-infostring-non-leading.stderr b/tests/ui/frontmatter/hyphen-in-infostring-non-leading.stderr new file mode 100644 index 0000000000000..959cf74e3274c --- /dev/null +++ b/tests/ui/frontmatter/hyphen-in-infostring-non-leading.stderr @@ -0,0 +1,10 @@ +error: invalid infostring for frontmatter + --> $DIR/hyphen-in-infostring-non-leading.rs:1:4 + | +LL | --- Cargo-toml + | ^^^^^^^^^^^ + | + = note: frontmatter infostrings must be a single identifier immediately following the opening + +error: aborting due to 1 previous error + From f43f974b9e14af328b7982d6320cc4d7a9104410 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 22 Aug 2025 09:26:19 -0500 Subject: [PATCH 2/2] fix(lexer): Allow '-' in the infostring continue set This more closely matches the RFC and what our T-lang contact has asked for, see https://github.com/rust-lang/rust/issues/136889#issuecomment-3212715312 --- compiler/rustc_lexer/src/lib.rs | 4 ++-- .../ui/frontmatter/hyphen-in-infostring-non-leading.rs | 4 ++-- .../hyphen-in-infostring-non-leading.stderr | 10 ---------- 3 files changed, 4 insertions(+), 14 deletions(-) delete mode 100644 tests/ui/frontmatter/hyphen-in-infostring-non-leading.stderr diff --git a/compiler/rustc_lexer/src/lib.rs b/compiler/rustc_lexer/src/lib.rs index e80196ed5679d..483cc3e93dc20 100644 --- a/compiler/rustc_lexer/src/lib.rs +++ b/compiler/rustc_lexer/src/lib.rs @@ -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)); diff --git a/tests/ui/frontmatter/hyphen-in-infostring-non-leading.rs b/tests/ui/frontmatter/hyphen-in-infostring-non-leading.rs index ccb80d8799a63..35e7b96ff875b 100644 --- a/tests/ui/frontmatter/hyphen-in-infostring-non-leading.rs +++ b/tests/ui/frontmatter/hyphen-in-infostring-non-leading.rs @@ -1,8 +1,8 @@ --- Cargo-toml -//~^ ERROR: invalid infostring for frontmatter --- -// infostrings cannot have hyphens +// infostrings can contain hyphens as long as a hyphen isn't the first character. +//@ check-pass #![feature(frontmatter)] diff --git a/tests/ui/frontmatter/hyphen-in-infostring-non-leading.stderr b/tests/ui/frontmatter/hyphen-in-infostring-non-leading.stderr deleted file mode 100644 index 959cf74e3274c..0000000000000 --- a/tests/ui/frontmatter/hyphen-in-infostring-non-leading.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: invalid infostring for frontmatter - --> $DIR/hyphen-in-infostring-non-leading.rs:1:4 - | -LL | --- Cargo-toml - | ^^^^^^^^^^^ - | - = note: frontmatter infostrings must be a single identifier immediately following the opening - -error: aborting due to 1 previous error -