Skip to content

Commit

Permalink
no need to return unmatched_delims from tokentrees
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Feb 28, 2023
1 parent 9ce7472 commit 88de2e1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
1 change: 0 additions & 1 deletion compiler/rustc_expand/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ pub(crate) fn string_to_stream(source_str: String) -> TokenStream {
ps.source_map().new_source_file(PathBuf::from("bogofile").into(), source_str),
None,
)
.0
}

/// Parses a string, returns a crate.
Expand Down
16 changes: 6 additions & 10 deletions compiler/rustc_parse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub const MACRO_ARGUMENTS: Option<&str> = Some("macro arguments");

#[macro_use]
pub mod parser;
use parser::{emit_unclosed_delims, make_unclosed_delims_error, Parser};
use parser::{make_unclosed_delims_error, Parser};
pub mod lexer;
pub mod validate_attr;

Expand Down Expand Up @@ -96,10 +96,7 @@ pub fn parse_stream_from_source_str(
sess: &ParseSess,
override_span: Option<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);
stream
source_file_to_stream(sess, sess.source_map().new_source_file(name, source), override_span)
}

/// Creates a new parser from a source string.
Expand Down Expand Up @@ -135,9 +132,8 @@ fn maybe_source_file_to_parser(
source_file: Lrc<SourceFile>,
) -> Result<Parser<'_>, Vec<Diagnostic>> {
let end_pos = source_file.end_pos;
let (stream, unclosed_delims) = maybe_file_to_stream(sess, source_file, None)?;
let stream = maybe_file_to_stream(sess, source_file, None)?;
let mut parser = stream_to_parser(sess, stream, None);
parser.unclosed_delims = unclosed_delims;
if parser.token == token::Eof {
parser.token.span = Span::new(end_pos, end_pos, parser.token.span.ctxt(), None);
}
Expand Down Expand Up @@ -182,7 +178,7 @@ pub fn source_file_to_stream(
sess: &ParseSess,
source_file: Lrc<SourceFile>,
override_span: Option<Span>,
) -> (TokenStream, Vec<lexer::UnmatchedDelim>) {
) -> TokenStream {
panictry_buffer!(&sess.span_diagnostic, maybe_file_to_stream(sess, source_file, override_span))
}

Expand All @@ -192,7 +188,7 @@ pub fn maybe_file_to_stream(
sess: &ParseSess,
source_file: Lrc<SourceFile>,
override_span: Option<Span>,
) -> Result<(TokenStream, Vec<lexer::UnmatchedDelim>), Vec<Diagnostic>> {
) -> Result<TokenStream, Vec<Diagnostic>> {
let src = source_file.src.as_ref().unwrap_or_else(|| {
sess.span_diagnostic.bug(&format!(
"cannot lex `source_file` without source: {}",
Expand All @@ -204,7 +200,7 @@ pub fn maybe_file_to_stream(
lexer::parse_token_trees(sess, src.as_str(), source_file.start_pos, override_span);

match token_trees {
Ok(stream) if unmatched_delims.is_empty() => Ok((stream, unmatched_delims)),
Ok(stream) if unmatched_delims.is_empty() => Ok(stream),
_ => {
// Return error if there are unmatched delimiters or unclosng delimiters.
// We emit delimiter mismatch errors first, then emit the unclosing delimiter mismatch
Expand Down

0 comments on commit 88de2e1

Please sign in to comment.