@@ -2703,8 +2703,8 @@ impl<'a> Parser<'a> {
2703
2703
token:: Literal ( token:: Float ( n) , _suf) => {
2704
2704
self . bump ( ) ;
2705
2705
let fstr = n. as_str ( ) ;
2706
- let mut err = self . diagnostic ( ) . struct_span_err ( self . prev_span ,
2707
- & format ! ( "unexpected token: `{}`" , n) ) ;
2706
+ let mut err = self . diagnostic ( )
2707
+ . struct_span_err ( self . prev_span , & format ! ( "unexpected token: `{}`" , n) ) ;
2708
2708
err. span_label ( self . prev_span , "unexpected token" ) ;
2709
2709
if fstr. chars ( ) . all ( |x| "0123456789." . contains ( x) ) {
2710
2710
let float = match fstr. parse :: < f64 > ( ) . ok ( ) {
@@ -2864,8 +2864,8 @@ impl<'a> Parser<'a> {
2864
2864
let e = self . parse_prefix_expr ( None ) ;
2865
2865
let ( span, e) = self . interpolated_or_expr_span ( e) ?;
2866
2866
let span_of_tilde = lo;
2867
- let mut err = self . diagnostic ( ) . struct_span_err ( span_of_tilde ,
2868
- "`~` cannot be used as a unary operator" ) ;
2867
+ let mut err = self . diagnostic ( )
2868
+ . struct_span_err ( span_of_tilde , "`~` cannot be used as a unary operator" ) ;
2869
2869
err. span_suggestion_short_with_applicability (
2870
2870
span_of_tilde,
2871
2871
"use `!` to perform bitwise negation" ,
@@ -3423,6 +3423,24 @@ impl<'a> Parser<'a> {
3423
3423
) ;
3424
3424
err. emit ( ) ;
3425
3425
}
3426
+ let in_span = self . prev_span ;
3427
+ if self . eat_keyword ( keywords:: In ) {
3428
+ // a common typo: `for _ in in bar {}`
3429
+ let mut err = self . sess . span_diagnostic . struct_span_err (
3430
+ self . prev_span ,
3431
+ "expected iterable, found keyword `in`" ,
3432
+ ) ;
3433
+ err. span_suggestion_short_with_applicability (
3434
+ in_span. until ( self . prev_span ) ,
3435
+ "remove the duplicated `in`" ,
3436
+ String :: new ( ) ,
3437
+ Applicability :: MachineApplicable ,
3438
+ ) ;
3439
+ err. note ( "if you meant to use emplacement syntax, it is obsolete (for now, anyway)" ) ;
3440
+ err. note ( "for more information on the status of emplacement syntax, see <\
3441
+ https://github.com/rust-lang/rust/issues/27779#issuecomment-378416911>") ;
3442
+ err. emit ( ) ;
3443
+ }
3426
3444
let expr = self . parse_expr_res ( Restrictions :: NO_STRUCT_LITERAL , None ) ?;
3427
3445
let ( iattrs, loop_block) = self . parse_inner_attrs_and_block ( ) ?;
3428
3446
attrs. extend ( iattrs) ;
@@ -4766,12 +4784,9 @@ impl<'a> Parser<'a> {
4766
4784
if !self . eat ( & token:: OpenDelim ( token:: Brace ) ) {
4767
4785
let sp = self . span ;
4768
4786
let tok = self . this_token_to_string ( ) ;
4769
- let mut do_not_suggest_help = false ;
4770
4787
let mut e = self . span_fatal ( sp, & format ! ( "expected `{{`, found `{}`" , tok) ) ;
4771
- if self . token . is_keyword ( keywords:: In ) || self . token == token:: Colon {
4772
- do_not_suggest_help = true ;
4773
- e. span_label ( sp, "expected `{`" ) ;
4774
- }
4788
+ let do_not_suggest_help =
4789
+ self . token . is_keyword ( keywords:: In ) || self . token == token:: Colon ;
4775
4790
4776
4791
if self . token . is_ident_named ( "and" ) {
4777
4792
e. span_suggestion_short_with_applicability (
@@ -4802,6 +4817,7 @@ impl<'a> Parser<'a> {
4802
4817
|| do_not_suggest_help {
4803
4818
// if the next token is an open brace (e.g., `if a b {`), the place-
4804
4819
// inside-a-block suggestion would be more likely wrong than right
4820
+ e. span_label ( sp, "expected `{`" ) ;
4805
4821
return Err ( e) ;
4806
4822
}
4807
4823
let mut stmt_span = stmt. span ;
0 commit comments