You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Copy file name to clipboardExpand all lines: src/cargo/util/toml/embedded.rs
+11-9Lines changed: 11 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -143,6 +143,11 @@ impl<'s> ScriptSource<'s> {
143
143
let frontmatter_len = input.len() - rest.len();
144
144
source.content = &input[frontmatter_len..];
145
145
146
+
let repeat = Self::parse(source.content)?;
147
+
if repeat.frontmatter.is_some(){
148
+
anyhow::bail!("only one frontmatter is supported");
149
+
}
150
+
146
151
Ok(source)
147
152
}
148
153
@@ -362,6 +367,7 @@ content: "\n//@ check-pass\n\n// check that frontmatter blocks can have tokens t
362
367
363
368
#[test]
364
369
fnrustc_frontmatter_whitespace_1(){
370
+
// Deferred to rustc since this requires knowledge of Rust grammar
365
371
assert_source(
366
372
r#" ---
367
373
//~^ ERROR: invalid preceding whitespace for frontmatter opening
@@ -539,8 +545,9 @@ content: "\nfn main() {}\n"
539
545
540
546
#[test]
541
547
fnrustc_multifrontmatter(){
542
-
assert_source(
543
-
r#"---
548
+
assert_err(
549
+
ScriptSource::parse(
550
+
r#"---
544
551
---
545
552
546
553
---
@@ -552,13 +559,8 @@ content: "\nfn main() {}\n"
552
559
553
560
fn main() {}
554
561
"#,
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"
0 commit comments