Skip to content

Commit b1f0e01

Browse files
committed
Merge branch 'master' into unit-arg
2 parents f3ccbef + c88c614 commit b1f0e01

File tree

68 files changed

+1434
-273
lines changed

Some content is hidden

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

68 files changed

+1434
-273
lines changed

.cargo/config

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[alias]
22
uitest = "test --test compile-test"
3-
dev = "run --package clippy_dev --bin clippy_dev --manifest-path clippy_dev/Cargo.toml --"
3+
dev = "run --target-dir clippy_dev/target --package clippy_dev --bin clippy_dev --manifest-path clippy_dev/Cargo.toml --"
44

55
[build]
66
rustflags = ["-Zunstable-options"]

.github/workflows/clippy.yml

+7
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ jobs:
9292
env:
9393
OS: ${{ runner.os }}
9494

95+
- name: Test cargo dev new lint
96+
run: |
97+
cargo dev new_lint --name new_early_pass --pass early
98+
cargo dev new_lint --name new_late_pass --pass late
99+
cargo check
100+
git reset --hard HEAD
101+
95102
# Cleanup
96103
- name: Run cargo-cache --autoclean
97104
run: |

CHANGELOG.md

+107-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,113 @@ document.
66

77
## Unreleased / In Rust Nightly
88

