File tree Expand file tree Collapse file tree 3 files changed +9
-7
lines changed Expand file tree Collapse file tree 3 files changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -172,6 +172,7 @@ fn maybe_source_file_to_parser(
172
172
parser. unclosed_delims = unclosed_delims;
173
173
if parser. token == token:: Eof && parser. token . span . is_dummy ( ) {
174
174
parser. token . span = Span :: new ( end_pos, end_pos, parser. token . span . ctxt ( ) ) ;
175
+ assert ! ( parser. unnormalized_token. is_none( ) ) ;
175
176
}
176
177
177
178
Ok ( parser)
Original file line number Diff line number Diff line change @@ -1400,8 +1400,9 @@ impl<'a> Parser<'a> {
1400
1400
}
1401
1401
1402
1402
fn report_invalid_macro_expansion_item ( & self , args : & MacArgs ) {
1403
+ let span = args. span ( ) . expect ( "undelimited macro call" ) ;
1403
1404
let mut err = self . struct_span_err (
1404
- self . prev_span ,
1405
+ span ,
1405
1406
"macros that expand to items must be delimited with braces or followed by a semicolon" ,
1406
1407
) ;
1407
1408
if self . unclosed_delims . is_empty ( ) {
@@ -1416,14 +1417,14 @@ impl<'a> Parser<'a> {
1416
1417
) ;
1417
1418
} else {
1418
1419
err. span_suggestion (
1419
- self . prev_span ,
1420
+ span ,
1420
1421
"change the delimiters to curly braces" ,
1421
1422
" { /* items */ }" . to_string ( ) ,
1422
1423
Applicability :: HasPlaceholders ,
1423
1424
) ;
1424
1425
}
1425
1426
err. span_suggestion (
1426
- self . prev_span . shrink_to_hi ( ) ,
1427
+ span . shrink_to_hi ( ) ,
1427
1428
"add a semicolon" ,
1428
1429
';' . to_string ( ) ,
1429
1430
Applicability :: MaybeIncorrect ,
Original file line number Diff line number Diff line change @@ -95,7 +95,7 @@ pub struct Parser<'a> {
95
95
/// The current non-normalized token if it's different from `token`.
96
96
/// Preferable use is through the `unnormalized_token()` getter.
97
97
/// Use span from this token if you need to concatenate it with some neighbouring spans.
98
- unnormalized_token : Option < Token > ,
98
+ pub unnormalized_token : Option < Token > ,
99
99
/// The previous normalized token.
100
100
/// Use span from this token if you need an isolated span.
101
101
prev_token : Token ,
@@ -1096,15 +1096,15 @@ impl<'a> Parser<'a> {
1096
1096
& mut self . token_cursor . frame ,
1097
1097
self . token_cursor . stack . pop ( ) . unwrap ( ) ,
1098
1098
) ;
1099
- self . token . span = frame. span . entire ( ) ;
1099
+ self . token = Token :: new ( TokenKind :: CloseDelim ( frame. delim ) , frame. span . close ) ;
1100
+ self . unnormalized_token = None ;
1100
1101
self . bump ( ) ;
1101
1102
TokenTree :: Delimited ( frame. span , frame. delim , frame. tree_cursor . stream . into ( ) )
1102
1103
}
1103
1104
token:: CloseDelim ( _) | token:: Eof => unreachable ! ( ) ,
1104
1105
_ => {
1105
- let token = self . token . clone ( ) ;
1106
1106
self . bump ( ) ;
1107
- TokenTree :: Token ( token )
1107
+ TokenTree :: Token ( self . prev_token . clone ( ) )
1108
1108
}
1109
1109
}
1110
1110
}
You can’t perform that action at this time.
0 commit comments