Skip to content

Commit

Permalink
impl Default for LangString, replacing all_false by default
Browse files Browse the repository at this point in the history
  • Loading branch information
poliorcetics committed Dec 19, 2020
1 parent 1b6b06a commit 74bd2ea
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 39 deletions.
20 changes: 11 additions & 9 deletions src/librustdoc/html/markdown.rs
Expand Up @@ -204,7 +204,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
CodeBlockKind::Fenced(ref lang) => {
LangString::parse_without_check(&lang, self.check_error_codes, false)
}
CodeBlockKind::Indented => LangString::all_false(),
CodeBlockKind::Indented => Default::default(),
};
if !parse_result.rust {
return Some(Event::Start(Tag::CodeBlock(kind)));
Expand Down Expand Up @@ -665,7 +665,7 @@ crate fn find_testable_code<T: doctest::Tester>(
let block_info = match kind {
CodeBlockKind::Fenced(ref lang) => {
if lang.is_empty() {
LangString::all_false()
Default::default()
} else {
LangString::parse(
lang,
Expand All @@ -675,7 +675,7 @@ crate fn find_testable_code<T: doctest::Tester>(
)
}
}
CodeBlockKind::Indented => LangString::all_false(),
CodeBlockKind::Indented => Default::default(),
};
if !block_info.rust {
continue;
Expand Down Expand Up @@ -778,22 +778,24 @@ crate enum Ignore {
Some(Vec<String>),
}

impl LangString {
fn all_false() -> LangString {
LangString {
impl Default for LangString {
fn default() -> Self {
Self {
original: String::new(),
should_panic: false,
no_run: false,
ignore: Ignore::None,
rust: true, // NB This used to be `notrust = false`
rust: true,
test_harness: false,
compile_fail: false,
error_codes: Vec::new(),
allow_fail: false,
edition: None,
}
}
}

impl LangString {
fn parse_without_check(
string: &str,
allow_error_code_check: ErrorCodes,
Expand All @@ -811,7 +813,7 @@ impl LangString {
let allow_error_code_check = allow_error_code_check.as_bool();
let mut seen_rust_tags = false;
let mut seen_other_tags = false;
let mut data = LangString::all_false();
let mut data = LangString::default();
let mut ignores = vec![];

data.original = string.to_owned();
Expand Down Expand Up @@ -1233,7 +1235,7 @@ crate fn rust_code_blocks(md: &str, extra_info: &ExtraInfo<'_, '_>) -> Vec<RustC
CodeBlockKind::Fenced(syntax) => {
let syntax = syntax.as_ref();
let lang_string = if syntax.is_empty() {
LangString::all_false()
Default::default()
} else {
LangString::parse(&*syntax, ErrorCodes::Yes, false, Some(extra_info))
};
Expand Down
48 changes: 18 additions & 30 deletions src/librustdoc/html/markdown/tests.rs
Expand Up @@ -56,71 +56,59 @@ fn test_lang_string_parse() {
assert_eq!(LangString::parse(s, ErrorCodes::Yes, true, None), lg)
}

t(LangString::all_false());
t(LangString { original: "rust".into(), ..LangString::all_false() });
t(LangString { original: "sh".into(), rust: false, ..LangString::all_false() });
t(LangString { original: "ignore".into(), ignore: Ignore::All, ..LangString::all_false() });
t(Default::default());
t(LangString { original: "rust".into(), ..Default::default() });
t(LangString { original: "sh".into(), rust: false, ..Default::default() });
t(LangString { original: "ignore".into(), ignore: Ignore::All, ..Default::default() });
t(LangString {
original: "ignore-foo".into(),
ignore: Ignore::Some(vec!["foo".to_string()]),
..LangString::all_false()
});
t(LangString {
original: "should_panic".into(),
should_panic: true,
..LangString::all_false()
});
t(LangString { original: "no_run".into(), no_run: true, ..LangString::all_false() });
t(LangString {
original: "test_harness".into(),
test_harness: true,
..LangString::all_false()
..Default::default()
});
t(LangString { original: "should_panic".into(), should_panic: true, ..Default::default() });
t(LangString { original: "no_run".into(), no_run: true, ..Default::default() });
t(LangString { original: "test_harness".into(), test_harness: true, ..Default::default() });
t(LangString {
original: "compile_fail".into(),
no_run: true,
compile_fail: true,
..LangString::all_false()
});
t(LangString { original: "allow_fail".into(), allow_fail: true, ..LangString::all_false() });
t(LangString {
original: "{.no_run .example}".into(),
no_run: true,
..LangString::all_false()
..Default::default()
});
t(LangString { original: "allow_fail".into(), allow_fail: true, ..Default::default() });
t(LangString { original: "{.no_run .example}".into(), no_run: true, ..Default::default() });
t(LangString {
original: "{.sh .should_panic}".into(),
should_panic: true,
rust: false,
..LangString::all_false()
..Default::default()
});
t(LangString { original: "{.example .rust}".into(), ..LangString::all_false() });
t(LangString { original: "{.example .rust}".into(), ..Default::default() });
t(LangString {
original: "{.test_harness .rust}".into(),
test_harness: true,
..LangString::all_false()
..Default::default()
});
t(LangString {
original: "text, no_run".into(),
no_run: true,
rust: false,
..LangString::all_false()
..Default::default()
});
t(LangString {
original: "text,no_run".into(),
no_run: true,
rust: false,
..LangString::all_false()
..Default::default()
});
t(LangString {
original: "edition2015".into(),
edition: Some(Edition::Edition2015),
..LangString::all_false()
..Default::default()
});
t(LangString {
original: "edition2018".into(),
edition: Some(Edition::Edition2018),
..LangString::all_false()
..Default::default()
});
}

Expand Down

0 comments on commit 74bd2ea

Please sign in to comment.