@@ -3,9 +3,11 @@ use crate::utils::{
33 is_automatically_derived, is_copy, match_path, span_lint_and_help, span_lint_and_note, span_lint_and_then,
44} ;
55use if_chain:: if_chain;
6- use rustc_hir as hir;
76use rustc_hir:: def_id:: DefId ;
87use rustc_hir:: intravisit:: { walk_expr, walk_fn, walk_item, FnKind , NestedVisitorMap , Visitor } ;
8+ use rustc_hir:: {
9+ BlockCheckMode , BodyId , Expr , ExprKind , FnDecl , HirId , Item , ItemKind , TraitRef , UnsafeSource , Unsafety ,
10+ } ;
911use rustc_lint:: { LateContext , LateLintPass } ;
1012use rustc_middle:: hir:: map:: Map ;
1113use rustc_middle:: ty:: { self , Ty } ;
@@ -97,15 +99,15 @@ declare_clippy_lint! {
9799 /// }
98100 /// ```
99101 pub UNSAFE_DERIVE_DESERIALIZE ,
100- correctness ,
102+ pedantic ,
101103 "deriving `serde::Deserialize` on a type that has methods using `unsafe`"
102104}
103105
104106declare_lint_pass ! ( Derive => [ EXPL_IMPL_CLONE_ON_COPY , DERIVE_HASH_XOR_EQ , UNSAFE_DERIVE_DESERIALIZE ] ) ;
105107
106108impl < ' a , ' tcx > LateLintPass < ' a , ' tcx > for Derive {
107- fn check_item ( & mut self , cx : & LateContext < ' a , ' tcx > , item : & ' tcx hir :: Item < ' _ > ) {
108- if let hir :: ItemKind :: Impl {
109+ fn check_item ( & mut self , cx : & LateContext < ' a , ' tcx > , item : & ' tcx Item < ' _ > ) {
110+ if let ItemKind :: Impl {
109111 of_trait : Some ( ref trait_ref) ,
110112 ..
111113 } = item. kind
@@ -128,7 +130,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Derive {
128130fn check_hash_peq < ' a , ' tcx > (
129131 cx : & LateContext < ' a , ' tcx > ,
130132 span : Span ,
131- trait_ref : & hir :: TraitRef < ' _ > ,
133+ trait_ref : & TraitRef < ' _ > ,
132134 ty : Ty < ' tcx > ,
133135 hash_is_automatically_derived : bool ,
134136) {
@@ -175,12 +177,7 @@ fn check_hash_peq<'a, 'tcx>(
175177}
176178
177179/// Implementation of the `EXPL_IMPL_CLONE_ON_COPY` lint.
178- fn check_copy_clone < ' a , ' tcx > (
179- cx : & LateContext < ' a , ' tcx > ,
180- item : & hir:: Item < ' _ > ,
181- trait_ref : & hir:: TraitRef < ' _ > ,
182- ty : Ty < ' tcx > ,
183- ) {
180+ fn check_copy_clone < ' a , ' tcx > ( cx : & LateContext < ' a , ' tcx > , item : & Item < ' _ > , trait_ref : & TraitRef < ' _ > , ty : Ty < ' tcx > ) {
184181 if match_path ( & trait_ref. path , & paths:: CLONE_TRAIT ) {
185182 if !is_copy ( cx, ty) {
186183 return ;
@@ -223,16 +220,16 @@ fn check_copy_clone<'a, 'tcx>(
223220/// Implementation of the `UNSAFE_DERIVE_DESERIALIZE` lint.
224221fn check_unsafe_derive_deserialize < ' a , ' tcx > (
225222 cx : & LateContext < ' a , ' tcx > ,
226- item : & hir :: Item < ' _ > ,
227- trait_ref : & hir :: TraitRef < ' _ > ,
223+ item : & Item < ' _ > ,
224+ trait_ref : & TraitRef < ' _ > ,
228225 ty : Ty < ' tcx > ,
229226) {
230- fn item_from_def_id < ' tcx > ( cx : & LateContext < ' _ , ' tcx > , def_id : DefId ) -> & ' tcx hir :: Item < ' tcx > {
227+ fn item_from_def_id < ' tcx > ( cx : & LateContext < ' _ , ' tcx > , def_id : DefId ) -> & ' tcx Item < ' tcx > {
231228 let hir_id = cx. tcx . hir ( ) . as_local_hir_id ( def_id) . unwrap ( ) ;
232229 cx. tcx . hir ( ) . expect_item ( hir_id)
233230 }
234231
235- fn has_unsafe < ' tcx > ( cx : & LateContext < ' _ , ' tcx > , item : & ' tcx hir :: Item < ' _ > ) -> bool {
232+ fn has_unsafe < ' tcx > ( cx : & LateContext < ' _ , ' tcx > , item : & ' tcx Item < ' _ > ) -> bool {
236233 let mut visitor = UnsafeVisitor { cx, has_unsafe : false } ;
237234 walk_item ( & mut visitor, item) ;
238235 visitor. has_unsafe
@@ -267,21 +264,14 @@ struct UnsafeVisitor<'a, 'tcx> {
267264impl < ' tcx > Visitor < ' tcx > for UnsafeVisitor < ' _ , ' tcx > {
268265 type Map = Map < ' tcx > ;
269266
270- fn visit_fn (
271- & mut self ,
272- kind : FnKind < ' tcx > ,
273- decl : & ' tcx hir:: FnDecl < ' _ > ,
274- body_id : hir:: BodyId ,
275- span : Span ,
276- id : hir:: HirId ,
277- ) {
267+ fn visit_fn ( & mut self , kind : FnKind < ' tcx > , decl : & ' tcx FnDecl < ' _ > , body_id : BodyId , span : Span , id : HirId ) {
278268 if self . has_unsafe {
279269 return ;
280270 }
281271
282272 if_chain ! {
283273 if let Some ( header) = kind. header( ) ;
284- if let hir :: Unsafety :: Unsafe = header. unsafety;
274+ if let Unsafety :: Unsafe = header. unsafety;
285275 then {
286276 self . has_unsafe = true ;
287277 }
@@ -290,14 +280,12 @@ impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> {
290280 walk_fn ( self , kind, decl, body_id, span, id) ;
291281 }
292282
293- fn visit_expr ( & mut self , expr : & ' tcx hir :: Expr < ' _ > ) {
283+ fn visit_expr ( & mut self , expr : & ' tcx Expr < ' _ > ) {
294284 if self . has_unsafe {
295285 return ;
296286 }
297287
298- if let hir:: ExprKind :: Block ( block, _) = expr. kind {
299- use hir:: { BlockCheckMode , UnsafeSource } ;
300-
288+ if let ExprKind :: Block ( block, _) = expr. kind {
301289 match block. rules {
302290 BlockCheckMode :: UnsafeBlock ( UnsafeSource :: UserProvided )
303291 | BlockCheckMode :: PushUnsafeBlock ( UnsafeSource :: UserProvided )
0 commit comments