Skip to content

Commit 463ce40

Browse files
committed
Auto merge of #80206 - poliorcetics:rustdoc-default-langstring, r=GuillaumeGomez,jyn514
impl Default for LangString, replacing all_false by default Fix #80015 `@rustbot` label C-cleanup T-rustdoc A-markdown-parsing
2 parents 15d1f81 + 74bd2ea commit 463ce40

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)));
@@ -666,7 +666,7 @@ crate fn find_testable_code<T: doctest::Tester>(
666666
let block_info = match kind {
667667
CodeBlockKind::Fenced(ref lang) => {
668668
if lang.is_empty() {
669-
LangString::all_false()
669+
Default::default()
670670
} else {
671671
LangString::parse(
672672
lang,
@@ -676,7 +676,7 @@ crate fn find_testable_code<T: doctest::Tester>(
676676
)
677677
}
678678
}
679-
CodeBlockKind::Indented => LangString::all_false(),
679+
CodeBlockKind::Indented => Default::default(),
680680
};
681681
if !block_info.rust {
682682
continue;
@@ -779,22 +779,24 @@ crate enum Ignore {
779779
Some(Vec<String>),
780780
}
781781

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

799+
impl LangString {
798800
fn parse_without_check(
799801
string: &str,
800802
allow_error_code_check: ErrorCodes,
@@ -812,7 +814,7 @@ impl LangString {
812814
let allow_error_code_check = allow_error_code_check.as_bool();
813815
let mut seen_rust_tags = false;
814816
let mut seen_other_tags = false;
815-
let mut data = LangString::all_false();
817+
let mut data = LangString::default();
816818
let mut ignores = vec![];
817819

818820
data.original = string.to_owned();
@@ -1230,7 +1232,7 @@ crate fn rust_code_blocks(md: &str, extra_info: &ExtraInfo<'_, '_>) -> Vec<RustC
12301232
CodeBlockKind::Fenced(syntax) => {
12311233
let syntax = syntax.as_ref();
12321234
let lang_string = if syntax.is_empty() {
1233-
LangString::all_false()
1235+
Default::default()
12341236
} else {
12351237
LangString::parse(&*syntax, ErrorCodes::Yes, false, Some(extra_info))
12361238
};

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)