Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_parse/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ parse_frontmatter_invalid_opening_preceding_whitespace = invalid preceding white
parse_frontmatter_length_mismatch = frontmatter close does not match the opening
.label_opening = the opening here has {$len_opening} dashes...
.label_close = ...while the close has {$len_close} dashes
parse_frontmatter_too_many_dashes = too many `-` symbols: frontmatter openings may be delimited by up to 255 `-` symbols, but found {$len_opening}
parse_frontmatter_unclosed = unclosed frontmatter
.note = frontmatter opening here was not closed
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_parse/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,12 @@ pub(crate) struct FrontmatterLengthMismatch {
pub len_close: usize,
}

#[derive(Diagnostic)]
#[diag(parse_frontmatter_too_many_dashes)]
pub(crate) struct FrontmatterTooManyDashes {
pub len_opening: usize,
}

#[derive(Diagnostic)]
#[diag(parse_leading_plus_not_supported)]
pub(crate) struct LeadingPlusNotSupported {
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_parse/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,11 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
});
}

// Only up to 255 `-`s are allowed in code fences
if u8::try_from(len_opening).is_err() {
self.dcx().emit_err(errors::FrontmatterTooManyDashes { len_opening });
}

if !rest.trim_matches(is_horizontal_whitespace).is_empty() {
let span = self.mk_sp(last_line_start_pos, self.pos);
self.dcx().emit_err(errors::FrontmatterExtraCharactersAfterClose { span });
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/frontmatter/fence-too-many-dashes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//~? ERROR: too many `-` symbols: frontmatter openings may be delimited by up to 255 `-` symbols
// ignore-tidy-linelength
[dependencies]
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#![feature(frontmatter)]

// check that we limit fence lengths

fn main() {}
4 changes: 4 additions & 0 deletions tests/ui/frontmatter/fence-too-many-dashes.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
error: too many `-` symbols: frontmatter openings may be delimited by up to 255 `-` symbols, but found 256

error: aborting due to 1 previous error

Loading