Simplify code
This commit is contained in:
parent
3818f8ba34
commit
6f0f2fc6d6
4 changed files with 16 additions and 29 deletions
|
@ -6,6 +6,7 @@ use crate::source_map::{SourceMap, FilePathMapping};
|
|||
use crate::feature_gate::UnstableFeatures;
|
||||
use crate::parse::parser::Parser;
|
||||
use crate::symbol::Symbol;
|
||||
use crate::syntax::parse::parser::emit_unclosed_delims;
|
||||
use crate::tokenstream::{TokenStream, TokenTree};
|
||||
use crate::diagnostics::plugin::ErrorMap;
|
||||
use crate::print::pprust::token_to_string;
|
||||
|
@ -141,8 +142,14 @@ pub fn parse_stream_from_source_str(
|
|||
source: String,
|
||||
sess: &ParseSess,
|
||||
override_span: Option<Span>,
|
||||
) -> (TokenStream, Vec<lexer::UnmatchedBrace>) {
|
||||
source_file_to_stream(sess, sess.source_map().new_source_file(name, source), override_span)
|
||||
) -> TokenStream {
|
||||
let (stream, mut errors) = source_file_to_stream(
|
||||
sess,
|
||||
sess.source_map().new_source_file(name, source),
|
||||
override_span,
|
||||
);
|
||||
emit_unclosed_delims(&mut errors, &sess.span_diagnostic);
|
||||
stream
|
||||
}
|
||||
|
||||
/// Creates a new parser from a source string.
|
||||
|
|
|
@ -261,11 +261,9 @@ pub struct Parser<'a> {
|
|||
|
||||
impl<'a> Drop for Parser<'a> {
|
||||
fn drop(&mut self) {
|
||||
if !self.unclosed_delims.is_empty() {
|
||||
let diag = self.diagnostic();
|
||||
emit_unclosed_delims(&mut self.unclosed_delims, diag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
|
|
@ -10,7 +10,6 @@ use crate::print::pprust;
|
|||
use crate::ptr::P;
|
||||
use crate::symbol::keywords;
|
||||
use crate::syntax::parse::parse_stream_from_source_str;
|
||||
use crate::syntax::parse::parser::emit_unclosed_delims;
|
||||
use crate::tokenstream::{self, DelimSpan, TokenStream, TokenTree};
|
||||
|
||||
use syntax_pos::symbol::{self, Symbol};
|
||||
|
@ -675,9 +674,7 @@ impl Nonterminal {
|
|||
// FIXME(#43081): Avoid this pretty-print + reparse hack
|
||||
let source = pprust::nonterminal_to_string(self);
|
||||
let filename = FileName::macro_expansion_source_code(&source);
|
||||
let (tokens_for_real, mut errors) =
|
||||
parse_stream_from_source_str(filename, source, sess, Some(span));
|
||||
emit_unclosed_delims(&mut errors, &sess.span_diagnostic);
|
||||
let tokens_for_real = parse_stream_from_source_str(filename, source, sess, Some(span));
|
||||
|
||||
// During early phases of the compiler the AST could get modified
|
||||
// directly (e.g., attributes added or removed) and the internal cache
|
||||
|
@ -740,13 +737,7 @@ fn prepend_attrs(sess: &ParseSess,
|
|||
let source = pprust::attr_to_string(attr);
|
||||
let macro_filename = FileName::macro_expansion_source_code(&source);
|
||||
if attr.is_sugared_doc {
|
||||
let (stream, mut errors) = parse_stream_from_source_str(
|
||||
macro_filename,
|
||||
source,
|
||||
sess,
|
||||
Some(span),
|
||||
);
|
||||
emit_unclosed_delims(&mut errors, &sess.span_diagnostic);
|
||||
let stream = parse_stream_from_source_str(macro_filename, source, sess, Some(span));
|
||||
builder.push(stream);
|
||||
continue
|
||||
}
|
||||
|
@ -763,13 +754,7 @@ fn prepend_attrs(sess: &ParseSess,
|
|||
// ... and for more complicated paths, fall back to a reparse hack that
|
||||
// should eventually be removed.
|
||||
} else {
|
||||
let (stream, mut errors) = parse_stream_from_source_str(
|
||||
macro_filename,
|
||||
source,
|
||||
sess,
|
||||
Some(span),
|
||||
);
|
||||
emit_unclosed_delims(&mut errors, &sess.span_diagnostic);
|
||||
let stream = parse_stream_from_source_str(macro_filename, source, sess, Some(span));
|
||||
brackets.push(stream);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ use syntax::ast;
|
|||
use syntax::ext::base::ExtCtxt;
|
||||
use syntax::parse::lexer::comments;
|
||||
use syntax::parse::{self, token, ParseSess};
|
||||
use syntax::parse::parser::emit_unclosed_delims;
|
||||
use syntax::tokenstream::{self, DelimSpan, IsJoint::*, TokenStream, TreeAndJoint};
|
||||
use syntax_pos::hygiene::{SyntaxContext, Transparency};
|
||||
use syntax_pos::symbol::{keywords, Symbol};
|
||||
|
@ -410,14 +409,12 @@ impl server::TokenStream for Rustc<'_> {
|
|||
stream.is_empty()
|
||||
}
|
||||
fn from_str(&mut self, src: &str) -> Self::TokenStream {
|
||||
let (tokens, mut errors) = parse::parse_stream_from_source_str(
|
||||
parse::parse_stream_from_source_str(
|
||||
FileName::proc_macro_source_code(src.clone()),
|
||||
src.to_string(),
|
||||
self.sess,
|
||||
Some(self.call_site),
|
||||
);
|
||||
emit_unclosed_delims(&mut errors, &self.sess.span_diagnostic);
|
||||
tokens
|
||||
)
|
||||
}
|
||||
fn to_string(&mut self, stream: &Self::TokenStream) -> String {
|
||||
stream.to_string()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue