Remove stream_to_parser
.
It's a zero-value wrapper of `Parser::new`.
This commit is contained in:
parent
769ca3f661
commit
3c321b9ea8
7 changed files with 13 additions and 25 deletions
|
@ -196,7 +196,7 @@ impl CfgEval<'_, '_> {
|
|||
// Re-parse the tokens, setting the `capture_cfg` flag to save extra information
|
||||
// to the captured `AttrTokenStream` (specifically, we capture
|
||||
// `AttrTokenTree::AttributesData` for all occurrences of `#[cfg]` and `#[cfg_attr]`)
|
||||
let mut parser = rustc_parse::stream_to_parser(&self.cfg.sess.psess, orig_tokens, None);
|
||||
let mut parser = Parser::new(&self.cfg.sess.psess, orig_tokens, None);
|
||||
parser.capture_cfg = true;
|
||||
match parse_annotatable_with(&mut parser) {
|
||||
Ok(a) => annotatable = a,
|
||||
|
|
|
@ -15,7 +15,7 @@ use rustc_data_structures::sync::{self, Lrc};
|
|||
use rustc_errors::{DiagCtxt, ErrorGuaranteed, PResult};
|
||||
use rustc_feature::Features;
|
||||
use rustc_lint_defs::{BufferedEarlyLint, RegisteredTools};
|
||||
use rustc_parse::{parser, MACRO_ARGUMENTS};
|
||||
use rustc_parse::{parser::Parser, MACRO_ARGUMENTS};
|
||||
use rustc_session::config::CollapseMacroDebuginfo;
|
||||
use rustc_session::{parse::ParseSess, Limit, Session};
|
||||
use rustc_span::def_id::{CrateNum, DefId, LocalDefId};
|
||||
|
@ -1149,8 +1149,8 @@ impl<'a> ExtCtxt<'a> {
|
|||
pub fn monotonic_expander<'b>(&'b mut self) -> expand::MacroExpander<'b, 'a> {
|
||||
expand::MacroExpander::new(self, true)
|
||||
}
|
||||
pub fn new_parser_from_tts(&self, stream: TokenStream) -> parser::Parser<'a> {
|
||||
rustc_parse::stream_to_parser(&self.sess.psess, stream, MACRO_ARGUMENTS)
|
||||
pub fn new_parser_from_tts(&self, stream: TokenStream) -> Parser<'a> {
|
||||
Parser::new(&self.sess.psess, stream, MACRO_ARGUMENTS)
|
||||
}
|
||||
pub fn source_map(&self) -> &'a SourceMap {
|
||||
self.sess.psess.source_map()
|
||||
|
|
|
@ -6,7 +6,7 @@ use rustc_ast as ast;
|
|||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::tokenstream::TokenStream;
|
||||
use rustc_errors::ErrorGuaranteed;
|
||||
use rustc_parse::parser::ForceCollect;
|
||||
use rustc_parse::parser::{ForceCollect, Parser};
|
||||
use rustc_session::config::ProcMacroExecutionStrategy;
|
||||
use rustc_span::profiling::SpannedEventArgRecorder;
|
||||
use rustc_span::Span;
|
||||
|
@ -154,8 +154,7 @@ impl MultiItemModifier for DeriveProcMacro {
|
|||
};
|
||||
|
||||
let error_count_before = ecx.dcx().err_count();
|
||||
let mut parser =
|
||||
rustc_parse::stream_to_parser(&ecx.sess.psess, stream, Some("proc-macro derive"));
|
||||
let mut parser = Parser::new(&ecx.sess.psess, stream, Some("proc-macro derive"));
|
||||
let mut items = vec![];
|
||||
|
||||
loop {
|
||||
|
|
|
@ -13,6 +13,7 @@ use rustc_data_structures::fx::FxHashMap;
|
|||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_errors::{Diag, ErrorGuaranteed, MultiSpan, PResult};
|
||||
use rustc_parse::lexer::nfc_normalize;
|
||||
use rustc_parse::parser::Parser;
|
||||
use rustc_parse::source_str_to_stream;
|
||||
use rustc_session::parse::ParseSess;
|
||||
use rustc_span::def_id::CrateNum;
|
||||
|
@ -553,11 +554,7 @@ impl server::TokenStream for Rustc<'_, '_> {
|
|||
fn expand_expr(&mut self, stream: &Self::TokenStream) -> Result<Self::TokenStream, ()> {
|
||||
// Parse the expression from our tokenstream.
|
||||
let expr: PResult<'_, _> = try {
|
||||
let mut p = rustc_parse::stream_to_parser(
|
||||
self.psess(),
|
||||
stream.clone(),
|
||||
Some("proc_macro expand expr"),
|
||||
);
|
||||
let mut p = Parser::new(self.psess(), stream.clone(), Some("proc_macro expand expr"));
|
||||
let expr = p.parse_expr()?;
|
||||
if p.token != token::Eof {
|
||||
p.unexpected()?;
|
||||
|
|
|
@ -2,6 +2,7 @@ use super::diagnostics::report_suspicious_mismatch_block;
|
|||
use super::diagnostics::same_indentation_level;
|
||||
use super::diagnostics::TokenTreeDiagInfo;
|
||||
use super::{StringReader, UnmatchedDelim};
|
||||
use crate::Parser;
|
||||
use rustc_ast::token::{self, Delimiter, Token};
|
||||
use rustc_ast::tokenstream::{DelimSpacing, DelimSpan, Spacing, TokenStream, TokenTree};
|
||||
use rustc_ast_pretty::pprust::token_to_string;
|
||||
|
@ -231,7 +232,7 @@ impl<'psess, 'src> TokenTreesReader<'psess, 'src> {
|
|||
) -> Vec<PErr<'psess>> {
|
||||
// If there are unclosed delims, see if there are diff markers and if so, point them
|
||||
// out instead of complaining about the unclosed delims.
|
||||
let mut parser = crate::stream_to_parser(self.string_reader.psess, tts, None);
|
||||
let mut parser = Parser::new(self.string_reader.psess, tts, None);
|
||||
let mut diff_errs = vec![];
|
||||
// Suggest removing a `{` we think appears in an `if`/`while` condition.
|
||||
// We want to suggest removing a `{` only if we think we're in an `if`/`while` condition,
|
||||
|
|
|
@ -123,7 +123,7 @@ fn maybe_source_file_to_parser(
|
|||
) -> Result<Parser<'_>, Vec<Diag<'_>>> {
|
||||
let end_pos = source_file.end_position();
|
||||
let stream = maybe_source_file_to_stream(psess, source_file, None)?;
|
||||
let mut parser = stream_to_parser(psess, stream, None);
|
||||
let mut parser = Parser::new(psess, stream, None);
|
||||
if parser.token == token::Eof {
|
||||
parser.token.span = Span::new(end_pos, end_pos, parser.token.span.ctxt(), None);
|
||||
}
|
||||
|
@ -168,15 +168,6 @@ fn maybe_source_file_to_stream<'psess>(
|
|||
lexer::lex_token_trees(psess, src.as_str(), source_file.start_pos, override_span)
|
||||
}
|
||||
|
||||
/// Given a stream and the `ParseSess`, produces a parser.
|
||||
pub fn stream_to_parser<'a>(
|
||||
psess: &'a ParseSess,
|
||||
stream: TokenStream,
|
||||
subparser_name: Option<&'static str>,
|
||||
) -> Parser<'a> {
|
||||
Parser::new(psess, stream, subparser_name)
|
||||
}
|
||||
|
||||
/// Runs the given subparser `f` on the tokens of the given `attr`'s item.
|
||||
pub fn parse_in<'a, T>(
|
||||
psess: &'a ParseSess,
|
||||
|
|
|
@ -2,7 +2,7 @@ use rustc_ast::token::{Delimiter, NonterminalKind, TokenKind};
|
|||
use rustc_ast::tokenstream::TokenStream;
|
||||
use rustc_ast::{ast, ptr};
|
||||
use rustc_parse::parser::{ForceCollect, Parser, Recovery};
|
||||
use rustc_parse::{stream_to_parser, MACRO_ARGUMENTS};
|
||||
use rustc_parse::MACRO_ARGUMENTS;
|
||||
use rustc_session::parse::ParseSess;
|
||||
use rustc_span::symbol::{self, kw};
|
||||
use rustc_span::Symbol;
|
||||
|
@ -15,7 +15,7 @@ pub(crate) mod cfg_if;
|
|||
pub(crate) mod lazy_static;
|
||||
|
||||
fn build_stream_parser<'a>(psess: &'a ParseSess, tokens: TokenStream) -> Parser<'a> {
|
||||
stream_to_parser(psess, tokens, MACRO_ARGUMENTS).recovery(Recovery::Forbidden)
|
||||
Parser::new(psess, tokens, MACRO_ARGUMENTS).recovery(Recovery::Forbidden)
|
||||
}
|
||||
|
||||
fn build_parser<'a>(context: &RewriteContext<'a>, tokens: TokenStream) -> Parser<'a> {
|
||||
|
|
Loading…
Add table
Reference in a new issue