Skip to content

Commit d81f6f3

Browse files
committed
Remove stream_to_parser.
It's a zero-value wrapper of `Parser::new`.
1 parent fc2bbb3 commit d81f6f3

File tree

7 files changed

+13
-25
lines changed

7 files changed

+13
-25
lines changed

compiler/rustc_builtin_macros/src/cfg_eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl CfgEval<'_, '_> {
196196
// Re-parse the tokens, setting the `capture_cfg` flag to save extra information
197197
// to the captured `AttrTokenStream` (specifically, we capture
198198
// `AttrTokenTree::AttributesData` for all occurrences of `#[cfg]` and `#[cfg_attr]`)
199-
let mut parser = rustc_parse::stream_to_parser(&self.cfg.sess.psess, orig_tokens, None);
199+
let mut parser = Parser::new(&self.cfg.sess.psess, orig_tokens, None);
200200
parser.capture_cfg = true;
201201
match parse_annotatable_with(&mut parser) {
202202
Ok(a) => annotatable = a,

compiler/rustc_expand/src/base.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_errors::{DiagCtxt, ErrorGuaranteed, PResult};
1616
use rustc_feature::Features;
1717
use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT;
1818
use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiag, RegisteredTools};
19-
use rustc_parse::{parser, MACRO_ARGUMENTS};
19+
use rustc_parse::{parser::Parser, MACRO_ARGUMENTS};
2020
use rustc_session::config::CollapseMacroDebuginfo;
2121
use rustc_session::{parse::ParseSess, Limit, Session};
2222
use rustc_span::def_id::{CrateNum, DefId, LocalDefId};
@@ -1150,8 +1150,8 @@ impl<'a> ExtCtxt<'a> {
11501150
pub fn monotonic_expander<'b>(&'b mut self) -> expand::MacroExpander<'b, 'a> {
11511151
expand::MacroExpander::new(self, true)
11521152
}
1153-
pub fn new_parser_from_tts(&self, stream: TokenStream) -> parser::Parser<'a> {
1154-
rustc_parse::stream_to_parser(&self.sess.psess, stream, MACRO_ARGUMENTS)
1153+
pub fn new_parser_from_tts(&self, stream: TokenStream) -> Parser<'a> {
1154+
Parser::new(&self.sess.psess, stream, MACRO_ARGUMENTS)
11551155
}
11561156
pub fn source_map(&self) -> &'a SourceMap {
11571157
self.sess.psess.source_map()

compiler/rustc_expand/src/proc_macro.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_ast::token;
88
use rustc_ast::tokenstream::TokenStream;
99
use rustc_data_structures::sync::Lrc;
1010
use rustc_errors::ErrorGuaranteed;
11-
use rustc_parse::parser::ForceCollect;
11+
use rustc_parse::parser::{ForceCollect, Parser};
1212
use rustc_session::config::ProcMacroExecutionStrategy;
1313
use rustc_span::profiling::SpannedEventArgRecorder;
1414
use rustc_span::{Span, DUMMY_SP};
@@ -161,8 +161,7 @@ impl MultiItemModifier for DeriveProcMacro {
161161
};
162162

163163
let error_count_before = ecx.dcx().err_count();
164-
let mut parser =
165-
rustc_parse::stream_to_parser(&ecx.sess.psess, stream, Some("proc-macro derive"));
164+
let mut parser = Parser::new(&ecx.sess.psess, stream, Some("proc-macro derive"));
166165
let mut items = vec![];
167166

