-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Strip frontmatter in fewer places #146340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This comment has been minimized.
This comment has been minimized.
7f38e98
to
6071c21
Compare
This comment has been minimized.
This comment has been minimized.
6071c21
to
50f74e5
Compare
This comment has been minimized.
This comment has been minimized.
50f74e5
to
96edbd6
Compare
This comment has been minimized.
This comment has been minimized.
self.psess(), | ||
name, | ||
s.to_owned(), | ||
StripTokens::Nothing, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updating this to not strip shebangs isn't breaking.
It already compares spans below to ensure no extra trivia is contained like whitespace, comments or – well – shebangs. However, it's just cleaner to pass Nothing
here.
/// | ||
/// On failure, the errors must be consumed via `unwrap_or_emit_fatal`, `emit`, `cancel`, | ||
/// etc., otherwise a panic will occur when they are dropped. | ||
pub fn new_parser_from_simple_source_str( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing this convenience wrapper (for StripTokens::Nothing
) to force all callers to have to think what behavior they want which is a lot more robust. Otherwise, people will just overlook this function and blindly go for the "normal" variant new_parser_from_source_str
.
psess: &ParseSess, | ||
name: FileName, | ||
source: String, | ||
override_span: Option<Span>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might add strip_tokens: StripTokens
as a parameter to this function in a future PR. At the time of writing, it wouldn't really matter but there are some call sites like the one for -Zcrate-attr
where we could pass StripTokens::Nothing
(since the input is wrapped in #![
]
anyway) but it wouldn't lead to any observable difference in rustc's behavior.
&psess, | ||
file_name, | ||
snippet.clone(), | ||
StripTokens::Nothing, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't make a difference since this is for (re)parsing macro matchers which will have already been validated by rustc and shebangs or frontmatters aren't part of that subgrammar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just test code; use StripTokens::Nothing
for simplicity. If anybody wants to test shebangs and/or frontmatter in here, they can just update it.
}; | ||
// Don't strip any tokens; it wouldn't matter anyway because the source is wrapped in a function. | ||
let mut parser = | ||
match new_parser_from_source_str(&psess, filename, wrapped_source, StripTokens::Nothing) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change is unobservable as the added comment explains.
let parser = rustc_parse::unwrap_or_emit_fatal(rustc_parse::new_parser_from_source_str( | ||
psess, | ||
FileName::anon_source_code(source_code), | ||
rustc_parse::lexer::StripTokens::Nothing, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also just test code.
96edbd6
to
541e36f
Compare
Some changes occurred in src/tools/clippy cc @rust-lang/clippy Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
This comment has been minimized.
This comment has been minimized.
541e36f
to
7a66925
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, r=me when green
@bors r=fee1-dead,Urgau rollup |
…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
…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
Rollup of 6 pull requests Successful merges: - #146311 (Minor symbol comment fixes.) - #146340 (Strip frontmatter in fewer places) - #146342 (Improve C-variadic error messages: part 2) - #146347 (report duplicate symbols added by the driver) - #146374 (Update `browser-ui-test` version to `0.22.2`) - #146379 (Fix `compare_against_sw_vers` test) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 8 pull requests Successful merges: - #145327 (std: make address resolution weirdness local to SGX) - #145879 (default auto traits: use default supertraits instead of `Self: Trait` bounds on associated items) - #146123 (Suggest examples of format specifiers in error messages) - #146311 (Minor symbol comment fixes.) - #146322 (Make Barrier RefUnwindSafe again) - #146327 (Add tests for deref on pin) - #146340 (Strip frontmatter in fewer places) - #146342 (Improve C-variadic error messages: part 2) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #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 #145945. Fixes #146132. r? fee1-dead
…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
proc_macro::Literal::from_str
(RUST-146132)include
s (RUST-145945)proc_macro::Literal::from_str
Literal::from_str("#!\n0")
already yieldsErr(_)
thankfully!)Fixes #145945.
Fixes #146132.
r? fee1-dead