]> git.lizzy.rs Git - rust.git/blobdiff - src/libsyntax/util/parser.rs
Account for `ty::Error` when suggesting `impl Trait` or `Box<dyn Trait>`
[rust.git] / src / libsyntax / util / parser.rs
index df72fdc801423a2f2bb1012afcaac4062cc5b572..a0ed89a9caef17f04e0181bca05b176774b0e65e 100644 (file)
@@ -1,6 +1,6 @@
-use crate::token::{self, Token, BinOpToken};
-use crate::symbol::kw;
 use crate::ast::{self, BinOpKind};
+use crate::token::{self, BinOpToken, Token};
+use rustc_span::symbol::kw;
 
 /// Associative operator with precedence.
 ///
@@ -64,7 +64,7 @@ pub enum Fixity {
     /// The operator is right-associative
     Right,
     /// The operator is not associative
-    None
+    None,
 }
 
 impl AssocOp {
@@ -100,7 +100,7 @@ pub fn from_token(t: &Token) -> Option<AssocOp> {
             // `<-` should probably be `< -`
             token::LArrow => Some(Less),
             _ if t.is_keyword(kw::As) => Some(As),
-            _ => None
+            _ => None,
         }
     }
 
@@ -125,7 +125,7 @@ pub fn from_ast_binop(op: BinOpKind) -> Self {
             BinOpKind::BitXor => BitXor,
             BinOpKind::BitOr => BitOr,
             BinOpKind::And => LAnd,
-            BinOpKind::Or => LOr
+            BinOpKind::Or => LOr,
         }
     }
 
@@ -154,10 +154,10 @@ pub fn fixity(&self) -> Fixity {
         // NOTE: it is a bug to have an operators that has same precedence but different fixities!
         match *self {
             Assign | AssignOp(_) => Fixity::Right,
-            As | Multiply | Divide | Modulus | Add | Subtract | ShiftLeft | ShiftRight | BitAnd |
-            BitXor | BitOr | Less | Greater | LessEqual | GreaterEqual | Equal | NotEqual |
-            LAnd | LOr | Colon => Fixity::Left,
-            DotDot | DotDotEq => Fixity::None
+            As | Multiply | Divide | Modulus | Add | Subtract | ShiftLeft | ShiftRight | BitAnd
+            | BitXor | BitOr | Less | Greater | LessEqual | GreaterEqual | Equal | NotEqual
+            LAnd | LOr | Colon => Fixity::Left,
+            DotDot | DotDotEq => Fixity::None,
         }
     }
 
@@ -165,9 +165,9 @@ pub fn is_comparison(&self) -> bool {
         use AssocOp::*;
         match *self {
             Less | Greater | LessEqual | GreaterEqual | Equal | NotEqual => true,
-            Assign | AssignOp(_) | As | Multiply | Divide | Modulus | Add |
-            Subtract | ShiftLeft | ShiftRight | BitAnd | BitXor | BitOr | LAnd | LOr |
-            DotDot | DotDotEq | Colon => false
+            Assign | AssignOp(_) | As | Multiply | Divide | Modulus | Add | Subtract
+            | ShiftLeft | ShiftRight | BitAnd | BitXor | BitOr | LAnd | LOr | DotDot | DotDotEq
+            | Colon => false,
         }
     }
 
@@ -175,9 +175,9 @@ pub fn is_assign_like(&self) -> bool {
         use AssocOp::*;
         match *self {
             Assign | AssignOp(_) => true,
-            Less | Greater | LessEqual | GreaterEqual | Equal | NotEqual | As | Multiply | Divide |
-            Modulus | Add | Subtract | ShiftLeft | ShiftRight | BitAnd | BitXor | BitOr | LAnd |
-            LOr | DotDot | DotDotEq | Colon => false
+            Less | Greater | LessEqual | GreaterEqual | Equal | NotEqual | As | Multiply
+            | Divide | Modulus | Add | Subtract | ShiftLeft | ShiftRight | BitAnd | BitXor
+            | BitOr | LAnd | LOr | DotDot | DotDotEq | Colon => false,
         }
     }
 
@@ -202,7 +202,7 @@ pub fn to_ast_binop(&self) -> Option<BinOpKind> {
             BitOr => Some(BinOpKind::BitOr),
             LAnd => Some(BinOpKind::And),
             LOr => Some(BinOpKind::Or),
-            Assign | AssignOp(_) | As | DotDot | DotDotEq | Colon => None
+            Assign | AssignOp(_) | As | DotDot | DotDotEq | Colon => None,
         }
     }
 
@@ -378,18 +378,18 @@ pub fn contains_exterior_struct_lit(value: &ast::Expr) -> bool {
     match value.kind {
         ast::ExprKind::Struct(..) => true,
 
-        ast::ExprKind::Assign(ref lhs, ref rhs) |
-        ast::ExprKind::AssignOp(_, ref lhs, ref rhs) |
-        ast::ExprKind::Binary(_, ref lhs, ref rhs) => {
+        ast::ExprKind::Assign(ref lhs, ref rhs, _)
+        | ast::ExprKind::AssignOp(_, ref lhs, ref rhs)
+        ast::ExprKind::Binary(_, ref lhs, ref rhs) => {
             // X { y: 1 } + X { y: 2 }
             contains_exterior_struct_lit(&lhs) || contains_exterior_struct_lit(&rhs)
         }
-        ast::ExprKind::Await(ref x) |
-        ast::ExprKind::Unary(_, ref x) |
-        ast::ExprKind::Cast(ref x, _) |
-        ast::ExprKind::Type(ref x, _) |
-        ast::ExprKind::Field(ref x, _) |
-        ast::ExprKind::Index(ref x, _) => {
+        ast::ExprKind::Await(ref x)
+        | ast::ExprKind::Unary(_, ref x)
+        | ast::ExprKind::Cast(ref x, _)
+        | ast::ExprKind::Type(ref x, _)
+        | ast::ExprKind::Field(ref x, _)
+        ast::ExprKind::Index(ref x, _) => {
             // &X { y: 1 }, X { y: 1 }.y
             contains_exterior_struct_lit(&x)
         }