diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index 8f18102101d3..fff029155891 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -14,7 +14,7 @@ use std::cmp::PartialOrd; use std::convert::TryInto; use std::hash::{Hash, Hasher}; use syntax::ast::{FloatTy, LitKind}; -use syntax_pos::symbol::{LocalInternedString, Symbol}; +use syntax_pos::symbol::Symbol; /// A `LitKind`-like enum to fold constant `Expr`s into. #[derive(Debug, Clone)] @@ -250,14 +250,18 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> { if let ExprKind::Path(qpath) = &callee.node; let res = self.tables.qpath_res(qpath, callee.hir_id); if let Some(def_id) = res.opt_def_id(); - let get_def_path = self.lcx.get_def_path(def_id); + let get_def_path = self.lcx.get_def_path(def_id, ); let def_path = get_def_path .iter() - .map(LocalInternedString::get) + .copied() + .map(Symbol::as_str) .collect::>(); - if let &["core", "num", impl_ty, "max_value"] = &def_path[..]; + if def_path[0] == "core"; + if def_path[1] == "num"; + if def_path[3] == "max_value"; + if def_path.len() == 4; then { - let value = match impl_ty { + let value = match &*def_path[2] { "" => i8::max_value() as u128, "" => i16::max_value() as u128, "" => i32::max_value() as u128, diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 7bce42369dc8..7b41bea4ff4b 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -18,6 +18,7 @@ use rustc_typeck::hir_ty_to_ty; use syntax::ast::{FloatTy, IntTy, UintTy}; use syntax::errors::DiagnosticBuilder; use syntax::source_map::Span; +use syntax::symbol::sym; use crate::consts::{constant, Constant}; use crate::utils::paths; @@ -1091,7 +1092,7 @@ fn is_c_void(cx: &LateContext<'_, '_>, ty: Ty<'_>) -> bool { if names.is_empty() { return false; } - if names[0] == "libc" || names[0] == "core" && *names.last().unwrap() == "c_void" { + if names[0] == sym!(libc) || names[0] == sym::core && *names.last().unwrap() == sym!(c_void) { return true; } } diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 179e006ed058..a812b1709bbc 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -1123,5 +1123,7 @@ mod test { } pub fn match_def_path<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, did: DefId, syms: &[&str]) -> bool { + // HACK: find a way to use symbols from clippy or just go fully to diagnostic items + let syms: Vec<_> = syms.iter().map(|sym| Symbol::intern(sym)).collect(); cx.match_def_path(did, &syms) }