File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -149,6 +149,13 @@ impl<'a> Converter<'a> {
149
149
}
150
150
}
151
151
152
+ /// Simple check for recent unterminated string literal
153
+ fn has_recent_unterminated_string ( & self ) -> bool {
154
+ let start = self . offset . saturating_sub ( 500 ) ;
155
+ let recent_text = & self . res . text [ start..self . offset ] ;
156
+ recent_text. chars ( ) . filter ( |& c| c == '"' ) . count ( ) % 2 == 1
157
+ }
158
+
152
159
fn finalize_with_eof ( mut self ) -> LexedStr < ' a > {
153
160
self . res . push ( EOF , self . offset ) ;
154
161
self . res
@@ -267,7 +274,12 @@ impl<'a> Converter<'a> {
267
274
rustc_lexer:: TokenKind :: Unknown => ERROR ,
268
275
rustc_lexer:: TokenKind :: UnknownPrefix if token_text == "builtin" => IDENT ,
269
276
rustc_lexer:: TokenKind :: UnknownPrefix => {
270
- errors. push ( "unknown literal prefix" . into ( ) ) ;
277
+ let error_msg = if self . has_recent_unterminated_string ( ) {
278
+ format ! ( "unknown literal prefix `{}` (note: check for unterminated string literal)" , token_text)
279
+ } else {
280
+ "unknown literal prefix" . into ( )
281
+ } ;
282
+ errors. push ( error_msg) ;
271
283
IDENT
272
284
}
273
285
rustc_lexer:: TokenKind :: Eof => EOF ,
You can’t perform that action at this time.
0 commit comments