Skip to content

Commit 2a4204b

Browse files
committed
Use default field values in markdown::parse::Context
1 parent 81d8edc commit 2a4204b

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

Diff for: compiler/rustc_errors/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#![feature(associated_type_defaults)]
1515
#![feature(box_into_inner)]
1616
#![feature(box_patterns)]
17+
#![feature(default_field_values)]
1718
#![feature(error_reporter)]
1819
#![feature(if_let_guard)]
1920
#![feature(let_chains)]

Diff for: compiler/rustc_errors/src/markdown/parse.rs

+7-13
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ type ParseResult<'a> = Option<Parsed<'a>>;
4040

4141
/// Parsing context
4242
#[derive(Clone, Copy, Debug, PartialEq)]
43+
// The default values are the most common setting for non top-level parsing: not top block, not at
44+
// line start (yes leading whitespace, not escaped).
4345
struct Context {
4446
/// If true, we are at a the topmost level (not recursing a nested tt)
45-
top_block: bool,
47+
top_block: bool = false,
4648
/// Previous character
47-
prev: Prev,
49+
prev: Prev = Prev::Whitespace,
4850
}
4951

5052
/// Character class preceding this one
@@ -57,14 +59,6 @@ enum Prev {
5759
Any,
5860
}
5961

60-
impl Default for Context {
61-
/// Most common setting for non top-level parsing: not top block, not at
62-
/// line start (yes leading whitespace, not escaped)
63-
fn default() -> Self {
64-
Self { top_block: false, prev: Prev::Whitespace }
65-
}
66-
}
67-
6862
/// Flags to simple parser function
6963
#[derive(Clone, Copy, Debug, PartialEq)]
7064
enum ParseOpt {
@@ -248,7 +242,7 @@ fn parse_heading(buf: &[u8]) -> ParseResult<'_> {
248242
}
249243

250244
let (txt, rest) = parse_to_newline(&buf[1..]);
251-
let ctx = Context { top_block: false, prev: Prev::Whitespace };
245+
let ctx = Context { .. };
252246
let stream = parse_recursive(txt, ctx);
253247

254248
Some((MdTree::Heading(level.try_into().unwrap(), stream), rest))
@@ -257,7 +251,7 @@ fn parse_heading(buf: &[u8]) -> ParseResult<'_> {
257251
/// Bulleted list
258252
fn parse_unordered_li(buf: &[u8]) -> Parsed<'_> {
259253
let (txt, rest) = get_indented_section(&buf[2..]);
260-
let ctx = Context { top_block: false, prev: Prev::Whitespace };
254+
let ctx = Context { .. };
261255
let stream = parse_recursive(trim_ascii_start(txt), ctx);
262256
(MdTree::UnorderedListItem(stream), rest)
263257
}
@@ -266,7 +260,7 @@ fn parse_unordered_li(buf: &[u8]) -> Parsed<'_> {
266260
fn parse_ordered_li(buf: &[u8]) -> Parsed<'_> {
267261
let (num, pos) = ord_list_start(buf).unwrap(); // success tested in caller
268262
let (txt, rest) = get_indented_section(&buf[pos..]);
269-
let ctx = Context { top_block: false, prev: Prev::Whitespace };
263+
let ctx = Context { .. };
270264
let stream = parse_recursive(trim_ascii_start(txt), ctx);
271265
(MdTree::OrderedListItem(num, stream), rest)
272266
}

0 commit comments

Comments
 (0)