@@ -20,39 +20,25 @@ use rustc_hir as hir;
20
20
use rustc_hir:: def:: Res ;
21
21
use rustc_hir:: intravisit:: { self , Visitor } ;
22
22
use rustc_hir:: { Expr , ExprKind , PatKind , TraitItem , TraitItemKind , UnOp } ;
23
- use rustc_hir:: { TraitItem , TraitItemKind } ;
24
23
use rustc_lint:: { LateContext , LateLintPass , Lint , LintContext } ;
25
24
use rustc_middle:: lint:: in_external_macro;
26
25
use rustc_middle:: ty:: { self , TraitRef , Ty , TyS } ;
27
26
use rustc_semver:: RustcVersion ;
28
27
use rustc_session:: { declare_tool_lint, impl_lint_pass} ;
29
28
use rustc_span:: source_map:: Span ;
30
29
use rustc_span:: symbol:: { sym, Symbol , SymbolStr } ;
31
- use rustc_span:: symbol:: { sym, Symbol , SymbolStr } ;
32
30
use rustc_typeck:: hir_ty_to_ty;
33
31
34
32
use crate :: consts:: { constant, Constant } ;
35
33
use crate :: utils:: eager_or_lazy:: is_lazyness_candidate;
36
34
use crate :: utils:: usage:: mutated_variables;
37
35
use crate :: utils:: {
38
- contains_return, contains_return, contains_ty, contains_ty, contains_ty, get_arg_name, get_arg_name,
39
- get_parent_expr, get_parent_expr, get_parent_expr, get_trait_def_id, get_trait_def_id, get_trait_def_id,
40
- has_iter_method, has_iter_method, has_iter_method, higher, higher, higher, implements_trait, implements_trait,
41
- implements_trait, in_macro, in_macro, in_macro, is_copy, is_copy, is_copy, is_expn_of, is_expn_of, is_expn_of,
42
- is_type_diagnostic_item, is_type_diagnostic_item, is_type_diagnostic_item, iter_input_pats, iter_input_pats,
43
- iter_input_pats, last_path_segment, last_path_segment, last_path_segment, match_def_path, match_def_path,
44
- match_def_path, match_qpath, match_qpath, match_qpath, match_trait_method, match_trait_method, match_trait_method,
45
- match_type, match_type, match_type, match_var, match_var, meets_msrv, meets_msrv, method_calls, method_calls,
46
- method_calls, method_chain_args, method_chain_args, method_chain_args, path_to_local_id, paths, paths, paths,
47
- remove_blocks, remove_blocks, remove_blocks, return_ty, return_ty, return_ty, single_segment_path,
48
- single_segment_path, single_segment_path, snippet, snippet, snippet, snippet_block, snippet_block,
49
- snippet_with_applicability, snippet_with_applicability, snippet_with_applicability, snippet_with_applicability,
50
- snippet_with_macro_callsite, snippet_with_macro_callsite, snippet_with_macro_callsite, snippet_with_macro_callsite,
51
- span_lint, span_lint, span_lint, span_lint, span_lint_and_help, span_lint_and_help, span_lint_and_help,
52
- span_lint_and_help, span_lint_and_sugg, span_lint_and_sugg, span_lint_and_sugg, span_lint_and_sugg,
53
- span_lint_and_then, span_lint_and_then, span_lint_and_then, span_lint_and_then, strip_pat_refs, sugg, sugg, sugg,
54
- sugg, walk_ptrs_ty_depth, walk_ptrs_ty_depth, walk_ptrs_ty_depth, walk_ptrs_ty_depth, SpanlessEq , SpanlessEq ,
55
- SpanlessEq , SpanlessEq ,
36
+ contains_return, contains_ty, get_parent_expr, get_trait_def_id, has_iter_method, higher, implements_trait,
37
+ in_macro, is_copy, is_expn_of, is_type_diagnostic_item, iter_input_pats, last_path_segment, match_def_path,
38
+ match_qpath, match_trait_method, match_type, match_var, meets_msrv, method_calls, method_chain_args,
39
+ path_to_local_id, paths, remove_blocks, return_ty, single_segment_path, snippet, snippet_block,
40
+ snippet_with_applicability, snippet_with_macro_callsite, span_lint, span_lint_and_help, span_lint_and_sugg,
41
+ span_lint_and_then, strip_pat_refs, sugg, walk_ptrs_ty_depth, SpanlessEq ,
56
42
} ;
57
43
58
44
declare_clippy_lint ! {
@@ -2212,13 +2198,13 @@ fn lint_expect_fun_call(
2212
2198
match node {
2213
2199
hir:: ExprKind :: AddrOf ( hir:: BorrowKind :: Ref , _, expr) => {
2214
2200
is_call ( & expr. kind )
2215
- } ,
2201
+ }
2216
2202
hir:: ExprKind :: Call ( ..)
2217
2203
| hir:: ExprKind :: MethodCall ( ..)
2218
2204
// These variants are debatable or require further examination
2219
2205
| hir:: ExprKind :: If ( ..)
2220
2206
| hir:: ExprKind :: Match ( ..)
2221
- | hir:: ExprKind :: Block { .. } => true ,
2207
+ | hir:: ExprKind :: Block { .. } => true ,
2222
2208
_ => false ,
2223
2209
}
2224
2210
}
@@ -4022,6 +4008,7 @@ struct ShouldImplTraitCase {
4022
4008
// certain methods with explicit lifetimes can't implement the equivalent trait method
4023
4009
lint_explicit_lifetime : bool ,
4024
4010
}
4011
+
4025
4012
impl ShouldImplTraitCase {
4026
4013
const fn new (
4027
4014
trait_name : & ' static str ,
@@ -4058,37 +4045,37 @@ impl ShouldImplTraitCase {
4058
4045
4059
4046
#[ rustfmt:: skip]
4060
4047
const TRAIT_METHODS : [ ShouldImplTraitCase ; 30 ] = [
4061
- ShouldImplTraitCase :: new ( "std::ops::Add" , "add" , 2 , FN_HEADER , SelfKind :: Value , OutType :: Any , true ) ,
4062
- ShouldImplTraitCase :: new ( "std::convert::AsMut" , "as_mut" , 1 , FN_HEADER , SelfKind :: RefMut , OutType :: Ref , true ) ,
4063
- ShouldImplTraitCase :: new ( "std::convert::AsRef" , "as_ref" , 1 , FN_HEADER , SelfKind :: Ref , OutType :: Ref , true ) ,
4064
- ShouldImplTraitCase :: new ( "std::ops::BitAnd" , "bitand" , 2 , FN_HEADER , SelfKind :: Value , OutType :: Any , true ) ,
4065
- ShouldImplTraitCase :: new ( "std::ops::BitOr" , "bitor" , 2 , FN_HEADER , SelfKind :: Value , OutType :: Any , true ) ,
4066
- ShouldImplTraitCase :: new ( "std::ops::BitXor" , "bitxor" , 2 , FN_HEADER , SelfKind :: Value , OutType :: Any , true ) ,
4067
- ShouldImplTraitCase :: new ( "std::borrow::Borrow" , "borrow" , 1 , FN_HEADER , SelfKind :: Ref , OutType :: Ref , true ) ,
4068
- ShouldImplTraitCase :: new ( "std::borrow::BorrowMut" , "borrow_mut" , 1 , FN_HEADER , SelfKind :: RefMut , OutType :: Ref , true ) ,
4069
- ShouldImplTraitCase :: new ( "std::clone::Clone" , "clone" , 1 , FN_HEADER , SelfKind :: Ref , OutType :: Any , true ) ,
4070
- ShouldImplTraitCase :: new ( "std::cmp::Ord" , "cmp" , 2 , FN_HEADER , SelfKind :: Ref , OutType :: Any , true ) ,
4048
+ ShouldImplTraitCase :: new ( "std::ops::Add" , "add" , 2 , FN_HEADER , SelfKind :: Value , OutType :: Any , true ) ,
4049
+ ShouldImplTraitCase :: new ( "std::convert::AsMut" , "as_mut" , 1 , FN_HEADER , SelfKind :: RefMut , OutType :: Ref , true ) ,
4050
+ ShouldImplTraitCase :: new ( "std::convert::AsRef" , "as_ref" , 1 , FN_HEADER , SelfKind :: Ref , OutType :: Ref , true ) ,
4051
+ ShouldImplTraitCase :: new ( "std::ops::BitAnd" , "bitand" , 2 , FN_HEADER , SelfKind :: Value , OutType :: Any , true ) ,
4052
+ ShouldImplTraitCase :: new ( "std::ops::BitOr" , "bitor" , 2 , FN_HEADER , SelfKind :: Value , OutType :: Any , true ) ,
4053
+ ShouldImplTraitCase :: new ( "std::ops::BitXor" , "bitxor" , 2 , FN_HEADER , SelfKind :: Value , OutType :: Any , true ) ,
4054
+ ShouldImplTraitCase :: new ( "std::borrow::Borrow" , "borrow" , 1 , FN_HEADER , SelfKind :: Ref , OutType :: Ref , true ) ,
4055
+ ShouldImplTraitCase :: new ( "std::borrow::BorrowMut" , "borrow_mut" , 1 , FN_HEADER , SelfKind :: RefMut , OutType :: Ref , true ) ,
4056
+ ShouldImplTraitCase :: new ( "std::clone::Clone" , "clone" , 1 , FN_HEADER , SelfKind :: Ref , OutType :: Any , true ) ,
4057
+ ShouldImplTraitCase :: new ( "std::cmp::Ord" , "cmp" , 2 , FN_HEADER , SelfKind :: Ref , OutType :: Any , true ) ,
4071
4058
// FIXME: default doesn't work
4072
- ShouldImplTraitCase :: new ( "std::default::Default" , "default" , 0 , FN_HEADER , SelfKind :: No , OutType :: Any , true ) ,
4073
- ShouldImplTraitCase :: new ( "std::ops::Deref" , "deref" , 1 , FN_HEADER , SelfKind :: Ref , OutType :: Ref , true ) ,
4074
- ShouldImplTraitCase :: new ( "std::ops::DerefMut" , "deref_mut" , 1 , FN_HEADER , SelfKind :: RefMut , OutType :: Ref , true ) ,
4075
- ShouldImplTraitCase :: new ( "std::ops::Div" , "div" , 2 , FN_HEADER , SelfKind :: Value , OutType :: Any , true ) ,
4076
- ShouldImplTraitCase :: new ( "std::ops::Drop" , "drop" , 1 , FN_HEADER , SelfKind :: RefMut , OutType :: Unit , true ) ,
4077
- ShouldImplTraitCase :: new ( "std::cmp::PartialEq" , "eq" , 2 , FN_HEADER , SelfKind :: Ref , OutType :: Bool , true ) ,
4078
- ShouldImplTraitCase :: new ( "std::iter::FromIterator" , "from_iter" , 1 , FN_HEADER , SelfKind :: No , OutType :: Any , true ) ,
4079
- ShouldImplTraitCase :: new ( "std::str::FromStr" , "from_str" , 1 , FN_HEADER , SelfKind :: No , OutType :: Any , true ) ,
4080
- ShouldImplTraitCase :: new ( "std::hash::Hash" , "hash" , 2 , FN_HEADER , SelfKind :: Ref , OutType :: Unit , true ) ,
4081
- ShouldImplTraitCase :: new ( "std::ops::Index" , "index" , 2 , FN_HEADER , SelfKind :: Ref , OutType :: Ref , true ) ,
4082
- ShouldImplTraitCase :: new ( "std::ops::IndexMut" , "index_mut" , 2 , FN_HEADER , SelfKind :: RefMut , OutType :: Ref , true ) ,
4083
- ShouldImplTraitCase :: new ( "std::iter::IntoIterator" , "into_iter" , 1 , FN_HEADER , SelfKind :: Value , OutType :: Any , true ) ,
4084
- ShouldImplTraitCase :: new ( "std::ops::Mul" , "mul" , 2 , FN_HEADER , SelfKind :: Value , OutType :: Any , true ) ,
4085
- ShouldImplTraitCase :: new ( "std::ops::Neg" , "neg" , 1 , FN_HEADER , SelfKind :: Value , OutType :: Any , true ) ,
4086
- ShouldImplTraitCase :: new ( "std::iter::Iterator" , "next" , 1 , FN_HEADER , SelfKind :: RefMut , OutType :: Any , false ) ,
4087
- ShouldImplTraitCase :: new ( "std::ops::Not" , "not" , 1 , FN_HEADER , SelfKind :: Value , OutType :: Any , true ) ,
4088
- ShouldImplTraitCase :: new ( "std::ops::Rem" , "rem" , 2 , FN_HEADER , SelfKind :: Value , OutType :: Any , true ) ,
4089
- ShouldImplTraitCase :: new ( "std::ops::Shl" , "shl" , 2 , FN_HEADER , SelfKind :: Value , OutType :: Any , true ) ,
4090
- ShouldImplTraitCase :: new ( "std::ops::Shr" , "shr" , 2 , FN_HEADER , SelfKind :: Value , OutType :: Any , true ) ,
4091
- ShouldImplTraitCase :: new ( "std::ops::Sub" , "sub" , 2 , FN_HEADER , SelfKind :: Value , OutType :: Any , true ) ,
4059
+ ShouldImplTraitCase :: new ( "std::default::Default" , "default" , 0 , FN_HEADER , SelfKind :: No , OutType :: Any , true ) ,
4060
+ ShouldImplTraitCase :: new ( "std::ops::Deref" , "deref" , 1 , FN_HEADER , SelfKind :: Ref , OutType :: Ref , true ) ,
4061
+ ShouldImplTraitCase :: new ( "std::ops::DerefMut" , "deref_mut" , 1 , FN_HEADER , SelfKind :: RefMut , OutType :: Ref , true ) ,
4062
+ ShouldImplTraitCase :: new ( "std::ops::Div" , "div" , 2 , FN_HEADER , SelfKind :: Value , OutType :: Any , true ) ,
4063
+ ShouldImplTraitCase :: new ( "std::ops::Drop" , "drop" , 1 , FN_HEADER , SelfKind :: RefMut , OutType :: Unit , true ) ,
4064
+ ShouldImplTraitCase :: new ( "std::cmp::PartialEq" , "eq" , 2 , FN_HEADER , SelfKind :: Ref , OutType :: Bool , true ) ,
4065
+ ShouldImplTraitCase :: new ( "std::iter::FromIterator" , "from_iter" , 1 , FN_HEADER , SelfKind :: No , OutType :: Any , true ) ,
4066
+ ShouldImplTraitCase :: new ( "std::str::FromStr" , "from_str" , 1 , FN_HEADER , SelfKind :: No , OutType :: Any , true ) ,
4067
+ ShouldImplTraitCase :: new ( "std::hash::Hash" , "hash" , 2 , FN_HEADER , SelfKind :: Ref , OutType :: Unit , true ) ,
4068
+ ShouldImplTraitCase :: new ( "std::ops::Index" , "index" , 2 , FN_HEADER , SelfKind :: Ref , OutType :: Ref , true ) ,
4069
+ ShouldImplTraitCase :: new ( "std::ops::IndexMut" , "index_mut" , 2 , FN_HEADER , SelfKind :: RefMut , OutType :: Ref , true ) ,
4070
+ ShouldImplTraitCase :: new ( "std::iter::IntoIterator" , "into_iter" , 1 , FN_HEADER , SelfKind :: Value , OutType :: Any , true ) ,
4071
+ ShouldImplTraitCase :: new ( "std::ops::Mul" , "mul" , 2 , FN_HEADER , SelfKind :: Value , OutType :: Any , true ) ,
4072
+ ShouldImplTraitCase :: new ( "std::ops::Neg" , "neg" , 1 , FN_HEADER , SelfKind :: Value , OutType :: Any , true ) ,
4073
+ ShouldImplTraitCase :: new ( "std::iter::Iterator" , "next" , 1 , FN_HEADER , SelfKind :: RefMut , OutType :: Any , false ) ,
4074
+ ShouldImplTraitCase :: new ( "std::ops::Not" , "not" , 1 , FN_HEADER , SelfKind :: Value , OutType :: Any , true ) ,
4075
+ ShouldImplTraitCase :: new ( "std::ops::Rem" , "rem" , 2 , FN_HEADER , SelfKind :: Value , OutType :: Any , true ) ,
4076
+ ShouldImplTraitCase :: new ( "std::ops::Shl" , "shl" , 2 , FN_HEADER , SelfKind :: Value , OutType :: Any , true ) ,
4077
+ ShouldImplTraitCase :: new ( "std::ops::Shr" , "shr" , 2 , FN_HEADER , SelfKind :: Value , OutType :: Any , true ) ,
4078
+ ShouldImplTraitCase :: new ( "std::ops::Sub" , "sub" , 2 , FN_HEADER , SelfKind :: Value , OutType :: Any , true ) ,
4092
4079
] ;
4093
4080
4094
4081
#[ rustfmt:: skip]
0 commit comments