@@ -2,7 +2,9 @@ use super::ty::AllowPlus;
2
2
use super :: { BlockMode , Parser , PathStyle , SemiColonMode , SeqSep , TokenExpectType , TokenType } ;
3
3
4
4
use rustc_ast:: ast:: { self , BinOpKind , BindingMode , BlockCheckMode , Expr , ExprKind , Item , Param } ;
5
- use rustc_ast:: ast:: { AttrVec , ItemKind , Mutability , Pat , PatKind , PathSegment , QSelf , Ty , TyKind } ;
5
+ use rustc_ast:: ast:: {
6
+ AngleBracketedArgs , AttrVec , ItemKind , Mutability , Pat , PatKind , PathSegment , QSelf , Ty , TyKind ,
7
+ } ;
6
8
use rustc_ast:: ptr:: P ;
7
9
use rustc_ast:: token:: { self , Lit , LitKind , TokenKind } ;
8
10
use rustc_ast:: util:: parser:: AssocOp ;
@@ -488,6 +490,44 @@ impl<'a> Parser<'a> {
488
490
false
489
491
}
490
492
493
+ /// Check if a method call with an intended turbofish has been written without surrounding
494
+ /// angle brackets.
495
+ pub ( super ) fn check_turbofish_missing_angle_brackets ( & mut self , segment : & mut PathSegment ) {
496
+ if token:: ModSep == self . token . kind && segment. args . is_none ( ) {
497
+ let snapshot = self . clone ( ) ;
498
+ self . bump ( ) ;
499
+ let lo = self . token . span ;
500
+ match self . parse_angle_args ( ) {
501
+ Ok ( args) if self . token . kind == token:: OpenDelim ( token:: Paren ) => {
502
+ // Recover from bad turbofish: `foo.collect::Vec<_>()`.
503
+ let span = lo. to ( self . prev_token . span ) ;
504
+ let args = AngleBracketedArgs { args, span } . into ( ) ;
505
+ segment. args = args;
506
+ self . struct_span_err (
507
+ span,
508
+ "generic parameters without surrounding angle brackets" ,
509
+ )
510
+ . multipart_suggestion (
511
+ "surround the type parameters with angle brackets" ,
512
+ vec ! [
513
+ ( span. shrink_to_lo( ) , "<" . to_string( ) ) ,
514
+ ( span. shrink_to_hi( ) , ">" . to_string( ) ) ,
515
+ ] ,
516
+ Applicability :: MachineApplicable ,
517
+ )
518
+ . emit ( ) ;
519
+ }
520
+ Ok ( _) => {
521
+ * self = snapshot;
522
+ }
523
+ Err ( mut err) => {
524
+ err. cancel ( ) ;
525
+ * self = snapshot;
526
+ }
527
+ }
528
+ }
529
+ }
530
+
491
531
/// Check to see if a pair of chained operators looks like an attempt at chained comparison,
492
532
/// e.g. `1 < x <= 3`. If so, suggest either splitting the comparison into two, or
493
533
/// parenthesising the leftmost comparison.
0 commit comments