@@ -44,6 +44,7 @@ impl<'a> StringReader<'a> {
44
44
}
45
45
46
46
fn parse_token_tree ( & mut self ) -> PResult < ' a , TokenStream > {
47
+ let sm = self . sess . source_map ( ) ;
47
48
match self . token {
48
49
token:: Eof => {
49
50
let msg = "this file contains an un-closed delimiter" ;
@@ -53,20 +54,25 @@ impl<'a> StringReader<'a> {
53
54
}
54
55
55
56
if let Some ( ( delim, _) ) = self . open_braces . last ( ) {
56
- if let Some ( ( d, open_sp, close_sp) ) = self . suspicious_open_spans . iter ( )
57
- . filter ( |( d, _, _) | delim == d)
58
- . next ( ) // these are in reverse order as they get inserted on close, but
59
- { // we want the last open/first close
60
- if d == delim {
61
- err. span_label (
62
- * open_sp,
63
- "this delimiter might not be properly closed..." ,
64
- ) ;
65
- err. span_label (
66
- * close_sp,
67
- "...as it matches this but it has different indentation" ,
68
- ) ;
57
+ if let Some ( ( _, open_sp, close_sp) ) = self . matching_delim_spans . iter ( )
58
+ . filter ( |( d, open_sp, close_sp) | {
59
+
60
+ if let Some ( close_padding) = sm. span_to_margin ( * close_sp) {
61
+ if let Some ( open_padding) = sm. span_to_margin ( * open_sp) {
62
+ return delim == d && close_padding != open_padding;
63
+ }
69
64
}
65
+ false
66
+ } ) . next ( ) // these are in reverse order as they get inserted on close, but
67
+ { // we want the last open/first close
68
+ err. span_label (
69
+ * open_sp,
70
+ "this delimiter might not be properly closed..." ,
71
+ ) ;
72
+ err. span_label (
73
+ * close_sp,
74
+ "...as it matches this but it has different indentation" ,
75
+ ) ;
70
76
}
71
77
}
72
78
Err ( err)
@@ -87,20 +93,11 @@ impl<'a> StringReader<'a> {
87
93
// Expand to cover the entire delimited token tree
88
94
let delim_span = DelimSpan :: from_pair ( pre_span, self . span ) ;
89
95
90
- let sm = self . sess . source_map ( ) ;
91
96
match self . token {
92
97
// Correct delimiter.
93
98
token:: CloseDelim ( d) if d == delim => {
94
99
let ( open_brace, open_brace_span) = self . open_braces . pop ( ) . unwrap ( ) ;
95
- if let Some ( current_padding) = sm. span_to_margin ( self . span ) {
96
- if let Some ( padding) = sm. span_to_margin ( open_brace_span) {
97
- if current_padding != padding {
98
- self . suspicious_open_spans . push (
99
- ( open_brace, open_brace_span, self . span ) ,
100
- ) ;
101
- }
102
- }
103
- }
100
+ self . matching_delim_spans . push ( ( open_brace, open_brace_span, self . span ) ) ;
104
101
// Parse the close delimiter.
105
102
self . real_token ( ) ;
106
103
}
0 commit comments