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