@@ -8,11 +8,9 @@ use rustc_const_eval::eval_const_expr_partial;
8
8
use std:: borrow:: Cow ;
9
9
use std:: fmt;
10
10
use syntax:: codemap:: Span ;
11
- use syntax:: ptr:: P ;
12
11
use utils:: { get_trait_def_id, implements_trait, in_external_macro, in_macro, is_copy, match_path,
13
12
match_trait_method, match_type, method_chain_args, return_ty, same_tys, snippet,
14
13
span_lint, span_lint_and_then, span_note_and_lint, walk_ptrs_ty, walk_ptrs_ty_depth} ;
15
- use utils:: MethodArgs ;
16
14
use utils:: paths;
17
15
use utils:: sugg;
18
16
@@ -693,7 +691,7 @@ impl LateLintPass for Pass {
693
691
}
694
692
695
693
/// Checks for the `OR_FUN_CALL` lint.
696
- fn lint_or_fun_call ( cx : & LateContext , expr : & hir:: Expr , name : & str , args : & [ P < hir:: Expr > ] ) {
694
+ fn lint_or_fun_call ( cx : & LateContext , expr : & hir:: Expr , name : & str , args : & [ hir:: Expr ] ) {
697
695
/// Check for `unwrap_or(T::new())` or `unwrap_or(T::default())`.
698
696
fn check_unwrap_or_default ( cx : & LateContext , name : & str , fun : & hir:: Expr , self_expr : & hir:: Expr , arg : & hir:: Expr ,
699
697
or_has_args : bool , span : Span )
@@ -825,7 +823,7 @@ fn lint_clone_on_copy(cx: &LateContext, expr: &hir::Expr, arg: &hir::Expr, arg_t
825
823
}
826
824
}
827
825
828
- fn lint_vec_extend ( cx : & LateContext , expr : & hir:: Expr , args : & MethodArgs ) {
826
+ fn lint_vec_extend ( cx : & LateContext , expr : & hir:: Expr , args : & [ hir :: Expr ] ) {
829
827
let arg_ty = cx. tcx . tables ( ) . expr_ty ( & args[ 1 ] ) ;
830
828
if let Some ( slice) = derefs_to_slice ( cx, & args[ 1 ] , arg_ty) {
831
829
span_lint_and_then ( cx, EXTEND_FROM_SLICE , expr. span , "use of `extend` to extend a Vec by a slice" , |db| {
@@ -838,7 +836,7 @@ fn lint_vec_extend(cx: &LateContext, expr: &hir::Expr, args: &MethodArgs) {
838
836
}
839
837
}
840
838
841
- fn lint_string_extend ( cx : & LateContext , expr : & hir:: Expr , args : & MethodArgs ) {
839
+ fn lint_string_extend ( cx : & LateContext , expr : & hir:: Expr , args : & [ hir :: Expr ] ) {
842
840
let arg = & args[ 1 ] ;
843
841
if let Some ( arglists) = method_chain_args ( arg, & [ "chars" ] ) {
844
842
let target = & arglists[ 0 ] [ 0 ] ;
@@ -866,7 +864,7 @@ fn lint_string_extend(cx: &LateContext, expr: &hir::Expr, args: &MethodArgs) {
866
864
}
867
865
}
868
866
869
- fn lint_extend ( cx : & LateContext , expr : & hir:: Expr , args : & MethodArgs ) {
867
+ fn lint_extend ( cx : & LateContext , expr : & hir:: Expr , args : & [ hir :: Expr ] ) {
870
868
let ( obj_ty, _) = walk_ptrs_ty_depth ( cx. tcx . tables ( ) . expr_ty ( & args[ 0 ] ) ) ;
871
869
if match_type ( cx, obj_ty, & paths:: VEC ) {
872
870
lint_vec_extend ( cx, expr, args) ;
@@ -891,9 +889,7 @@ fn lint_cstring_as_ptr(cx: &LateContext, expr: &hir::Expr, new: &hir::Expr, unwr
891
889
} }
892
890
}
893
891
894
- #[ allow( ptr_arg) ]
895
- // Type of MethodArgs is potentially a Vec
896
- fn lint_iter_nth ( cx : & LateContext , expr : & hir:: Expr , iter_args : & MethodArgs , is_mut : bool ) {
892
+ fn lint_iter_nth ( cx : & LateContext , expr : & hir:: Expr , iter_args : & [ hir:: Expr ] , is_mut : bool ) {
897
893
let mut_str = if is_mut { "_mut" } else { "" } ;
898
894
let caller_type = if derefs_to_slice ( cx, & iter_args[ 0 ] , cx. tcx . tables ( ) . expr_ty ( & iter_args[ 0 ] ) ) . is_some ( ) {
899
895
"slice"
@@ -917,7 +913,7 @@ fn lint_iter_nth(cx: &LateContext, expr: &hir::Expr, iter_args: &MethodArgs, is_
917
913
) ;
918
914
}
919
915
920
- fn lint_get_unwrap ( cx : & LateContext , expr : & hir:: Expr , get_args : & MethodArgs , is_mut : bool ) {
916
+ fn lint_get_unwrap ( cx : & LateContext , expr : & hir:: Expr , get_args : & [ hir :: Expr ] , is_mut : bool ) {
921
917
// Note: we don't want to lint `get_mut().unwrap` for HashMap or BTreeMap,
922
918
// because they do not implement `IndexMut`
923
919
let expr_ty = cx. tcx . tables ( ) . expr_ty ( & get_args[ 0 ] ) ;
@@ -980,7 +976,7 @@ fn derefs_to_slice(cx: &LateContext, expr: &hir::Expr, ty: ty::Ty) -> Option<sug
980
976
981
977
if let hir:: ExprMethodCall ( name, _, ref args) = expr. node {
982
978
if & * name. node . as_str ( ) == "iter" && may_slice ( cx, cx. tcx . tables ( ) . expr_ty ( & args[ 0 ] ) ) {
983
- sugg:: Sugg :: hir_opt ( cx, & * args[ 0 ] ) . map ( |sugg| {
979
+ sugg:: Sugg :: hir_opt ( cx, & args[ 0 ] ) . map ( |sugg| {
984
980
sugg. addr ( )
985
981
} )
986
982
} else {
@@ -1002,10 +998,8 @@ fn derefs_to_slice(cx: &LateContext, expr: &hir::Expr, ty: ty::Ty) -> Option<sug
1002
998
}
1003
999
}
1004
1000
1005
- #[ allow( ptr_arg) ]
1006
- // Type of MethodArgs is potentially a Vec
1007
1001
/// lint use of `unwrap()` for `Option`s and `Result`s
1008
- fn lint_unwrap ( cx : & LateContext , expr : & hir:: Expr , unwrap_args : & MethodArgs ) {
1002
+ fn lint_unwrap ( cx : & LateContext , expr : & hir:: Expr , unwrap_args : & [ hir :: Expr ] ) {
1009
1003
let ( obj_ty, _) = walk_ptrs_ty_depth ( cx. tcx . tables ( ) . expr_ty ( & unwrap_args[ 0 ] ) ) ;
1010
1004
1011
1005
let mess = if match_type ( cx, obj_ty, & paths:: OPTION ) {
@@ -1028,10 +1022,8 @@ fn lint_unwrap(cx: &LateContext, expr: &hir::Expr, unwrap_args: &MethodArgs) {
1028
1022
}
1029
1023
}
1030
1024
1031
- #[ allow( ptr_arg) ]
1032
- // Type of MethodArgs is potentially a Vec
1033
1025
/// lint use of `ok().expect()` for `Result`s
1034
- fn lint_ok_expect ( cx : & LateContext , expr : & hir:: Expr , ok_args : & MethodArgs ) {
1026
+ fn lint_ok_expect ( cx : & LateContext , expr : & hir:: Expr , ok_args : & [ hir :: Expr ] ) {
1035
1027
// lint if the caller of `ok()` is a `Result`
1036
1028
if match_type ( cx, cx. tcx . tables ( ) . expr_ty ( & ok_args[ 0 ] ) , & paths:: RESULT ) {
1037
1029
let result_type = cx. tcx . tables ( ) . expr_ty ( & ok_args[ 0 ] ) ;
@@ -1046,10 +1038,8 @@ fn lint_ok_expect(cx: &LateContext, expr: &hir::Expr, ok_args: &MethodArgs) {
1046
1038
}
1047
1039
}
1048
1040
1049
- #[ allow( ptr_arg) ]
1050
- // Type of MethodArgs is potentially a Vec
1051
1041
/// lint use of `map().unwrap_or()` for `Option`s
1052
- fn lint_map_unwrap_or ( cx : & LateContext , expr : & hir:: Expr , map_args : & MethodArgs , unwrap_args : & MethodArgs ) {
1042
+ fn lint_map_unwrap_or ( cx : & LateContext , expr : & hir:: Expr , map_args : & [ hir :: Expr ] , unwrap_args : & [ hir :: Expr ] ) {
1053
1043
// lint if the caller of `map()` is an `Option`
1054
1044
if match_type ( cx, cx. tcx . tables ( ) . expr_ty ( & map_args[ 0 ] ) , & paths:: OPTION ) {
1055
1045
// lint message
@@ -1077,10 +1067,8 @@ fn lint_map_unwrap_or(cx: &LateContext, expr: &hir::Expr, map_args: &MethodArgs,
1077
1067
}
1078
1068
}
1079
1069
1080
- #[ allow( ptr_arg) ]
1081
- // Type of MethodArgs is potentially a Vec
1082
1070
/// lint use of `map().unwrap_or_else()` for `Option`s
1083
- fn lint_map_unwrap_or_else ( cx : & LateContext , expr : & hir:: Expr , map_args : & MethodArgs , unwrap_args : & MethodArgs ) {
1071
+ fn lint_map_unwrap_or_else ( cx : & LateContext , expr : & hir:: Expr , map_args : & [ hir :: Expr ] , unwrap_args : & [ hir :: Expr ] ) {
1084
1072
// lint if the caller of `map()` is an `Option`
1085
1073
if match_type ( cx, cx. tcx . tables ( ) . expr_ty ( & map_args[ 0 ] ) , & paths:: OPTION ) {
1086
1074
// lint message
@@ -1108,10 +1096,8 @@ fn lint_map_unwrap_or_else(cx: &LateContext, expr: &hir::Expr, map_args: &Method
1108
1096
}
1109
1097
}
1110
1098
1111
- #[ allow( ptr_arg) ]
1112
- // Type of MethodArgs is potentially a Vec
1113
1099
/// lint use of `filter().next()` for `Iterators`
1114
- fn lint_filter_next ( cx : & LateContext , expr : & hir:: Expr , filter_args : & MethodArgs ) {
1100
+ fn lint_filter_next ( cx : & LateContext , expr : & hir:: Expr , filter_args : & [ hir :: Expr ] ) {
1115
1101
// lint if caller of `.filter().next()` is an Iterator
1116
1102
if match_trait_method ( cx, expr, & paths:: ITERATOR ) {
1117
1103
let msg = "called `filter(p).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(p)` \
@@ -1131,9 +1117,8 @@ fn lint_filter_next(cx: &LateContext, expr: &hir::Expr, filter_args: &MethodArgs
1131
1117
}
1132
1118
}
1133
1119
1134
- // Type of MethodArgs is potentially a Vec
1135
1120
/// lint use of `filter().map()` for `Iterators`
1136
- fn lint_filter_map ( cx : & LateContext , expr : & hir:: Expr , _filter_args : & MethodArgs , _map_args : & MethodArgs ) {
1121
+ fn lint_filter_map ( cx : & LateContext , expr : & hir:: Expr , _filter_args : & [ hir :: Expr ] , _map_args : & [ hir :: Expr ] ) {
1137
1122
// lint if caller of `.filter().map()` is an Iterator
1138
1123
if match_trait_method ( cx, expr, & paths:: ITERATOR ) {
1139
1124
let msg = "called `filter(p).map(q)` on an `Iterator`. \
@@ -1142,9 +1127,8 @@ fn lint_filter_map(cx: &LateContext, expr: &hir::Expr, _filter_args: &MethodArgs
1142
1127
}
1143
1128
}
1144
1129
1145
- // Type of MethodArgs is potentially a Vec
1146
1130
/// lint use of `filter().map()` for `Iterators`
1147
- fn lint_filter_map_map ( cx : & LateContext , expr : & hir:: Expr , _filter_args : & MethodArgs , _map_args : & MethodArgs ) {
1131
+ fn lint_filter_map_map ( cx : & LateContext , expr : & hir:: Expr , _filter_args : & [ hir :: Expr ] , _map_args : & [ hir :: Expr ] ) {
1148
1132
// lint if caller of `.filter().map()` is an Iterator
1149
1133
if match_trait_method ( cx, expr, & paths:: ITERATOR ) {
1150
1134
let msg = "called `filter_map(p).map(q)` on an `Iterator`. \
@@ -1153,9 +1137,8 @@ fn lint_filter_map_map(cx: &LateContext, expr: &hir::Expr, _filter_args: &Method
1153
1137
}
1154
1138
}
1155
1139
1156
- // Type of MethodArgs is potentially a Vec
1157
1140
/// lint use of `filter().flat_map()` for `Iterators`
1158
- fn lint_filter_flat_map ( cx : & LateContext , expr : & hir:: Expr , _filter_args : & MethodArgs , _map_args : & MethodArgs ) {
1141
+ fn lint_filter_flat_map ( cx : & LateContext , expr : & hir:: Expr , _filter_args : & [ hir :: Expr ] , _map_args : & [ hir :: Expr ] ) {
1159
1142
// lint if caller of `.filter().flat_map()` is an Iterator
1160
1143
if match_trait_method ( cx, expr, & paths:: ITERATOR ) {
1161
1144
let msg = "called `filter(p).flat_map(q)` on an `Iterator`. \
@@ -1165,9 +1148,8 @@ fn lint_filter_flat_map(cx: &LateContext, expr: &hir::Expr, _filter_args: &Metho
1165
1148
}
1166
1149
}
1167
1150
1168
- // Type of MethodArgs is potentially a Vec
1169
1151
/// lint use of `filter_map().flat_map()` for `Iterators`
1170
- fn lint_filter_map_flat_map ( cx : & LateContext , expr : & hir:: Expr , _filter_args : & MethodArgs , _map_args : & MethodArgs ) {
1152
+ fn lint_filter_map_flat_map ( cx : & LateContext , expr : & hir:: Expr , _filter_args : & [ hir :: Expr ] , _map_args : & [ hir :: Expr ] ) {
1171
1153
// lint if caller of `.filter_map().flat_map()` is an Iterator
1172
1154
if match_trait_method ( cx, expr, & paths:: ITERATOR ) {
1173
1155
let msg = "called `filter_map(p).flat_map(q)` on an `Iterator`. \
@@ -1177,13 +1159,11 @@ fn lint_filter_map_flat_map(cx: &LateContext, expr: &hir::Expr, _filter_args: &M
1177
1159
}
1178
1160
}
1179
1161
1180
- #[ allow( ptr_arg) ]
1181
- // Type of MethodArgs is potentially a Vec
1182
1162
/// lint searching an Iterator followed by `is_some()`
1183
- fn lint_search_is_some ( cx : & LateContext , expr : & hir:: Expr , search_method : & str , search_args : & MethodArgs ,
1184
- is_some_args : & MethodArgs ) {
1163
+ fn lint_search_is_some ( cx : & LateContext , expr : & hir:: Expr , search_method : & str , search_args : & [ hir :: Expr ] ,
1164
+ is_some_args : & [ hir :: Expr ] ) {
1185
1165
// lint if caller of search is an Iterator
1186
- if match_trait_method ( cx, & * is_some_args[ 0 ] , & paths:: ITERATOR ) {
1166
+ if match_trait_method ( cx, & is_some_args[ 0 ] , & paths:: ITERATOR ) {
1187
1167
let msg = format ! ( "called `is_some()` after searching an `Iterator` with {}. This is more succinctly expressed \
1188
1168
by calling `any()`.",
1189
1169
search_method) ;
0 commit comments