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
@@ -211,6 +211,11 @@ impl<'s> ScriptSource<'s> {
211
211
let frontmatter_len = input.len() - rest.len();
212
212
source.content = &input[frontmatter_len..];
213
213
214
+
let repeat = Self::parse(source.content)?;
215
+
if repeat.frontmatter.is_some(){
216
+
anyhow::bail!("only one frontmatter is supported");
217
+
}
218
+
214
219
Ok(source)
215
220
}
216
221
@@ -430,6 +435,7 @@ content: "\n//@ check-pass\n\n// check that frontmatter blocks can have tokens t
430
435
431
436
#[test]
432
437
fnrustc_frontmatter_whitespace_1(){
438
+
// Deferred to rustc since this requires knowledge of Rust grammar
433
439
assert_source(
434
440
r#" ---
435
441
//~^ ERROR: invalid preceding whitespace for frontmatter opening
@@ -607,8 +613,9 @@ content: "\nfn main() {}\n"
607
613
608
614
#[test]
609
615
fnrustc_multifrontmatter(){
610
-
assert_source(
611
-
r#"---
616
+
assert_err(
617
+
ScriptSource::parse(
618
+
r#"---
612
619
---
613
620
614
621
---
@@ -620,13 +627,8 @@ content: "\nfn main() {}\n"
620
627
621
628
fn main() {}
622
629
"#,
623
-
str![[r#"
624
-
shebang: None
625
-
info: None
626
-
frontmatter: ""
627
-
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