diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index 5780b9bcfd41..49722e5ad71f 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -14,6 +14,7 @@ use std::convert::TryInto; use std::hash::{Hash, Hasher}; use syntax::ast::{FloatTy, LitKind}; use syntax::ptr::P; +use syntax_pos::symbol::Symbol; /// A `LitKind`-like enum to fold constant `Expr`s into. #[derive(Debug, Clone)] @@ -38,6 +39,8 @@ pub enum Constant { Repeat(Box, u64), /// a tuple of constants Tuple(Vec), + /// a literal with syntax error + Err(Symbol), } impl PartialEq for Constant { @@ -103,6 +106,9 @@ impl Hash for Constant { c.hash(state); l.hash(state); }, + Constant::Err(ref s) => { + s.hash(state); + }, } } } @@ -155,6 +161,7 @@ pub fn lit_to_constant<'tcx>(lit: &LitKind, ty: Ty<'tcx>) -> Constant { _ => bug!(), }, LitKind::Bool(b) => Constant::Bool(b), + LitKind::Err(s) => Constant::Err(s), } } diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 36eac00b54bd..9623c6cbdadd 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -260,6 +260,7 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor { match lit.node { LitKind::Bool(val) => println!(" if let LitKind::Bool({:?}) = {}.node;", val, lit_pat), LitKind::Char(c) => println!(" if let LitKind::Char({:?}) = {}.node;", c, lit_pat), + LitKind::Err(val) => println!(" if let LitKind::Err({}) = {}.node;", val, lit_pat), LitKind::Byte(b) => println!(" if let LitKind::Byte({}) = {}.node;", b, lit_pat), // FIXME: also check int type LitKind::Int(i, _) => println!(" if let LitKind::Int({}, _) = {}.node;", i, lit_pat),