168167
loop {

compiler/rustc_expand/src/proc_macro_server.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rustc_data_structures::fx::FxHashMap;
1313
use rustc_data_structures::sync::Lrc;
1414
use rustc_errors::{Diag, ErrorGuaranteed, MultiSpan, PResult};
1515
use rustc_parse::lexer::nfc_normalize;
16+
use rustc_parse::parser::Parser;
1617
use rustc_parse::source_str_to_stream;
1718
use rustc_session::parse::ParseSess;
1819
use rustc_span::def_id::CrateNum;
@@ -554,11 +555,7 @@ impl server::TokenStream for Rustc<'_, '_> {
554555
fn expand_expr(&mut self, stream: &Self::TokenStream) -> Result<Self::TokenStream, ()> {
555556
// Parse the expression from our tokenstream.
556557
let expr: PResult<'_, _> = try {
557-
let mut p = rustc_parse::stream_to_parser(
558-
self.psess(),
559-
stream.clone(),
560-
Some("proc_macro expand expr"),
561-
);
558+
let mut p = Parser::new(self.psess(), stream.clone(), Some("proc_macro expand expr"));
562559
let expr = p.parse_expr()?;
563560
if p.token != token::Eof {
564561
p.unexpected()?;

compiler/rustc_parse/src/lexer/tokentrees.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use super::diagnostics::report_suspicious_mismatch_block;
22
use super::diagnostics::same_indentation_level;
33
use super::diagnostics::TokenTreeDiagInfo;
44
use super::{StringReader, UnmatchedDelim};
5+
use crate::Parser;
56
use rustc_ast::token::{self, Delimiter, Token};
67
use rustc_ast::tokenstream::{DelimSpacing, DelimSpan, Spacing, TokenStream, TokenTree};
78
use rustc_ast_pretty::pprust::token_to_string;
@@ -231,7 +232,7 @@ impl<'psess, 'src> TokenTreesReader<'psess, 'src> {
231232
) -> Vec<PErr<'psess>> {
232233
// If there are unclosed delims, see if there are diff markers and if so, point them
233234
// out instead of complaining about the unclosed delims.
234-
let mut parser = crate::stream_to_parser(self.string_reader.psess, tts, None);
235+
let mut parser = Parser::new(self.string_reader.psess, tts, None);
235236
let mut diff_errs = vec![];
236237
// Suggest removing a `{` we think appears in an `if`/`while` condition.
237238
// We want to suggest removing a `{` only if we think we're in an `if`/`while` condition,

compiler/rustc_parse/src/lib.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ fn maybe_source_file_to_parser(
122122
) -> Result<Parser<'_>, Vec<Diag<'_>>> {
123123
let end_pos = source_file.end_position();
124124
let stream = maybe_source_file_to_stream(psess, source_file, None)?;
125-
let mut parser = stream_to_parser(psess, stream, None);
125+
let mut parser = Parser::new(psess, stream, None);
126126
if parser.token == token::Eof {
127127
parser.token.span = Span::new(end_pos, end_pos, parser.token.span.ctxt(), None);
128128
}
@@ -167,15 +167,6 @@ fn maybe_source_file_to_stream<'psess>(
167167
lexer::lex_token_trees(psess, src.as_str(), source_file.start_pos, override_span)
168168
}
169169

170-
/// Given a stream and the `ParseSess`, produces a parser.
171-
pub fn stream_to_parser<'a>(
172-
psess: &'a ParseSess,
173-
stream: TokenStream,
174-
subparser_name: Option<&'static str>,
175-
) -> Parser<'a> {
176-
Parser::new(psess, stream, subparser_name)
177-
}
178-
179170
/// Runs the given subparser `f` on the tokens of the given `attr`'s item.
180171
pub fn parse_in<'a, T>(
181172
psess: &'a ParseSess,

src/tools/rustfmt/src/parse/macros/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_ast::token::{Delimiter, NonterminalKind, TokenKind};
22
use rustc_ast::tokenstream::TokenStream;
33
use rustc_ast::{ast, ptr};
44
use rustc_parse::parser::{ForceCollect, Parser, Recovery};
5-
use rustc_parse::{stream_to_parser, MACRO_ARGUMENTS};
5+
use rustc_parse::MACRO_ARGUMENTS;
66
use rustc_session::parse::ParseSess;
77
use rustc_span::symbol::{self, kw};
88
use rustc_span::Symbol;
@@ -15,7 +15,7 @@ pub(crate) mod cfg_if;
1515
pub(crate) mod lazy_static;
1616

1717
fn build_stream_parser<'a>(psess: &'a ParseSess, tokens: TokenStream) -> Parser<'a> {
18-
stream_to_parser(psess, tokens, MACRO_ARGUMENTS).recovery(Recovery::Forbidden)
18+
Parser::new(psess, tokens, MACRO_ARGUMENTS).recovery(Recovery::Forbidden)
1919
}
2020

2121
fn build_parser<'a>(context: &RewriteContext<'a>, tokens: TokenStream) -> Parser<'a> {

0 commit comments

Comments
 (0)