Skip to content

Commit 70f09a0

Browse files
committed
fix(embedded): Disallow ambiguous multiple frontmatters
We could say that we delegate this to rustc but if they add support for multiple frontmatters, we need to update to be able to know which we should read, so its better to error on our side.
1 parent c3a9712 commit 70f09a0

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/cargo/util/toml/embedded.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ impl<'s> ScriptSource<'s> {
143143
let frontmatter_len = input.len() - rest.len();
144144
source.content = &input[frontmatter_len..];
145145

146+
let repeat = Self::parse(source.content)?;
147+
if repeat.frontmatter.is_some() {
148+
anyhow::bail!("only one frontmatter is supported");
149+
}
150+
146151
Ok(source)
147152
}
148153

@@ -362,6 +367,7 @@ content: "\n//@ check-pass\n\n// check that frontmatter blocks can have tokens t
362367

363368
#[test]
364369
fn rustc_frontmatter_whitespace_1() {
370+
// Deferred to rustc since this requires knowledge of Rust grammar
365371
assert_source(
366372
r#" ---
367373
//~^ ERROR: invalid preceding whitespace for frontmatter opening
@@ -539,8 +545,9 @@ content: "\nfn main() {}\n"
539545

540546
#[test]
541547
fn rustc_multifrontmatter() {
542-
assert_source(
543-
r#"---
548+
assert_err(
549+
ScriptSource::parse(
550+
r#"---
544551
---
545552
546553
---
@@ -552,13 +559,8 @@ content: "\nfn main() {}\n"
552559
553560
fn main() {}
554561
"#,
555-
str![[r#"
556-
shebang: None
557-
info: None
558-
frontmatter: ""
559-
content: "\n---\n//~^ ERROR: expected item, found `-`\n// FIXME(frontmatter): make this diagnostic better\n---\n\n// test that we do not parse another frontmatter block after the first one.\n\nfn main() {}\n"
560-
561-
"#]],
562+
),
563+
str!["only one frontmatter is supported"],
562564
);
563565
}
564566

0 commit comments

Comments
 (0)