Skip to content

Commit 6f0f2fc

Browse files
committed
Simplify code
1 parent 3818f8b commit 6f0f2fc

File tree

4 files changed

+16
-29
lines changed

4 files changed

+16
-29
lines changed

src/libsyntax/parse/mod.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::source_map::{SourceMap, FilePathMapping};
66
use crate::feature_gate::UnstableFeatures;
77
use crate::parse::parser::Parser;
88
use crate::symbol::Symbol;
9+
use crate::syntax::parse::parser::emit_unclosed_delims;
910
use crate::tokenstream::{TokenStream, TokenTree};
1011
use crate::diagnostics::plugin::ErrorMap;
1112
use crate::print::pprust::token_to_string;
@@ -141,8 +142,14 @@ pub fn parse_stream_from_source_str(
141142
source: String,
142143
sess: &ParseSess,
143144
override_span: Option<Span>,
144-
) -> (TokenStream, Vec<lexer::UnmatchedBrace>) {
145-
source_file_to_stream(sess, sess.source_map().new_source_file(name, source), override_span)
145+
) -> TokenStream {
146+
let (stream, mut errors) = source_file_to_stream(
147+
sess,
148+
sess.source_map().new_source_file(name, source),
149+
override_span,
150+
);
151+
emit_unclosed_delims(&mut errors, &sess.span_diagnostic);
152+
stream
146153
}
147154

148155
/// Creates a new parser from a source string.

src/libsyntax/parse/parser.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,8 @@ pub struct Parser<'a> {
261261

262262
impl<'a> Drop for Parser<'a> {
263263
fn drop(&mut self) {
264-
if !self.unclosed_delims.is_empty() {
265-
let diag = self.diagnostic();
266-
emit_unclosed_delims(&mut self.unclosed_delims, diag);
267-
}
264+
let diag = self.diagnostic();
265+
emit_unclosed_delims(&mut self.unclosed_delims, diag);
268266
}
269267
}
270268

src/libsyntax/parse/token.rs

+3-18
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use crate::print::pprust;
1010
use crate::ptr::P;
1111
use crate::symbol::keywords;
1212
use crate::syntax::parse::parse_stream_from_source_str;
13-
use crate::syntax::parse::parser::emit_unclosed_delims;
1413
use crate::tokenstream::{self, DelimSpan, TokenStream, TokenTree};
1514

1615
use syntax_pos::symbol::{self, Symbol};
@@ -675,9 +674,7 @@ impl Nonterminal {
675674
// FIXME(#43081): Avoid this pretty-print + reparse hack
676675
let source = pprust::nonterminal_to_string(self);
677676
let filename = FileName::macro_expansion_source_code(&source);
678-
let (tokens_for_real, mut errors) =
679-
parse_stream_from_source_str(filename, source, sess, Some(span));
680-
emit_unclosed_delims(&mut errors, &sess.span_diagnostic);
677+
let tokens_for_real = parse_stream_from_source_str(filename, source, sess, Some(span));
681678

682679
// During early phases of the compiler the AST could get modified
683680
// directly (e.g., attributes added or removed) and the internal cache
@@ -740,13 +737,7 @@ fn prepend_attrs(sess: &ParseSess,
740737
let source = pprust::attr_to_string(attr);
741738
let macro_filename = FileName::macro_expansion_source_code(&source);
742739
if attr.is_sugared_doc {
743-
let (stream, mut errors) = parse_stream_from_source_str(
744-
macro_filename,
745-
source,
746-
sess,
747-
Some(span),
748-
);
749-
emit_unclosed_delims(&mut errors, &sess.span_diagnostic);
740+
let stream = parse_stream_from_source_str(macro_filename, source, sess, Some(span));
750741
builder.push(stream);
751742
continue
752743
}
@@ -763,13 +754,7 @@ fn prepend_attrs(sess: &ParseSess,
763754
// ... and for more complicated paths, fall back to a reparse hack that
764755
// should eventually be removed.
765756
} else {
766-
let (stream, mut errors) = parse_stream_from_source_str(
767-
macro_filename,
768-
source,
769-
sess,
770-
Some(span),
771-
);
772-
emit_unclosed_delims(&mut errors, &sess.span_diagnostic);
757+
let stream = parse_stream_from_source_str(macro_filename, source, sess, Some(span));
773758
brackets.push(stream);
774759
}
775760

src/libsyntax_ext/proc_macro_server.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use syntax::ast;
1212
use syntax::ext::base::ExtCtxt;
1313
use syntax::parse::lexer::comments;
1414
use syntax::parse::{self, token, ParseSess};
15-
use syntax::parse::parser::emit_unclosed_delims;
1615
use syntax::tokenstream::{self, DelimSpan, IsJoint::*, TokenStream, TreeAndJoint};
1716
use syntax_pos::hygiene::{SyntaxContext, Transparency};
1817
use syntax_pos::symbol::{keywords, Symbol};
@@ -410,14 +409,12 @@ impl server::TokenStream for Rustc<'_> {
410409
stream.is_empty()
411410
}
412411
fn from_str(&mut self, src: &str) -> Self::TokenStream {
413-
let (tokens, mut errors) = parse::parse_stream_from_source_str(
412+
parse::parse_stream_from_source_str(
414413
FileName::proc_macro_source_code(src.clone()),
415414
src.to_string(),
416415
self.sess,
417416
Some(self.call_site),
418-
);
419-
emit_unclosed_delims(&mut errors, &self.sess.span_diagnostic);
420-
tokens
417+
)
421418
}
422419
fn to_string(&mut self, stream: &Self::TokenStream) -> String {
423420
stream.to_string()

0 commit comments

Comments
 (0)