From 2e6ce68fba372f2a334abfe3f0118782776b8b74 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 31 Jul 2023 12:49:01 +1000 Subject: [PATCH] Remove `desugar_doc_comments` arg from `Parser::new()`. It's only true at one call site; do the desugaring there instead. --- compiler/rustc_expand/src/mbe/macro_rules.rs | 13 +++++++++---- compiler/rustc_parse/src/lib.rs | 4 ++-- compiler/rustc_parse/src/parser/mod.rs | 7 +------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs index dcf11527ba9..0e4af6f1c03 100644 --- a/compiler/rustc_expand/src/mbe/macro_rules.rs +++ b/compiler/rustc_expand/src/mbe/macro_rules.rs @@ -249,7 +249,7 @@ fn expand_macro<'cx>( trace_macros_note(&mut cx.expansions, sp, msg); } - let p = Parser::new(sess, tts, false, None); + let p = Parser::new(sess, tts, None); if is_local { cx.resolver.record_macro_rule_usage(node_id, i); @@ -446,7 +446,7 @@ pub fn compile_declarative_macro( let create_parser = || { let body = macro_def.body.tokens.clone(); - Parser::new(&sess.parse_sess, body, false, rustc_parse::MACRO_ARGUMENTS) + Parser::new(&sess.parse_sess, body, rustc_parse::MACRO_ARGUMENTS) }; let parser = create_parser(); @@ -1417,6 +1417,11 @@ fn quoted_tt_to_string(tt: &mbe::TokenTree) -> String { } } -pub(super) fn parser_from_cx(sess: &ParseSess, tts: TokenStream, recovery: Recovery) -> Parser<'_> { - Parser::new(sess, tts, true, rustc_parse::MACRO_ARGUMENTS).recovery(recovery) +pub(super) fn parser_from_cx( + sess: &ParseSess, + mut tts: TokenStream, + recovery: Recovery, +) -> Parser<'_> { + tts.desugar_doc_comments(); + Parser::new(sess, tts, rustc_parse::MACRO_ARGUMENTS).recovery(recovery) } diff --git a/compiler/rustc_parse/src/lib.rs b/compiler/rustc_parse/src/lib.rs index 25de7808532..52990a3bd0d 100644 --- a/compiler/rustc_parse/src/lib.rs +++ b/compiler/rustc_parse/src/lib.rs @@ -205,7 +205,7 @@ pub fn stream_to_parser<'a>( stream: TokenStream, subparser_name: Option<&'static str>, ) -> Parser<'a> { - Parser::new(sess, stream, false, subparser_name) + Parser::new(sess, stream, subparser_name) } /// Runs the given subparser `f` on the tokens of the given `attr`'s item. @@ -215,7 +215,7 @@ pub fn parse_in<'a, T>( name: &'static str, mut f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>, ) -> PResult<'a, T> { - let mut parser = Parser::new(sess, tts, false, Some(name)); + let mut parser = Parser::new(sess, tts, Some(name)); let result = f(&mut parser)?; if parser.token != token::Eof { parser.unexpected()?; diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 7d39bf8edf3..d689b61f63f 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -388,14 +388,9 @@ pub(super) fn token_descr(token: &Token) -> String { impl<'a> Parser<'a> { pub fn new( sess: &'a ParseSess, - mut stream: TokenStream, - desugar_doc_comments: bool, + stream: TokenStream, subparser_name: Option<&'static str>, ) -> Self { - if desugar_doc_comments { - stream.desugar_doc_comments(); - } - let mut parser = Parser { sess, token: Token::dummy(),