From 792153104c5af9948df6d8def8ab4b2611731eb6 Mon Sep 17 00:00:00 2001 From: xd009642 Date: Wed, 24 Jul 2019 22:27:12 +0100 Subject: [PATCH] Fix some of the compile errors --- clippy_lints/src/trait_bounds.rs | 22 ++++++-------------- clippy_lints/src/utils/hir_utils.rs | 32 ++++++++++++++--------------- 2 files changed, 22 insertions(+), 32 deletions(-) diff --git a/clippy_lints/src/trait_bounds.rs b/clippy_lints/src/trait_bounds.rs index 1f4c6850760..e41437bf1f8 100644 --- a/clippy_lints/src/trait_bounds.rs +++ b/clippy_lints/src/trait_bounds.rs @@ -1,29 +1,19 @@ use crate::utils::{in_macro, span_help_and_lint, SpanlessHash}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_tool_lint, lint_array, impl_lint_pass}; use rustc_data_structures::fx::FxHashMap; use rustc::hir::*; +#[derive(Copy, Clone)] +pub struct TraitBounds; + declare_clippy_lint! { pub TYPE_REPETITION_IN_BOUNDS, complexity, "Types are repeated unnecessary in trait bounds use `+` instead of using `T: _, T: _`" } -#[derive(Copy, Clone)] -pub struct TraitBounds; - -impl LintPass for TraitBounds { - fn get_lints(&self) -> LintArray { - lint_array!(TYPE_REPETITION_IN_BOUNDS) - } - - fn name(&self) -> &'static str { - "TypeRepetitionInBounds" - } -} - - +impl_lint_pass!(TraitBounds => [TYPE_REPETITION_IN_BOUNDS]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TraitBounds { fn check_generics(&mut self, cx: &LateContext<'a, 'tcx>, gen: &'tcx Generics) { @@ -38,7 +28,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TraitBounds { let mut map = FxHashMap::default(); for bound in &gen.where_clause.predicates { if let WherePredicate::BoundPredicate(ref p) = bound { - let h = hash(&p.bounded_ty); + let h = hash(&p.bounded_ty.node); if let Some(ref v) = map.insert(h, p.bounds) { let mut hint_string = format!("consider combining the bounds: `{:?}: ", p.bounded_ty); for &b in v.iter() { diff --git a/clippy_lints/src/utils/hir_utils.rs b/clippy_lints/src/utils/hir_utils.rs index 276d984f820..5304a9226ae 100644 --- a/clippy_lints/src/utils/hir_utils.rs +++ b/clippy_lints/src/utils/hir_utils.rs @@ -258,7 +258,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> { } pub fn eq_ty(&mut self, left: &Ty<'tcx>, right: &Ty<'tcx>) -> bool { - self.eq_ty_kind(&left.node, &right.node) + self.eq_ty_kind(&left.sty, &right.sty) } #[allow(clippy::similar_names)] @@ -604,26 +604,26 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { } } - pub fn hash_ty(&mut self, ty: &Ty<'tcx>) { + pub fn hash_ty(&mut self, ty: &TyKind) { std::mem::discriminant(&ty.node).hash(&mut self.s); - match ty.sty { - ty::Slice(ty) => { + match ty { + TyKind::Slice(ty) => { self.hash_ty(ty); }, - ty::Array(ty, anon_const) => { + TyKind::Array(ty, anon_const) => { self.hash_ty(ty); self.hash_expr(&self.cx.tcx.hir().body(anon_const.body).value); }, - ty::Ptr(mut_ty) => { + TyKind::Ptr(mut_ty) => { self.hash_ty(&mut_ty.ty); mut_ty.mutbl.hash(&mut self.s); }, - ty::Rptr(lifetime, mut_ty) => { + TyKind::Rptr(lifetime, mut_ty) => { self.hash_lifetime(lifetime); self.hash_ty(&mut_ty.ty); mut_ty.mutbl.hash(&mut self.s); }, - ty::BareFn(bfn) => { + TyKind::BareFn(bfn) => { bfn.unsafety.hash(&mut self.s); bfn.abi.hash(&mut self.s); for arg in &bfn.decl.inputs { @@ -639,13 +639,13 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { } bfn.decl.c_variadic.hash(&mut self.s); }, - ty::Tup(ty_list) => { + TyKind::Tup(ty_list) => { for ty in ty_list { self.hash_ty(ty); } }, - ty::Path(qpath) => { + TyKind::Path(qpath) => { match qpath { QPath::Resolved(ref maybe_ty, ref path) => { if let Some(ref ty) = maybe_ty { @@ -661,7 +661,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { }, } }, - ty::Def(_, arg_list) => { + TyKind::Def(_, arg_list) => { for arg in arg_list { match arg { GenericArg::Lifetime(ref l) => self.hash_lifetime(l), @@ -672,17 +672,17 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { } } }, - ty::TraitObject(_, lifetime) => { + TyKind::TraitObject(_, lifetime) => { self.hash_lifetime(lifetime); }, - ty::Typeof(anon_const) => { + TyKind::Typeof(anon_const) => { self.hash_expr(&self.cx.tcx.hir().body(anon_const.body).value); }, - ty::CVarArgs(lifetime) => { - self.hash_lifetime(lifetime); + TyKind::CVarArgs(lifetime) => { + self.hash_lifetime(lifetime) }, - ty::Err | ty::Infer | ty::Never => {}, + TyKind::Err | TyKind::Infer | TyKind::Never => {}, } } }