@@ -300,6 +300,26 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
300
300
let prefix_span = self . mk_sp ( start, ident_start) ;
301
301
302
302
if prefix_span. at_least_rust_2021 ( ) {
303
+ // If the raw lifetime is followed by \' then treat it a normal
304
+ // lifetime followed by a \', which is to interpret it as a character
305
+ // literal. In this case, it's always an invalid character literal
306
+ // since the literal must necessarily have >3 characters (r#...) inside
307
+ // of it, which is invalid.
308
+ if self . cursor . as_str ( ) . starts_with ( '\'' ) {
309
+ let lit_span = self . mk_sp ( start, self . pos + BytePos ( 1 ) ) ;
310
+ let contents = self . str_from_to ( start + BytePos ( 1 ) , self . pos ) ;
311
+ emit_unescape_error (
312
+ self . dcx ( ) ,
313
+ contents,
314
+ lit_span,
315
+ lit_span,
316
+ Mode :: Char ,
317
+ 0 ..contents. len ( ) ,
318
+ EscapeError :: MoreThanOneChar ,
319
+ )
320
+ . expect ( "expected error" ) ;
321
+ }
322
+
303
323
let span = self . mk_sp ( start, self . pos ) ;
304
324
305
325
let lifetime_name_without_tick =
@@ -371,8 +391,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
371
391
rustc_lexer:: TokenKind :: Caret => token:: BinOp ( token:: Caret ) ,
372
392
rustc_lexer:: TokenKind :: Percent => token:: BinOp ( token:: Percent ) ,
373
393
374
- rustc_lexer:: TokenKind :: Unknown
375
- | rustc_lexer:: TokenKind :: InvalidIdent => {
394
+ rustc_lexer:: TokenKind :: Unknown | rustc_lexer:: TokenKind :: InvalidIdent => {
376
395
// Don't emit diagnostics for sequences of the same invalid token
377
396
if swallow_next_invalid > 0 {
378
397
swallow_next_invalid -= 1 ;
0 commit comments