Skip to content

Commit 0c83325

Browse files
author
Michael Wright
committed
Merge branch 'master' into fix-4437
2 parents 23336ad + 4c8a941 commit 0c83325

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+680
-181
lines changed

CONTRIBUTING.md

+17-1
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,28 @@ using that version of Rust.
145145

146146
You can use [rustup-toolchain-install-master][rtim] to do that:
147147

148-
```
148+
```bash
149149
cargo install rustup-toolchain-install-master
150150
rustup-toolchain-install-master -n master --force
151151
rustup override set master
152152
cargo test
153153
```
154154

155+
After fixing the build failure on this repository, we can submit a pull request
156+
to [`rust-lang/rust`] to fix the toolstate.
157+
158+
To submit a pull request, you should follow these steps:
159+
160+
```bash
161+
# Assuming you already cloned the rust-lang/rust repo and you're in the correct directory
162+
git submodule update --remote src/tools/clippy
163+
cargo update -p clippy
164+
git add -u
165+
git commit -m "Update Clippy"
166+
./x.py test -i --stage 1 src/tools/clippy # This is optional and should succeed anyway
167+
# Open a PR in rust-lang/rust
168+
```
169+
155170
## Issue and PR triage
156171

157172
Clippy is following the [Rust triage procedure][triage] for issues and pull
@@ -211,3 +226,4 @@ or the [MIT](http://opensource.org/licenses/MIT) license.
211226
[homu]: https://github.com/servo/homu
212227
[homu_instructions]: https://buildbot2.rust-lang.org/homu/
213228
[homu_queue]: https://buildbot2.rust-lang.org/homu/queue/clippy
229+
[`rust-lang/rust`]: https://github.com/rust-lang/rust

clippy_lints/src/bytecount.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount {
4747
then {
4848
let body = cx.tcx.hir().body(body_id);
4949
if_chain! {
50-
if body.arguments.len() == 1;
51-
if let Some(argname) = get_pat_name(&body.arguments[0].pat);
50+
if body.params.len() == 1;
51+
if let Some(argname) = get_pat_name(&body.params[0].pat);
5252
if let ExprKind::Binary(ref op, ref l, ref r) = body.value.node;
5353
if op.node == BinOpKind::Eq;
5454
if match_type(cx,

clippy_lints/src/escape.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ fn is_argument(map: &hir::map::Map<'_>, id: HirId) -> bool {
108108
}
109109

110110
match map.find(map.get_parent_node(id)) {
111-
Some(Node::Arg(_)) => true,
111+
Some(Node::Param(_)) => true,
112112
_ => false,
113113
}
114114
}

clippy_lints/src/eta_reduction.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,10 @@ fn get_type_name(cx: &LateContext<'_, '_>, ty: Ty<'_>) -> String {
202202
}
203203
}
204204

205-
fn compare_inputs(closure_inputs: &mut dyn Iterator<Item = &Arg>, call_args: &mut dyn Iterator<Item = &Expr>) -> bool {
205+
fn compare_inputs(
206+
closure_inputs: &mut dyn Iterator<Item = &Param>,
207+
call_args: &mut dyn Iterator<Item = &Expr>,
208+
) -> bool {
206209
for (closure_input, function_arg) in closure_inputs.zip(call_args) {
207210
if let PatKind::Binding(_, _, ident, _) = closure_input.pat.node {
208211
// XXXManishearth Should I be checking the binding mode here?

clippy_lints/src/functions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ impl<'a, 'tcx> Functions {
280280
}
281281
}
282282

283-
fn raw_ptr_arg(arg: &hir::Arg, ty: &hir::Ty) -> Option<hir::HirId> {
283+
fn raw_ptr_arg(arg: &hir::Param, ty: &hir::Ty) -> Option<hir::HirId> {
284284
if let (&hir::PatKind::Binding(_, id, _, _), &hir::TyKind::Ptr(_)) = (&arg.pat.node, &ty.node) {
285285
Some(id)
286286
} else {

clippy_lints/src/inherent_to_string.rs

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InherentToString {
104104
if impl_item.ident.name.as_str() == "to_string";
105105
let decl = &signature.decl;
106106
if decl.implicit_self.has_implicit_self();
107+
if decl.inputs.len() == 1;
107108

108109
// Check if return type is String
109110
if match_type(cx, return_ty(cx, impl_item.hir_id), &paths::STRING);

clippy_lints/src/loops.rs

+8
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,14 @@ declare_clippy_lint! {
312312
/// for i in 0..v.len() { foo(v[i]); }
313313
/// for i in 0..v.len() { bar(i, v[i]); }
314314
/// ```
315+
/// Could be written as
316+
/// ```rust
317+
/// # let v = vec![1];
318+
/// # fn foo(bar: usize) {}
319+
/// # fn bar(bar: usize, baz: usize) {}
320+
/// for item in &v { foo(*item); }
321+
/// for (i, item) in v.iter().enumerate() { bar(i, *item); }
322+
/// ```
315323
pub EXPLICIT_COUNTER_LOOP,
316324
complexity,
317325
"for-looping with an explicit counter when `_.enumerate()` would do"

