Skip to content

Commit af05cf6

Browse files
committed
fix(frontmatter): Try alternative len code fences
Of the non-ideal error cases mentioned in rust-lang#15939, this is likely the one people will hit the most and so important for us to improve.
1 parent b10679f commit af05cf6

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/cargo/util/frontmatter.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,19 @@ impl<'s> ScriptSource<'s> {
9595
// Ends with a line that starts with a matching number of `-` only followed by whitespace
9696
let nl_fence_pattern = format!("\n{fence_pattern}");
9797
let Some(frontmatter_nl) = input.find_slice(nl_fence_pattern.as_str()) else {
98+
for len in (2..(nl_fence_pattern.len() - 1)).rev() {
99+
let Some(frontmatter_nl) = input.find_slice(&nl_fence_pattern[0..len]) else {
100+
continue;
101+
};
102+
let _ = input.next_slice(frontmatter_nl.start + 1);
103+
let close_start = input.current_token_start();
104+
let _ = input.next_slice(len);
105+
let close_end = input.current_token_start();
106+
return Err(FrontmatterError::new(
107+
format!("closing code fence has too few `-`"),
108+
close_start..close_end,
109+
));
110+
}
98111
return Err(FrontmatterError::new(
99112
format!("no closing `{fence_pattern}` found for frontmatter"),
100113
open_start..open_end,
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
[ERROR] no closing `----` found for frontmatter
2-
--> script:1:1
1+
[ERROR] closing code fence has too few `-`
2+
--> script:3:1
33
|
4-
1 | ----cargo
5-
| ^^^^
4+
3 | ---cargo
5+
| ^^^

0 commit comments

Comments
 (0)