Skip to content

Commit

Permalink
Merge branch 'master' into fix-4437
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Wright committed Aug 29, 2019
2 parents 23336ad + 4c8a941 commit 0c83325
Show file tree
Hide file tree
Showing 59 changed files with 680 additions and 181 deletions.
18 changes: 17 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,28 @@ using that version of Rust.

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

```
```bash
cargo install rustup-toolchain-install-master
rustup-toolchain-install-master -n master --force
rustup override set master
cargo test
```

After fixing the build failure on this repository, we can submit a pull request
to [`rust-lang/rust`] to fix the toolstate.

To submit a pull request, you should follow these steps:

```bash
# Assuming you already cloned the rust-lang/rust repo and you're in the correct directory
git submodule update --remote src/tools/clippy
cargo update -p clippy
git add -u
git commit -m "Update Clippy"
./x.py test -i --stage 1 src/tools/clippy # This is optional and should succeed anyway
# Open a PR in rust-lang/rust
```

## Issue and PR triage

Clippy is following the [Rust triage procedure][triage] for issues and pull
Expand Down Expand Up @@ -211,3 +226,4 @@ or the [MIT](http://opensource.org/licenses/MIT) license.
[homu]: https://github.com/servo/homu
[homu_instructions]: https://buildbot2.rust-lang.org/homu/
[homu_queue]: https://buildbot2.rust-lang.org/homu/queue/clippy
[`rust-lang/rust`]: https://github.com/rust-lang/rust
4 changes: 2 additions & 2 deletions clippy_lints/src/bytecount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount {
then {
let body = cx.tcx.hir().body(body_id);
if_chain! {
if body.arguments.len() == 1;
if let Some(argname) = get_pat_name(&body.arguments[0].pat);
if body.params.len() == 1;
if let Some(argname) = get_pat_name(&body.params[0].pat);
if let ExprKind::Binary(ref op, ref l, ref r) = body.value.node;
if op.node == BinOpKind::Eq;
if match_type(cx,
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ fn is_argument(map: &hir::map::Map<'_>, id: HirId) -> bool {
}

match map.find(map.get_parent_node(id)) {
Some(Node::Arg(_)) => true,
Some(Node::Param(_)) => true,
_ => false,
}
}
Expand Down
5 changes: 4 additions & 1 deletion clippy_lints/src/eta_reduction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ fn get_type_name(cx: &LateContext<'_, '_>, ty: Ty<'_>) -> String {
}
}

fn compare_inputs(closure_inputs: &mut dyn Iterator<Item = &Arg>, call_args: &mut dyn Iterator<Item = &Expr>) -> bool {
fn compare_inputs(
closure_inputs: &mut dyn Iterator<Item = &Param>,
call_args: &mut dyn Iterator<Item = &Expr>,
) -> bool {
for (closure_input, function_arg) in closure_inputs.zip(call_args) {
if let PatKind::Binding(_, _, ident, _) = closure_input.pat.node {
// XXXManishearth Should I be checking the binding mode here?
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ impl<'a, 'tcx> Functions {
}
}

fn raw_ptr_arg(arg: &hir::Arg, ty: &hir::Ty) -> Option<hir::HirId> {
fn raw_ptr_arg(arg: &hir::Param, ty: &hir::Ty) -> Option<hir::HirId> {
if let (&hir::PatKind::Binding(_, id, _, _), &hir::TyKind::Ptr(_)) = (&arg.pat.node, &ty.node) {
Some(id)
} else {
Expand Down
1 change: 1 addition & 0 deletions clippy_lints/src/inherent_to_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InherentToString {
if impl_item.ident.name.as_str() == "to_string";
let decl = &signature.decl;
if decl.implicit_self.has_implicit_self();
if decl.inputs.len() == 1;

// Check if return type is String
if match_type(cx, return_ty(cx, impl_item.hir_id), &paths::STRING);
Expand Down
8 changes: 8 additions & 0 deletions clippy_lints/src/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,14 @@ declare_clippy_lint! {
/// for i in 0..v.len() { foo(v[i]); }
/// for i in 0..v.len() { bar(i, v[i]); }
/// ```
/// Could be written as
/// ```rust
/// # let v = vec![1];
/// # fn foo(bar: usize) {}
/// # fn bar(bar: usize, baz: usize) {}
/// for item in &v { foo(*item); }
/// for (i, item) in v.iter().enumerate() { bar(i, *item); }
/// ```
pub EXPLICIT_COUNTER_LOOP,
complexity,
"for-looping with an explicit counter when `_.enumerate()` would do"
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/map_clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MapClone {
let closure_body = cx.tcx.hir().body(body_id);
let closure_expr = remove_blocks(&closure_body.value);
then {
match closure_body.arguments[0].pat.node {
match closure_body.params[0].pat.node {
hir::PatKind::Ref(ref inner, _) => if let hir::PatKind::Binding(
hir::BindingAnnotation::Unannotated, .., name, None
) = inner.node {
Expand Down
5 changes: 4 additions & 1 deletion clippy_lints/src/map_unit_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ fn reduce_unit_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a hir::Expr) ->
}
}

fn unit_closure<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'a hir::Expr) -> Option<(&'tcx hir::Arg, &'a hir::Expr)> {
fn unit_closure<'a, 'tcx>(
cx: &LateContext<'a, 'tcx>,
expr: &'a hir::Expr,
) -> Option<(&'tcx hir::Param, &'a hir::Expr)> {
if let hir::ExprKind::Closure(_, ref decl, inner_expr_id, _, _) = expr.node {
let body = cx.tcx.hir().body(inner_expr_id);
let body_expr = &body.value;
Expand Down
34 changes: 28 additions & 6 deletions clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,11 @@ declare_clippy_lint! {
/// # let vec = vec![1];
/// vec.iter().filter(|x| **x == 0).next();
/// ```
/// Could be written as
/// ```rust
/// # let vec = vec![1];
/// vec.iter().find(|x| **x == 0);
/// ```
pub FILTER_NEXT,
complexity,
"using `filter(p).next()`, which is more succinctly expressed as `.find(p)`"
Expand Down Expand Up @@ -425,6 +430,11 @@ declare_clippy_lint! {
/// # let vec = vec![1];
/// vec.iter().find(|x| **x == 0).is_some();
/// ```
/// Could be written as
/// ```rust
/// # let vec = vec![1];
/// vec.iter().any(|x| *x == 0);
/// ```
pub SEARCH_IS_SOME,
complexity,
"using an iterator search followed by `is_some()`, which is more succinctly expressed as a call to `any()`"
Expand All @@ -442,7 +452,12 @@ declare_clippy_lint! {
/// **Example:**
/// ```rust
/// let name = "foo";
/// name.chars().next() == Some('_');
/// if name.chars().next() == Some('_') {};
/// ```
/// Could be written as
/// ```rust
/// let name = "foo";
/// if name.starts_with('_') {};
/// ```
pub CHARS_NEXT_CMP,
complexity,
Expand Down Expand Up @@ -889,6 +904,10 @@ declare_clippy_lint! {
/// ```rust
/// let _ = [1, 2, 3].into_iter().map(|x| *x).collect::<Vec<u32>>();
/// ```
/// Could be written as:
/// ```rust
/// let _ = [1, 2, 3].iter().map(|x| *x).collect::<Vec<u32>>();
/// ```
pub INTO_ITER_ON_ARRAY,
correctness,
"using `.into_iter()` on an array"
Expand Down Expand Up @@ -1713,8 +1732,8 @@ fn lint_unnecessary_fold(cx: &LateContext<'_, '_>, expr: &hir::Expr, fold_args:
if bin_op.node == op;

// Extract the names of the two arguments to the closure
if let Some(first_arg_ident) = get_arg_name(&closure_body.arguments[0].pat);
if let Some(second_arg_ident) = get_arg_name(&closure_body.arguments[1].pat);
if let Some(first_arg_ident) = get_arg_name(&closure_body.params[0].pat);
if let Some(second_arg_ident) = get_arg_name(&closure_body.params[1].pat);

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

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

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

let trait_def_id = get_trait_def_id(cx, trait_path).expect("trait def id not found");
let trait_def_id = match get_trait_def_id(cx, trait_path) {
Some(did) => did,
None => return false,
};
implements_trait(cx, ty, trait_def_id, &[parent_ty.into()])
}

Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/unnecessary_filter_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub(super) fn lint(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &[hir::Expr

if let hir::ExprKind::Closure(_, _, body_id, ..) = args[1].node {
let body = cx.tcx.hir().body(body_id);
let arg_id = body.arguments[0].pat.hir_id;
let arg_id = body.params[0].pat.hir_id;
let mutates_arg = match mutated_variables(&body.value, cx) {
Some(used_mutably) => used_mutably.contains(&arg_id),
None => true,
Expand Down
6 changes: 6 additions & 0 deletions clippy_lints/src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ declare_clippy_lint! {
/// # let y = String::from("foo");
/// if x.to_owned() == y {}
/// ```
/// Could be written as
/// ```rust
/// # let x = "foo";
/// # let y = String::from("foo");
/// if x == y {}
/// ```
pub CMP_OWNED,
perf,
"creating owned instances for comparing with others, e.g., `x == \"foo\".to_string()`"
Expand Down
Loading

0 comments on commit 0c83325

Please sign in to comment.