diff options
| author | bors <bors@rust-lang.org> | 2018-09-11 01:08:49 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-09-11 01:08:49 +0000 |
| commit | d6720cc810ea3dc9e051a95ff1a8dc9755c3bdb5 (patch) | |
| tree | 42b9b4fb713c50e0f2bdea8efae3298d67d2fc2d /src/libsyntax | |
| parent | 551244f05b92f90fe327f8f0a6d9a6e674eaab1b (diff) | |
| parent | 014a56ca9c0ad4b0ab1e377a66236242b4329413 (diff) | |
| download | rust-d6720cc810ea3dc9e051a95ff1a8dc9755c3bdb5.tar.gz rust-d6720cc810ea3dc9e051a95ff1a8dc9755c3bdb5.zip | |
Auto merge of #54092 - estebank:gotta-go-fast, r=nikomatsakis
Don't compute padding of braces unless they are unmatched Follow up to #53949. Attempt to fix # #54083. r? @nikomatsakis
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/parse/lexer/mod.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/parse/lexer/tokentrees.rs | 43 |
2 files changed, 23 insertions, 26 deletions
diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index b7e8a880e7e..aa47d5bf669 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -66,10 +66,10 @@ pub struct StringReader<'a> { /// The raw source span which *does not* take `override_span` into account span_src_raw: Span, open_braces: Vec<(token::DelimToken, Span)>, - /// The type and spans for all braces that have different indentation. + /// The type and spans for all braces /// /// Used only for error recovery when arriving to EOF with mismatched braces. - suspicious_open_spans: Vec<(token::DelimToken, Span, Span)>, + matching_delim_spans: Vec<(token::DelimToken, Span, Span)>, crate override_span: Option<Span>, last_unclosed_found_span: Option<Span>, } @@ -220,7 +220,7 @@ impl<'a> StringReader<'a> { span: syntax_pos::DUMMY_SP, span_src_raw: syntax_pos::DUMMY_SP, open_braces: Vec::new(), - suspicious_open_spans: Vec::new(), + matching_delim_spans: Vec::new(), override_span, last_unclosed_found_span: None, } diff --git a/src/libsyntax/parse/lexer/tokentrees.rs b/src/libsyntax/parse/lexer/tokentrees.rs index 9e08fa232f1..8047ab01465 100644 --- a/src/libsyntax/parse/lexer/tokentrees.rs +++ b/src/libsyntax/parse/lexer/tokentrees.rs @@ -44,6 +44,7 @@ impl<'a> StringReader<'a> { } fn parse_token_tree(&mut self) -> PResult<'a, TokenStream> { + let sm = self.sess.source_map(); match self.token { token::Eof => { let msg = "this file contains an un-closed delimiter"; @@ -53,20 +54,25 @@ impl<'a> StringReader<'a> { } if let Some((delim, _)) = self.open_braces.last() { - if let Some((d, open_sp, close_sp)) = self.suspicious_open_spans.iter() - .filter(|(d, _, _)| delim == d) - .next() // these are in reverse order as they get inserted on close, but - { // we want the last open/first close - if d == delim { - err.span_label( - *open_sp, - "this delimiter might not be properly closed...", - ); - err.span_label( - *close_sp, - "...as it matches this but it has different indentation", - ); + if let Some((_, open_sp, close_sp)) = self.matching_delim_spans.iter() + .filter(|(d, open_sp, close_sp)| { + + if let Some(close_padding) = sm.span_to_margin(*close_sp) { + if let Some(open_padding) = sm.span_to_margin(*open_sp) { + return delim == d && close_padding != open_padding; + } } + false + }).next() // these are in reverse order as they get inserted on close, but + { // we want the last open/first close + err.span_label( + *open_sp, + "this delimiter might not be properly closed...", + ); + err.span_label( + *close_sp, + "...as it matches this but it has different indentation", + ); } } Err(err) @@ -87,20 +93,11 @@ impl<'a> StringReader<'a> { // Expand to cover the entire delimited token tree let delim_span = DelimSpan::from_pair(pre_span, self.span); - let sm = self.sess.source_map(); match self.token { // Correct delimiter. token::CloseDelim(d) if d == delim => { let (open_brace, open_brace_span) = self.open_braces.pop().unwrap(); - if let Some(current_padding) = sm.span_to_margin(self.span) { - if let Some(padding) = sm.span_to_margin(open_brace_span) { - if current_padding != padding { - self.suspicious_open_spans.push( - (open_brace, open_brace_span, self.span), - ); - } - } - } + self.matching_delim_spans.push((open_brace, open_brace_span, self.span)); // Parse the close delimiter. self.real_token(); } |