clippy_lints/src/map_clone.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MapClone {
5757
let closure_body = cx.tcx.hir().body(body_id);
5858
let closure_expr = remove_blocks(&closure_body.value);
5959
then {
60-
match closure_body.arguments[0].pat.node {
60+
match closure_body.params[0].pat.node {
6161
hir::PatKind::Ref(ref inner, _) => if let hir::PatKind::Binding(
6262
hir::BindingAnnotation::Unannotated, .., name, None
6363
) = inner.node {

clippy_lints/src/map_unit_fn.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,10 @@ fn reduce_unit_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a hir::Expr) ->
161161
}
162162
}
163163

164-
fn unit_closure<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'a hir::Expr) -> Option<(&'tcx hir::Arg, &'a hir::Expr)> {
164+
fn unit_closure<'a, 'tcx>(
165+
cx: &LateContext<'a, 'tcx>,
166+
expr: &'a hir::Expr,
167+
) -> Option<(&'tcx hir::Param, &'a hir::Expr)> {
165168
if let hir::ExprKind::Closure(_, ref decl, inner_expr_id, _, _) = expr.node {
166169
let body = cx.tcx.hir().body(inner_expr_id);
167170
let body_expr = &body.value;

clippy_lints/src/methods/mod.rs

+28-6
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,11 @@ declare_clippy_lint! {
302302
/// # let vec = vec![1];
303303
/// vec.iter().filter(|x| **x == 0).next();
304304
/// ```
305+
/// Could be written as
306+
/// ```rust
307+
/// # let vec = vec![1];
308+
/// vec.iter().find(|x| **x == 0);
309+
/// ```
305310
pub FILTER_NEXT,
306311
complexity,
307312
"using `filter(p).next()`, which is more succinctly expressed as `.find(p)`"
@@ -425,6 +430,11 @@ declare_clippy_lint! {
425430
/// # let vec = vec![1];
426431
/// vec.iter().find(|x| **x == 0).is_some();
427432
/// ```
433+
/// Could be written as
434+
/// ```rust
435+
/// # let vec = vec![1];
436+
/// vec.iter().any(|x| *x == 0);
437+
/// ```
428438
pub SEARCH_IS_SOME,
429439
complexity,
430440
"using an iterator search followed by `is_some()`, which is more succinctly expressed as a call to `any()`"
@@ -442,7 +452,12 @@ declare_clippy_lint! {
442452
/// **Example:**
443453
/// ```rust
444454
/// let name = "foo";
445-
/// name.chars().next() == Some('_');
455+
/// if name.chars().next() == Some('_') {};
456+
/// ```
457+
/// Could be written as
458+
/// ```rust
459+
/// let name = "foo";
460+
/// if name.starts_with('_') {};
446461
/// ```
447462
pub CHARS_NEXT_CMP,
448463
complexity,
@@ -889,6 +904,10 @@ declare_clippy_lint! {
889904
/// ```rust
890905
/// let _ = [1, 2, 3].into_iter().map(|x| *x).collect::<Vec<u32>>();
891906
/// ```
907+
/// Could be written as:
908+
/// ```rust
909+
/// let _ = [1, 2, 3].iter().map(|x| *x).collect::<Vec<u32>>();
910+
/// ```
892911
pub INTO_ITER_ON_ARRAY,
893912
correctness,
894913
"using `.into_iter()` on an array"
@@ -1713,8 +1732,8 @@ fn lint_unnecessary_fold(cx: &LateContext<'_, '_>, expr: &hir::Expr, fold_args:
17131732
if bin_op.node == op;
17141733

17151734
// Extract the names of the two arguments to the closure
1716-
if let Some(first_arg_ident) = get_arg_name(&closure_body.arguments[0].pat);
1717-
if let Some(second_arg_ident) = get_arg_name(&closure_body.arguments[1].pat);
1735+
if let Some(first_arg_ident) = get_arg_name(&closure_body.params[0].pat);
1736+
if let Some(second_arg_ident) = get_arg_name(&closure_body.params[1].pat);
17181737

17191738
if match_var(&*left_expr, first_arg_ident);
17201739
if replacement_has_args || match_var(&*right_expr, second_arg_ident);
@@ -2326,7 +2345,7 @@ fn lint_flat_map_identity<'a, 'tcx>(
23262345
if let hir::ExprKind::Closure(_, _, body_id, _, _) = arg_node;
23272346
let body = cx.tcx.hir().body(*body_id);
23282347

2329-
if let hir::PatKind::Binding(_, _, binding_ident, _) = body.arguments[0].pat.node;
2348+
if let hir::PatKind::Binding(_, _, binding_ident, _) = body.params[0].pat.node;
23302349
if let hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) = body.value.node;
23312350

23322351
if path.segments.len() == 1;
@@ -2371,7 +2390,7 @@ fn lint_search_is_some<'a, 'tcx>(
23712390
if search_method == "find";
23722391
if let hir::ExprKind::Closure(_, _, body_id, ..) = search_args[1].node;
23732392
let closure_body = cx.tcx.hir().body(body_id);
2374-
if let Some(closure_arg) = closure_body.arguments.get(0);
2393+
if let Some(closure_arg) = closure_body.params.get(0);
23752394
if let hir::PatKind::Ref(..) = closure_arg.pat.node;
23762395
then {
23772396
Some(search_snippet.replacen('&', "", 1))
@@ -2781,7 +2800,10 @@ impl SelfKind {
27812800
hir::Mutability::MutMutable => &paths::ASMUT_TRAIT,
27822801
};
27832802

2784-
let trait_def_id = get_trait_def_id(cx, trait_path).expect("trait def id not found");
2803+
let trait_def_id = match get_trait_def_id(cx, trait_path) {
2804+
Some(did) => did,
2805+
None => return false,
2806+
};
27852807
implements_trait(cx, ty, trait_def_id, &[parent_ty.into()])
27862808
}
27872809

clippy_lints/src/methods/unnecessary_filter_map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub(super) fn lint(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &[hir::Expr
1717

1818
if let hir::ExprKind::Closure(_, _, body_id, ..) = args[1].node {
1919
let body = cx.tcx.hir().body(body_id);
20-
let arg_id = body.arguments[0].pat.hir_id;
20+
let arg_id = body.params[0].pat.hir_id;
2121
let mutates_arg = match mutated_variables(&body.value, cx) {
2222
Some(used_mutably) => used_mutably.contains(&arg_id),
2323
None => true,

clippy_lints/src/misc.rs

+6
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ declare_clippy_lint! {
105105
/// # let y = String::from("foo");
106106
/// if x.to_owned() == y {}
107107
/// ```
108+
/// Could be written as
109+
/// ```rust
110+
/// # let x = "foo";
111+
/// # let y = String::from("foo");
112+
/// if x == y {}
113+
/// ```
108114
pub CMP_OWNED,
109115
perf,
110116
"creating owned instances for comparing with others, e.g., `x == \"foo\".to_string()`"

0 commit comments

Comments
 (0)