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