9-
[c2c07fa...master](https://github.com/rust-lang/rust-clippy/compare/c2c07fa...master)
9+
[09bd400...master](https://github.com/rust-lang/rust-clippy/compare/09bd400...master)
10+
11+
## Rust 1.47
12+
13+
Current beta, release 2020-10-08
14+
15+
[c2c07fa...09bd400](https://github.com/rust-lang/rust-clippy/compare/c2c07fa...09bd400)
16+
17+
### New lints
18+
19+
* [`derive_ord_xor_partial_ord`] [#5848](https://github.com/rust-lang/rust-clippy/pull/5848)
20+
* [`trait_duplication_in_bounds`] [#5852](https://github.com/rust-lang/rust-clippy/pull/5852)
21+
* [`map_identity`] [#5694](https://github.com/rust-lang/rust-clippy/pull/5694)
22+
* [`unit_return_expecting_ord`] [#5737](https://github.com/rust-lang/rust-clippy/pull/5737)
23+
* [`pattern_type_mismatch`] [#4841](https://github.com/rust-lang/rust-clippy/pull/4841)
24+
* [`repeat_once`] [#5773](https://github.com/rust-lang/rust-clippy/pull/5773)
25+
* [`same_item_push`] [#5825](https://github.com/rust-lang/rust-clippy/pull/5825)
26+
* [`needless_arbitrary_self_type`] [#5869](https://github.com/rust-lang/rust-clippy/pull/5869)
27+
* [`match_like_matches_macro`] [#5769](https://github.com/rust-lang/rust-clippy/pull/5769)
28+
* [`stable_sort_primitive`] [#5809](https://github.com/rust-lang/rust-clippy/pull/5809)
29+
* [`blanket_clippy_restriction_lints`] [#5750](https://github.com/rust-lang/rust-clippy/pull/5750)
30+
* [`option_if_let_else`] [#5301](https://github.com/rust-lang/rust-clippy/pull/5301)
31+
32+
### Moves and Deprecations
33+
34+
* Deprecate [`regex_macro`] lint
35+
[#5760](https://github.com/rust-lang/rust-clippy/pull/5760)
36+
* Move [`range_minus_one`] to `pedantic`
37+
[#5752](https://github.com/rust-lang/rust-clippy/pull/5752)
38+
39+
### Enhancements
40+
41+
* Improve [`needless_collect`] by catching `collect` calls followed by `iter` or `into_iter` calls
42+
[#5837](https://github.com/rust-lang/rust-clippy/pull/5837)
43+
* [`panic`], [`todo`], [`unimplemented`] and [`unreachable`] now detect calls with formatting
44+
[#5811](https://github.com/rust-lang/rust-clippy/pull/5811)
45+
* Detect more cases of [`suboptimal_flops`] and [`imprecise_flops`]
46+
[#5443](https://github.com/rust-lang/rust-clippy/pull/5443)
47+
* Handle asymmetrical implementations of `PartialEq` in [`cmp_owned`]
48+
[#5701](https://github.com/rust-lang/rust-clippy/pull/5701)
49+
* Make it possible to allow [`unsafe_derive_deserialize`]
50+
[#5870](https://github.com/rust-lang/rust-clippy/pull/5870)
51+
* Catch `ord.min(a).max(b)` where a < b in [`min_max`]
52+
[#5871](https://github.com/rust-lang/rust-clippy/pull/5871)
53+
* Make [`clone_on_copy`] suggestion machine applicable
54+
[#5745](https://github.com/rust-lang/rust-clippy/pull/5745)
55+
* Enable [`len_zero`] on ranges now that `is_empty` is stable on them
56+
[#5961](https://github.com/rust-lang/rust-clippy/pull/5961)
57+
58+
### False Positive Fixes
59+
60+
* Avoid triggering [`or_fun_call`] with const fns that take no arguments
61+
[#5889](https://github.com/rust-lang/rust-clippy/pull/5889)
62+
* Fix [`redundant_closure_call`] false positive for closures that have multiple calls
63+
[#5800](https://github.com/rust-lang/rust-clippy/pull/5800)
64+
* Don't lint cases involving `ManuallyDrop` in [`redundant_clone`]
65+
[#5824](https://github.com/rust-lang/rust-clippy/pull/5824)
66+
* Treat a single expression the same as a single statement in the 2nd arm of a match in [`single_match_else`]
67+
[#5771](https://github.com/rust-lang/rust-clippy/pull/5771)
68+
* Don't trigger [`unnested_or_patterns`] if the feature `or_patterns` is not enabled
69+
[#5758](https://github.com/rust-lang/rust-clippy/pull/5758)
70+
* Avoid linting if key borrows in [`unnecessary_sort_by`]
71+
[#5756](https://github.com/rust-lang/rust-clippy/pull/5756)
72+
* Consider `Try` impl for `Poll` when generating suggestions in [`try_err`]
73+
[#5857](https://github.com/rust-lang/rust-clippy/pull/5857)
74+
* Take input lifetimes into account in `manual_async_fn`
75+
[#5859](https://github.com/rust-lang/rust-clippy/pull/5859)
76+
* Fix multiple false positives in [`type_repetition_in_bounds`] and add a configuration option
77+
[#5761](https://github.com/rust-lang/rust-clippy/pull/5761)
78+
* Limit the [`suspicious_arithmetic_impl`] lint to one binary operation
79+
[#5820](https://github.com/rust-lang/rust-clippy/pull/5820)
80+
81+
### Suggestion Fixes/Improvements
82+
83+
* Improve readability of [`shadow_unrelated`] suggestion by truncating the RHS snippet
84+
[#5788](https://github.com/rust-lang/rust-clippy/pull/5788)
85+
* Suggest `filter_map` instead of `flat_map` when mapping to `Option` in [`map_flatten`]
86+
[#5846](https://github.com/rust-lang/rust-clippy/pull/5846)
87+
* Ensure suggestion is shown correctly for long method call chains in [`iter_nth_zero`]
88+
[#5793](https://github.com/rust-lang/rust-clippy/pull/5793)
89+
* Drop borrow operator in suggestions of [`redundant_pattern_matching`]
90+
[#5815](https://github.com/rust-lang/rust-clippy/pull/5815)
91+
* Add suggestion for [`iter_skip_next`]
92+
[#5843](https://github.com/rust-lang/rust-clippy/pull/5843)
93+
* Improve [`collapsible_if`] fix suggestion
94+
[#5732](https://github.com/rust-lang/rust-clippy/pull/5732)
95+
96+
### ICE Fixes
97+
98+
* Fix ICE caused by [`needless_collect`]
99+
[#5877](https://github.com/rust-lang/rust-clippy/pull/5877)
100+
* Fix ICE caused by [`unnested_or_patterns`]
101+
[#5784](https://github.com/rust-lang/rust-clippy/pull/5784)
102+
103+
### Documentation Improvements
104+
105+
* Fix grammar of [`await_holding_lock`] documentation
106+
[#5748](https://github.com/rust-lang/rust-clippy/pull/5748)
107+
108+
### Others
109+
110+
* Make lints adhere to the rustc dev guide
111+
[#5888](https://github.com/rust-lang/rust-clippy/pull/5888)
10112

11113
## Rust 1.46
12114

13-
Current beta, release 2020-08-27
115+
Current stable, released 2020-08-27
14116

15117
[7ea7cd1...c2c07fa](https://github.com/rust-lang/rust-clippy/compare/7ea7cd1...c2c07fa)
16118

@@ -72,7 +174,7 @@ Current beta, release 2020-08-27
72174

73175
## Rust 1.45
74176

75-
Current stable, released 2020-07-16
177+
Released 2020-07-16
76178

77179
[891e1a8...7ea7cd1](https://github.com/rust-lang/rust-clippy/compare/891e1a8...7ea7cd1)
78180

@@ -1498,6 +1600,7 @@ Released 2018-09-13
14981600
[`float_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#float_arithmetic
14991601
[`float_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#float_cmp
15001602
[`float_cmp_const`]: https://rust-lang.github.io/rust-clippy/master/index.html#float_cmp_const
1603+
[`float_equality_without_abs`]: https://rust-lang.github.io/rust-clippy/master/index.html#float_equality_without_abs
15011604
[`fn_address_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#fn_address_comparisons
15021605
[`fn_params_excessive_bools`]: https://rust-lang.github.io/rust-clippy/master/index.html#fn_params_excessive_bools
15031606
[`fn_to_numeric_cast`]: https://rust-lang.github.io/rust-clippy/master/index.html#fn_to_numeric_cast
@@ -1777,6 +1880,7 @@ Released 2018-09-13
17771880
[`unused_label`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_label
17781881
[`unused_self`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_self
17791882
[`unused_unit`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_unit
1883+
[`unwrap_in_result`]: https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_in_result
17801884
[`unwrap_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_used
17811885
[`use_debug`]: https://rust-lang.github.io/rust-clippy/master/index.html#use_debug
17821886
[`use_self`]: https://rust-lang.github.io/rust-clippy/master/index.html#use_self

CONTRIBUTING.md

+49-9
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,35 @@ Clippy in the `rust-lang/rust` repository.
189189
For general information about `subtree`s in the Rust repository see [Rust's
190190
`CONTRIBUTING.md`][subtree].
191191

192+
### Patching git-subtree to work with big repos
193+
194+
Currently there's a bug in `git-subtree` that prevents it from working properly
195+
with the [`rust-lang/rust`] repo. There's an open PR to fix that, but it's stale.
196+
Before continuing with the following steps, we need to manually apply that fix to
197+
our local copy of `git-subtree`.
198+
199+
You can get the patched version of `git-subtree` from [here][gitgitgadget-pr].
200+
Put this file under `/usr/lib/git-core` (taking a backup of the previous file)
201+
and make sure it has the proper permissions:
202+
203+
```bash
204+
sudo cp --backup /path/to/patched/git-subtree.sh /usr/lib/git-core/git-subtree
205+
sudo chmod --reference=/usr/lib/git-core/git-subtree~ /usr/lib/git-core/git-subtree
206+
sudo chown --reference=/usr/lib/git-core/git-subtree~ /usr/lib/git-core/git-subtree
207+
```
208+
209+
_Note:_ The first time running `git subtree push` a cache has to be built. This
210+
involves going through the complete Clippy history once. For this you have to
211+
increase the stack limit though, which you can do with `ulimit -s 60000`.
212+
Make sure to run the `ulimit` command from the same session you call git subtree.
213+
214+
_Note:_ If you are a Debian user, `dash` is the shell used by default for scripts instead of `sh`.
215+
This shell has a hardcoded recursion limit set to 1000. In order to make this process work,
216+
you need to force the script to run `bash` instead. You can do this by editing the first
217+
line of the `git-subtree` script and changing `sh` to `bash`.
218+
219+
### Performing the sync
220+
192221
Here is a TL;DR version of the sync process (all of the following commands have
193222
to be run inside the `rust` directory):
194223

@@ -198,6 +227,7 @@ to be run inside the `rust` directory):
198227
# Make sure to change `your-github-name` to your github name in the following command
199228
git subtree push -P src/tools/clippy [email protected]:your-github-name/rust-clippy sync-from-rust
200229
```
230+
201231
_Note:_ This will directly push to the remote repository. You can also push
202232
to your local copy by replacing the remote address with `/path/to/rust-clippy`
203233
directory.
@@ -213,14 +243,30 @@ to be run inside the `rust` directory):
213243
3. Open a PR to `rust-lang/rust-clippy` and wait for it to get merged (to
214244
accelerate the process ping the `@rust-lang/clippy` team in your PR and/or
215245
~~annoy~~ ask them in the [Discord] channel.)
216-
4. Sync the `rust-lang/rust-clippy` master to the rust-copy of Clippy:
246+
247+
### Syncing back changes in Clippy to [`rust-lang/rust`]
248+
249+
To avoid flooding the [`rust-lang/rust`] PR queue, changes in Clippy's repo are synced back
250+
in a bi-weekly basis if there's no urgent changes. This is done starting on the day of
251+
the Rust stable release and then every other week. That way we guarantee that
252+
every feature in Clippy is available for 2 weeks in nightly, before it can get to beta.
253+
For reference, the first sync following this cadence was performed the 2020-08-27.
254+
255+
All of the following commands have to be run inside the `rust` directory.
256+
257+
1. Make sure Clippy itself is up-to-date by following the steps outlined in the previous
258+
section if necessary.
259+
260+
2. Sync the `rust-lang/rust-clippy` master to the rust-copy of Clippy:
217261
```bash
218262
git checkout -b sync-from-clippy
219263
git subtree pull -P src/tools/clippy https://github.com/rust-lang/rust-clippy master
220264
```
221-
5. Open a PR to [`rust-lang/rust`]
265+
3. Open a PR to [`rust-lang/rust`]
266+
267+
### Defining remotes
222268

223-
Also, you may want to define remotes, so you don't have to type out the remote
269+
You may want to define remotes, so you don't have to type out the remote
224270
addresses on every sync. You can do this with the following commands (these
225271
commands still have to be run inside the `rust` directory):
226272
@@ -241,12 +287,6 @@ You can then sync with the remote names from above, e.g.:
241287
$ git subtree push -P src/tools/clippy clippy-local sync-from-rust
242288
```
243289
244-
_Note:_ The first time running `git subtree push` a cache has to be built. This
245-
involves going through the complete Clippy history once. For this you have to
246-
increase the stack limit though, which you can do with `ulimit -s 60000`. For
247-
this to work, you will need the fix of `git subtree` available
248-
[here][gitgitgadget-pr].
249-
250290
[gitgitgadget-pr]: https://github.com/gitgitgadget/git/pull/493
251291
[subtree]: https://rustc-dev-guide.rust-lang.org/contributing.html#external-dependencies-subtree
252292
[`rust-lang/rust`]: https://github.com/rust-lang/rust

clippy_dev/src/new_lint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub fn create(pass: Option<&str>, lint_name: Option<&str>, category: Option<&str
4747
fn create_lint(lint: &LintData) -> io::Result<()> {
4848
let (pass_type, pass_lifetimes, pass_import, context_import) = match lint.pass {
4949
"early" => ("EarlyLintPass", "", "use rustc_ast::ast::*;", "EarlyContext"),
50-
"late" => ("LateLintPass", "<'_, '_>", "use rustc_hir::*;", "LateContext"),
50+
"late" => ("LateLintPass", "<'_>", "use rustc_hir::*;", "LateContext"),
5151
_ => {
5252
unreachable!("`pass_type` should only ever be `early` or `late`!");
5353
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
use crate::utils::{match_qpath, paths, span_lint_and_then, sugg};
2+
use if_chain::if_chain;
3+
use rustc_ast::util::parser::AssocOp;
4+
use rustc_errors::Applicability;
5+
use rustc_hir::{BinOpKind, Expr, ExprKind};
6+
use rustc_lint::{LateContext, LateLintPass};
7+
use rustc_middle::ty;
8+
use rustc_session::{declare_lint_pass, declare_tool_lint};
9+
use rustc_span::source_map::Spanned;
10+
11+
declare_clippy_lint! {
12+
/// **What it does:** Checks for statements of the form `(a - b) < f32::EPSILON` or
13+
/// `(a - b) < f64::EPSILON`. Notes the missing `.abs()`.
14+
///
15+
/// **Why is this bad?** The code without `.abs()` is more likely to have a bug.
16+
///
17+
/// **Known problems:** If the user can ensure that b is larger than a, the `.abs()` is
18+
/// technically unneccessary. However, it will make the code more robust and doesn't have any
19+
/// large performance implications. If the abs call was deliberately left out for performance
20+
/// reasons, it is probably better to state this explicitly in the code, which then can be done
21+
/// with an allow.
22+
///
23+
/// **Example:**
24+
///
25+
/// ```rust
26+
/// pub fn is_roughly_equal(a: f32, b: f32) -> bool {
27+
/// (a - b) < f32::EPSILON
28+
/// }
29+
/// ```
30+
/// Use instead:
31+
/// ```rust
32+
/// pub fn is_roughly_equal(a: f32, b: f32) -> bool {
33+
/// (a - b).abs() < f32::EPSILON
34+
/// }
35+
/// ```
36+
pub FLOAT_EQUALITY_WITHOUT_ABS,
37+
correctness,
38+
"float equality check without `.abs()`"
39+
}
40+
41+
declare_lint_pass!(FloatEqualityWithoutAbs => [FLOAT_EQUALITY_WITHOUT_ABS]);
42+
43+
impl<'tcx> LateLintPass<'tcx> for FloatEqualityWithoutAbs {
44+
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
45+
let lhs;
46+
let rhs;
47+
48+
// check if expr is a binary expression with a lt or gt operator
49+
if let ExprKind::Binary(op, ref left, ref right) = expr.kind {
50+
match op.node {
51+
BinOpKind::Lt => {
52+
lhs = left;
53+
rhs = right;
54+
},
55+
BinOpKind::Gt => {
56+
lhs = right;
57+
rhs = left;
58+
},
59+
_ => return,
60+
};
61+
} else {
62+
return;
63+
}
64+
65+
if_chain! {
66+
67+
// left hand side is a substraction
68+
if let ExprKind::Binary(
69+
Spanned {
70+
node: BinOpKind::Sub,
71+
..
72+
},
73+
val_l,
74+
val_r,
75+
) = lhs.kind;
76+
77+
// right hand side matches either f32::EPSILON or f64::EPSILON
78+
if let ExprKind::Path(ref epsilon_path) = rhs.kind;
79+
if match_qpath(epsilon_path, &paths::F32_EPSILON) || match_qpath(epsilon_path, &paths::F64_EPSILON);
80+
81+
// values of the substractions on the left hand side are of the type float
82+
let t_val_l = cx.typeck_results().expr_ty(val_l);
83+
let t_val_r = cx.typeck_results().expr_ty(val_r);
84+
if let ty::Float(_) = t_val_l.kind;
85+
if let ty::Float(_) = t_val_r.kind;
86+
87+
then {
88+
let sug_l = sugg::Sugg::hir(cx, &val_l, "..");
89+
let sug_r = sugg::Sugg::hir(cx, &val_r, "..");
90+
// format the suggestion
91+
let suggestion = format!("{}.abs()", sugg::make_assoc(AssocOp::Subtract, &sug_l, &sug_r).maybe_par());
92+
// spans the lint
93+
span_lint_and_then(
94+
cx,
95+
FLOAT_EQUALITY_WITHOUT_ABS,
96+
expr.span,
97+
"float equality check without `.abs()`",
98+
| diag | {
99+
diag.span_suggestion(
100+
lhs.span,
101+
"add `.abs()`",
102+
suggestion,
103+
Applicability::MaybeIncorrect,
104+
);
105+
}
106+
);
107+
}
108+
}
109+
}
110+
}

0 commit comments

Comments
 (0)