Skip to content

Commit 5782d9e

Browse files
authored
Rollup merge of rust-lang#146340 - fmease:frontmatter-containment, r=fee1-dead,Urgau
Strip frontmatter in fewer places * Stop stripping frontmatter in `proc_macro::Literal::from_str` (RUST-146132) * Stop stripping frontmatter in expr-ctxt (but not item-ctxt!) `include`s (RUST-145945) * Stop stripping shebang (!) in `proc_macro::Literal::from_str` * Not a breaking change because it did compare spans already to ensure there wasn't extra whitespace or comments (`Literal::from_str("#!\n0")` already yields `Err(_)` thankfully!) * Stop stripping frontmatter+shebang inside some rustdoc code where it doesn't make any observable difference (see self review comments) * (Stop stripping frontmatter+shebang inside internal test code) Fixes rust-lang#145945. Fixes rust-lang#146132. r? fee1-dead
2 parents a6acb29 + c9ed8a1 commit 5782d9e

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

clippy_lints/src/doc/needless_doctest_main.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_ast::{CoroutineKind, Fn, FnRetTy, Item, ItemKind};
88
use rustc_errors::emitter::HumanEmitter;
99
use rustc_errors::{Diag, DiagCtxt};
1010
use rustc_lint::LateContext;
11+
use rustc_parse::lexer::StripTokens;
1112
use rustc_parse::new_parser_from_source_str;
1213
use rustc_parse::parser::ForceCollect;
1314
use rustc_session::parse::ParseSess;
@@ -49,13 +50,14 @@ pub fn check(
4950
let sm = Arc::new(SourceMap::new(FilePathMapping::empty()));
5051
let psess = ParseSess::with_dcx(dcx, sm);
5152

52-
let mut parser = match new_parser_from_source_str(&psess, filename, code) {
53-
Ok(p) => p,
54-
Err(errs) => {
55-
errs.into_iter().for_each(Diag::cancel);
56-
return (false, test_attr_spans);
57-
},
58-
};
53+
let mut parser =
54+
match new_parser_from_source_str(&psess, filename, code, StripTokens::ShebangAndFrontmatter) {
55+
Ok(p) => p,
56+
Err(errs) => {
57+
errs.into_iter().for_each(Diag::cancel);
58+
return (false, test_attr_spans);
59+
},
60+
};
5961

6062
let mut relevant_main_found = false;
6163
let mut eligible = true;

0 commit comments

Comments
 (0)