Skip to content

Commit 74bd2ea

Browse files
committed
impl Default for LangString, replacing all_false by default
1 parent 1b6b06a commit 74bd2ea

File tree

2 files changed

+29
-39
lines changed

2 files changed

+29
-39
lines changed

src/librustdoc/html/markdown.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
204204
CodeBlockKind::Fenced(ref lang) => {
205205
LangString::parse_without_check(&lang, self.check_error_codes, false)
206206
}
207-
CodeBlockKind::Indented => LangString::all_false(),
207+
CodeBlockKind::Indented => Default::default(),
208208
};
209209
if !parse_result.rust {
210210
return Some(Event::Start(Tag::CodeBlock(kind)));
@@ -665,7 +665,7 @@ crate fn find_testable_code<T: doctest::Tester>(
665665
let block_info = match kind {
666666
CodeBlockKind::Fenced(ref lang) => {
667667
if lang.is_empty() {
668-
LangString::all_false()
668+
Default::default()
669669
} else {
670670
LangString::parse(
671671
lang,
@@ -675,7 +675,7 @@ crate fn find_testable_code<T: doctest::Tester>(
675675
)
676676
}
677677
}
678-
CodeBlockKind::Indented => LangString::all_false(),
678+
CodeBlockKind::Indented => Default::default(),
679679
};
680680
if !block_info.rust {
681681
continue;
@@ -778,22 +778,24 @@ crate enum Ignore {
778778
Some(Vec<String>),
779779
}
780780

781-
impl LangString {
782-
fn all_false() -> LangString {
783-
LangString {
781+
impl Default for LangString {
782+
fn default() -> Self {
783+
Self {
784784
original: String::new(),
785785
should_panic: false,
786786
no_run: false,
787787
ignore: Ignore::None,
788-
rust: true, // NB This used to be `notrust = false`
788+
rust: true,
789789
test_harness: false,
790790
compile_fail: false,
791791
error_codes: Vec::new(),
792792
allow_fail: false,
793793
edition: None,
794794
}
795795
}
796+
}
796797

798+
impl LangString {
797799
fn parse_without_check(
798800
string: &str,
799801
allow_error_code_check: ErrorCodes,
@@ -811,7 +813,7 @@ impl LangString {
811813
let allow_error_code_check = allow_error_code_check.as_bool();
812814
let mut seen_rust_tags = false;
813815
let mut seen_other_tags = false;
814-
let mut data = LangString::all_false();
816+
let mut data = LangString::default();
815817
let mut ignores = vec![];
816818

817819
data.original = string.to_owned();
@@ -1233,7 +1235,7 @@ crate fn rust_code_blocks(md: &str, extra_info: &ExtraInfo<'_, '_>) -> Vec<RustC
12331235
CodeBlockKind::Fenced(syntax) => {
12341236
let syntax = syntax.as_ref();
12351237
let lang_string = if syntax.is_empty() {
1236-
LangString::all_false()
1238+
Default::default()
12371239
} else {
12381240
LangString::parse(&*syntax, ErrorCodes::Yes, false, Some(extra_info))
12391241
};

src/librustdoc/html/markdown/tests.rs

+18-30
Original file line numberDiff line numberDiff line change
@@ -56,71 +56,59 @@ fn test_lang_string_parse() {
5656
assert_eq!(LangString::parse(s, ErrorCodes::Yes, true, None), lg)
5757
}
5858

59-
t(LangString::all_false());
60-
t(LangString { original: "rust".into(), ..LangString::all_false() });
61-
t(LangString { original: "sh".into(), rust: false, ..LangString::all_false() });
62-
t(LangString { original: "ignore".into(), ignore: Ignore::All, ..LangString::all_false() });
59+
t(Default::default());
60+
t(LangString { original: "rust".into(), ..Default::default() });
61+
t(LangString { original: "sh".into(), rust: false, ..Default::default() });
62+
t(LangString { original: "ignore".into(), ignore: Ignore::All, ..Default::default() });
6363
t(LangString {
6464
original: "ignore-foo".into(),
6565
ignore: Ignore::Some(vec!["foo".to_string()]),
66-
..LangString::all_false()
67-
});
68-
t(LangString {
69-
original: "should_panic".into(),
70-
should_panic: true,
71-
..LangString::all_false()
72-
});
73-
t(LangString { original: "no_run".into(), no_run: true, ..LangString::all_false() });
74-
t(LangString {
75-
original: "test_harness".into(),
76-
test_harness: true,
77-
..LangString::all_false()
66+
..Default::default()
7867
});
68+
t(LangString { original: "should_panic".into(), should_panic: true, ..Default::default() });
69+
t(LangString { original: "no_run".into(), no_run: true, ..Default::default() });
70+
t(LangString { original: "test_harness".into(), test_harness: true, ..Default::default() });
7971
t(LangString {
8072
original: "compile_fail".into(),
8173
no_run: true,
8274
compile_fail: true,
83-
..LangString::all_false()
84-
});
85-
t(LangString { original: "allow_fail".into(), allow_fail: true, ..LangString::all_false() });
86-
t(LangString {
87-
original: "{.no_run .example}".into(),
88-
no_run: true,
89-
..LangString::all_false()
75+
..Default::default()
9076
});
77+
t(LangString { original: "allow_fail".into(), allow_fail: true, ..Default::default() });
78+
t(LangString { original: "{.no_run .example}".into(), no_run: true, ..Default::default() });
9179
t(LangString {
9280
original: "{.sh .should_panic}".into(),
9381
should_panic: true,
9482
rust: false,
95-
..LangString::all_false()
83+
..Default::default()
9684
});
97-
t(LangString { original: "{.example .rust}".into(), ..LangString::all_false() });
85+
t(LangString { original: "{.example .rust}".into(), ..Default::default() });
9886
t(LangString {
9987
original: "{.test_harness .rust}".into(),
10088
test_harness: true,
101-
..LangString::all_false()
89+
..Default::default()
10290
});
10391
t(LangString {
10492
original: "text, no_run".into(),
10593
no_run: true,
10694
rust: false,
107-
..LangString::all_false()
95+
..Default::default()
10896
});
10997
t(LangString {
11098
original: "text,no_run".into(),
11199
no_run: true,
112100
rust: false,
113-
..LangString::all_false()
101+
..Default::default()
114102
});
115103
t(LangString {
116104
original: "edition2015".into(),
117105
edition: Some(Edition::Edition2015),
118-
..LangString::all_false()
106+
..Default::default()
119107
});
120108
t(LangString {
121109
original: "edition2018".into(),
122110
edition: Some(Edition::Edition2018),
123-
..LangString::all_false()
111+
..Default::default()
124112
});
125113
}
126114

0 commit comments

Comments
 (0)