Skip to content

Commit 25058c9

Browse files
committed
Merge branch 'master' into 7594/while_let_some_result
2 parents d10171f + 871ad80 commit 25058c9

File tree

258 files changed

+4585
-3687
lines changed

Some content is hidden

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

258 files changed

+4585
-3687
lines changed

.cargo/config

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
[alias]
22
uitest = "test --test compile-test"
3-
dev = "run --target-dir clippy_dev/target --package clippy_dev --bin clippy_dev --manifest-path clippy_dev/Cargo.toml --"
4-
lintcheck = "run --target-dir lintcheck/target --package lintcheck --bin lintcheck --manifest-path lintcheck/Cargo.toml -- "
3+
dev = "run --package clippy_dev --bin clippy_dev --manifest-path clippy_dev/Cargo.toml --"
4+
lintcheck = "run --package lintcheck --bin lintcheck --manifest-path lintcheck/Cargo.toml -- "
55
collect-metadata = "test --test dogfood --features metadata-collector-lint -- run_metadata_collection_lint --ignored"
66

77
[build]
8-
rustflags = ["-Zunstable-options"]
8+
# -Zbinary-dep-depinfo allows us to track which rlib files to use for compiling UI tests
9+
rustflags = ["-Zunstable-options", "-Zbinary-dep-depinfo"]
10+
target-dir = "target"

.github/ISSUE_TEMPLATE/blank_issue.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ about: Create a blank issue.
55

66

77
<!--
8-
Additional labels can be added to this issue by including the following command:
8+
Additional labels can be added to this issue by including the following command
9+
(without the space after the @ symbol):
910
10-
@rustbot label +<label>
11+
@ rustbot label +<label>
1112
1213
Common labels for this issue type are:
1314
* C-an-interesting-project

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ LLVM version: 10.0
3333
```
3434

3535
<!--
36-
Additional labels can be added to this issue by including the following command:
36+
Additional labels can be added to this issue by including the following command
37+
(without the space after the @ symbol):
3738
38-
@rustbot label +<label>
39+
@ rustbot label +<label>
3940
4041
Common labels for this issue type are:
4142
* `I-suggestion-causes-error`

.github/ISSUE_TEMPLATE/false_positive.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ LLVM version: 10.0
3434
```
3535

3636
<!--
37-
Additional labels can be added to this issue by including the following command:
37+
Additional labels can be added to this issue by including the following command
38+
(without the space after the @ symbol):
3839
39-
@rustbot label +<label>
40+
@ rustbot label +<label>
4041
4142
Common labels for this issue type are:
4243
* I-suggestion-causes-error

CHANGELOG.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ Released 2020-11-19
968968
[#5907](https://github.com/rust-lang/rust-clippy/pull/5907)
969969
* [`suspicious_arithmetic_impl`]: extend to implementations of `BitAnd`, `BitOr`, `BitXor`, `Rem`, `Shl`, and `Shr`
970970
[#5884](https://github.com/rust-lang/rust-clippy/pull/5884)
971-
* [`invalid_atomic_ordering`]: detect misuse of `compare_exchange`, `compare_exchange_weak`, and `fetch_update`
971+
* `invalid_atomic_ordering`: detect misuse of `compare_exchange`, `compare_exchange_weak`, and `fetch_update`
972972
[#6025](https://github.com/rust-lang/rust-clippy/pull/6025)
973973
* Avoid [`redundant_pattern_matching`] triggering in macros
974974
[#6069](https://github.com/rust-lang/rust-clippy/pull/6069)
@@ -1455,7 +1455,7 @@ Released 2020-03-12
14551455
* [`option_as_ref_deref`] [#4945](https://github.com/rust-lang/rust-clippy/pull/4945)
14561456
* [`wildcard_in_or_patterns`] [#4960](https://github.com/rust-lang/rust-clippy/pull/4960)
14571457
* [`iter_nth_zero`] [#4966](https://github.com/rust-lang/rust-clippy/pull/4966)
1458-
* [`invalid_atomic_ordering`] [#4999](https://github.com/rust-lang/rust-clippy/pull/4999)
1458+
* `invalid_atomic_ordering` [#4999](https://github.com/rust-lang/rust-clippy/pull/4999)
14591459
* [`skip_while_next`] [#5067](https://github.com/rust-lang/rust-clippy/pull/5067)
14601460

14611461
### Moves and Deprecations
@@ -2617,6 +2617,7 @@ Released 2018-09-13
26172617
[`deprecated_cfg_attr`]: https://rust-lang.github.io/rust-clippy/master/index.html#deprecated_cfg_attr
26182618
[`deprecated_semver`]: https://rust-lang.github.io/rust-clippy/master/index.html#deprecated_semver
26192619
[`deref_addrof`]: https://rust-lang.github.io/rust-clippy/master/index.html#deref_addrof
2620+
[`derivable_impls`]: https://rust-lang.github.io/rust-clippy/master/index.html#derivable_impls
26202621
[`derive_hash_xor_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_hash_xor_eq
26212622
[`derive_ord_xor_partial_ord`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_ord_xor_partial_ord
26222623
[`disallowed_method`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_method
@@ -2715,7 +2716,6 @@ Released 2018-09-13
27152716
[`integer_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#integer_arithmetic
27162717
[`integer_division`]: https://rust-lang.github.io/rust-clippy/master/index.html#integer_division
27172718
[`into_iter_on_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_on_ref
2718-
[`invalid_atomic_ordering`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_atomic_ordering
27192719
[`invalid_null_ptr_usage`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_null_ptr_usage
27202720
[`invalid_regex`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_regex
27212721
[`invalid_upcast_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_upcast_comparisons
@@ -2725,6 +2725,7 @@ Released 2018-09-13
27252725
[`iter_count`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_count
27262726
[`iter_next_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_next_loop
27272727
[`iter_next_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_next_slice
2728+
[`iter_not_returning_iterator`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_not_returning_iterator
27282729
[`iter_nth`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_nth
27292730
[`iter_nth_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_nth_zero
27302731
[`iter_skip_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_skip_next
@@ -2827,6 +2828,7 @@ Released 2018-09-13
28272828
[`needless_doctest_main`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_doctest_main
28282829
[`needless_for_each`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_for_each
28292830
[`needless_lifetimes`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
2831+
[`needless_option_as_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_option_as_deref
28302832
[`needless_pass_by_value`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_value
28312833
[`needless_question_mark`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_question_mark
28322834
[`needless_range_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_range_loop
@@ -2908,6 +2910,7 @@ Released 2018-09-13
29082910
[`reversed_empty_ranges`]: https://rust-lang.github.io/rust-clippy/master/index.html#reversed_empty_ranges
29092911
[`same_functions_in_if_condition`]: https://rust-lang.github.io/rust-clippy/master/index.html#same_functions_in_if_condition
29102912
[`same_item_push`]: https://rust-lang.github.io/rust-clippy/master/index.html#same_item_push
2913+
[`same_name_method`]: https://rust-lang.github.io/rust-clippy/master/index.html#same_name_method
29112914
[`search_is_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#search_is_some
29122915
[`self_assignment`]: https://rust-lang.github.io/rust-clippy/master/index.html#self_assignment
29132916
[`self_named_constructors`]: https://rust-lang.github.io/rust-clippy/master/index.html#self_named_constructors

Cargo.toml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy"
3-
version = "0.1.56"
3+
version = "0.1.57"
44
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
55
repository = "https://github.com/rust-lang/rust-clippy"
66
readme = "README.md"
@@ -32,11 +32,7 @@ tempfile = { version = "3.1.0", optional = true }
3232
cargo_metadata = "0.12"
3333
compiletest_rs = { version = "0.6.0", features = ["tmp"] }
3434
tester = "0.9"
35-
serde = { version = "1.0", features = ["derive"] }
36-
derive-new = "0.5"
3735
regex = "1.4"
38-
quote = "1"
39-
syn = { version = "1", features = ["full"] }
4036
# This is used by the `collect-metadata` alias.
4137
filetime = "0.2"
4238

@@ -45,6 +41,15 @@ filetime = "0.2"
4541
# for more information.
4642
rustc-workspace-hack = "1.0.0"
4743

44+
# UI test dependencies
45+
clippy_utils = { path = "clippy_utils" }
46+
derive-new = "0.5"
47+
if_chain = "1.0"
48+
itertools = "0.10.1"
49+
quote = "1"
50+
serde = { version = "1.0", features = ["derive"] }
51+
syn = { version = "1", features = ["full"] }
52+
4853
[build-dependencies]
4954
rustc_tools_util = { version = "0.2.0", path = "rustc_tools_util" }
5055

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ or in Travis CI.
4545
One way to use Clippy is by installing Clippy through rustup as a cargo
4646
subcommand.
4747

48-
#### Step 1: Install rustup
48+
#### Step 1: Install Rustup
4949

50-
You can install [rustup](https://rustup.rs/) on supported platforms. This will help
50+
You can install [Rustup](https://rustup.rs/) on supported platforms. This will help
5151
us install Clippy and its dependencies.
5252

53-
If you already have rustup installed, update to ensure you have the latest
54-
rustup and compiler:
53+
If you already have Rustup installed, update to ensure you have the latest
54+
Rustup and compiler:
5555

5656
```terminal
5757
rustup update

clippy_dev/src/bless.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! `bless` updates the reference files in the repo with changed output files
22
//! from the last test run.
33
4-
use std::env;
54
use std::ffi::OsStr;
65
use std::fs;
76
use std::lazy::SyncLazy;
@@ -10,17 +9,9 @@ use walkdir::WalkDir;
109

1110
use crate::clippy_project_root;
1211

13-
// NOTE: this is duplicated with tests/cargo/mod.rs What to do?
14-
pub static CARGO_TARGET_DIR: SyncLazy<PathBuf> = SyncLazy::new(|| match env::var_os("CARGO_TARGET_DIR") {
15-
Some(v) => v.into(),
16-
None => env::current_dir().unwrap().join("target"),
17-
});
18-
1912
static CLIPPY_BUILD_TIME: SyncLazy<Option<std::time::SystemTime>> = SyncLazy::new(|| {
20-
let profile = env::var("PROFILE").unwrap_or_else(|_| "debug".to_string());
21-
let mut path = PathBuf::from(&**CARGO_TARGET_DIR);
22-
path.push(profile);
23-
path.push("cargo-clippy");
13+
let mut path = std::env::current_exe().unwrap();
14+
path.set_file_name("cargo-clippy");
2415
fs::metadata(path).ok()?.modified().ok()
2516
});
2617

@@ -94,10 +85,7 @@ fn updated_since_clippy_build(path: &Path) -> Option<bool> {
9485
}
9586

9687
fn build_dir() -> PathBuf {
97-
let profile = env::var("PROFILE").unwrap_or_else(|_| "debug".to_string());
98-
let mut path = PathBuf::new();
99-
path.push(CARGO_TARGET_DIR.clone());
100-
path.push(profile);
101-
path.push("test_build_base");
88+
let mut path = std::env::current_exe().unwrap();
89+
path.set_file_name("test");
10290
path
10391
}

clippy_lints/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
[package]
22
name = "clippy_lints"
3-
# begin automatic update
4-
version = "0.1.56"
5-
# end automatic update
3+
version = "0.1.57"
64
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
75
repository = "https://github.com/rust-lang/rust-clippy"
86
readme = "README.md"

clippy_lints/src/approx_const.rs

Lines changed: 70 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
use clippy_utils::diagnostics::span_lint;
1+
use clippy_utils::diagnostics::span_lint_and_help;
2+
use clippy_utils::{meets_msrv, msrvs};
23
use rustc_ast::ast::{FloatTy, LitFloatType, LitKind};
34
use rustc_hir::{Expr, ExprKind};
4-
use rustc_lint::{LateContext, LateLintPass};
5-
use rustc_session::{declare_lint_pass, declare_tool_lint};
5+
use rustc_lint::{LateContext, LateLintPass, LintContext};
6+
use rustc_semver::RustcVersion;
7+
use rustc_session::{declare_tool_lint, impl_lint_pass};
68
use rustc_span::symbol;
79
use std::f64::consts as f64;
810

@@ -36,68 +38,82 @@ declare_clippy_lint! {
3638
"the approximate of a known float constant (in `std::fXX::consts`)"
3739
}
3840

39-
// Tuples are of the form (constant, name, min_digits)
40-
const KNOWN_CONSTS: [(f64, &str, usize); 18] = [
41-
(f64::E, "E", 4),
42-
(f64::FRAC_1_PI, "FRAC_1_PI", 4),
43-
(f64::FRAC_1_SQRT_2, "FRAC_1_SQRT_2", 5),
44-
(f64::FRAC_2_PI, "FRAC_2_PI", 5),
45-
(f64::FRAC_2_SQRT_PI, "FRAC_2_SQRT_PI", 5),
46-
(f64::FRAC_PI_2, "FRAC_PI_2", 5),
47-
(f64::FRAC_PI_3, "FRAC_PI_3", 5),
48-
(f64::FRAC_PI_4, "FRAC_PI_4", 5),
49-
(f64::FRAC_PI_6, "FRAC_PI_6", 5),
50-
(f64::FRAC_PI_8, "FRAC_PI_8", 5),
51-
(f64::LN_10, "LN_10", 5),
52-
(f64::LN_2, "LN_2", 5),
53-
(f64::LOG10_E, "LOG10_E", 5),
54-
(f64::LOG2_E, "LOG2_E", 5),
55-
(f64::LOG2_10, "LOG2_10", 5),
56-
(f64::LOG10_2, "LOG10_2", 5),
57-
(f64::PI, "PI", 3),
58-
(f64::SQRT_2, "SQRT_2", 5),
41+
// Tuples are of the form (constant, name, min_digits, msrv)
42+
const KNOWN_CONSTS: [(f64, &str, usize, Option<RustcVersion>); 19] = [
43+
(f64::E, "E", 4, None),
44+
(f64::FRAC_1_PI, "FRAC_1_PI", 4, None),
45+
(f64::FRAC_1_SQRT_2, "FRAC_1_SQRT_2", 5, None),
46+
(f64::FRAC_2_PI, "FRAC_2_PI", 5, None),
47+
(f64::FRAC_2_SQRT_PI, "FRAC_2_SQRT_PI", 5, None),
48+
(f64::FRAC_PI_2, "FRAC_PI_2", 5, None),
49+
(f64::FRAC_PI_3, "FRAC_PI_3", 5, None),
50+
(f64::FRAC_PI_4, "FRAC_PI_4", 5, None),
51+
(f64::FRAC_PI_6, "FRAC_PI_6", 5, None),
52+
(f64::FRAC_PI_8, "FRAC_PI_8", 5, None),
53+
(f64::LN_2, "LN_2", 5, None),
54+
(f64::LN_10, "LN_10", 5, None),
55+
(f64::LOG2_10, "LOG2_10", 5, Some(msrvs::LOG2_10)),
56+
(f64::LOG2_E, "LOG2_E", 5, None),
57+
(f64::LOG10_2, "LOG10_2", 5, Some(msrvs::LOG10_2)),
58+
(f64::LOG10_E, "LOG10_E", 5, None),
59+
(f64::PI, "PI", 3, None),
60+
(f64::SQRT_2, "SQRT_2", 5, None),
61+
(f64::TAU, "TAU", 3, Some(msrvs::TAU)),
5962
];
6063

61-
declare_lint_pass!(ApproxConstant => [APPROX_CONSTANT]);
64+
pub struct ApproxConstant {
65+
msrv: Option<RustcVersion>,
66+
}
6267

63-
impl<'tcx> LateLintPass<'tcx> for ApproxConstant {
64-
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
65-
if let ExprKind::Lit(lit) = &e.kind {
66-
check_lit(cx, &lit.node, e);
68+
impl ApproxConstant {
69+
#[must_use]
70+
pub fn new(msrv: Option<RustcVersion>) -> Self {
71+
Self { msrv }
72+
}
73+
74+
fn check_lit(&self, cx: &LateContext<'_>, lit: &LitKind, e: &Expr<'_>) {
75+
match *lit {
76+
LitKind::Float(s, LitFloatType::Suffixed(fty)) => match fty {
77+
FloatTy::F32 => self.check_known_consts(cx, e, s, "f32"),
78+
FloatTy::F64 => self.check_known_consts(cx, e, s, "f64"),
79+
},
80+
LitKind::Float(s, LitFloatType::Unsuffixed) => self.check_known_consts(cx, e, s, "f{32, 64}"),
81+
_ => (),
6782
}
6883
}
69-
}
7084

71-
fn check_lit(cx: &LateContext<'_>, lit: &LitKind, e: &Expr<'_>) {
72-
match *lit {
73-
LitKind::Float(s, LitFloatType::Suffixed(fty)) => match fty {
74-
FloatTy::F32 => check_known_consts(cx, e, s, "f32"),
75-
FloatTy::F64 => check_known_consts(cx, e, s, "f64"),
76-
},
77-
LitKind::Float(s, LitFloatType::Unsuffixed) => check_known_consts(cx, e, s, "f{32, 64}"),
78-
_ => (),
85+
fn check_known_consts(&self, cx: &LateContext<'_>, e: &Expr<'_>, s: symbol::Symbol, module: &str) {
86+
let s = s.as_str();
87+
if s.parse::<f64>().is_ok() {
88+
for &(constant, name, min_digits, msrv) in &KNOWN_CONSTS {
89+
if is_approx_const(constant, &s, min_digits)
90+
&& msrv.as_ref().map_or(true, |msrv| meets_msrv(self.msrv.as_ref(), msrv))
91+
{
92+
span_lint_and_help(
93+
cx,
94+
APPROX_CONSTANT,
95+
e.span,
96+
&format!("approximate value of `{}::consts::{}` found", module, &name),
97+
None,
98+
"consider using the constant directly",
99+
);
100+
return;
101+
}
102+
}
103+
}
79104
}
80105
}
81106

82-
fn check_known_consts(cx: &LateContext<'_>, e: &Expr<'_>, s: symbol::Symbol, module: &str) {
83-
let s = s.as_str();
84-
if s.parse::<f64>().is_ok() {
85-
for &(constant, name, min_digits) in &KNOWN_CONSTS {
86-
if is_approx_const(constant, &s, min_digits) {
87-
span_lint(
88-
cx,
89-
APPROX_CONSTANT,
90-
e.span,
91-
&format!(
92-
"approximate value of `{}::consts::{}` found. \
93-
Consider using it directly",
94-
module, &name
95-
),
96-
);
97-
return;
98-
}
107+
impl_lint_pass!(ApproxConstant => [APPROX_CONSTANT]);
108+
109+
impl<'tcx> LateLintPass<'tcx> for ApproxConstant {
110+
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
111+
if let ExprKind::Lit(lit) = &e.kind {
112+
self.check_lit(cx, &lit.node, e);
99113
}
100114
}
115+
116+
extract_msrv_attr!(LateContext);
101117
}
102118

103119
/// Returns `false` if the number of significant figures in `value` are

clippy_lints/src/assertions_on_constants.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use clippy_utils::consts::{constant, Constant};
22
use clippy_utils::diagnostics::span_lint_and_help;
3+
use clippy_utils::higher;
34
use clippy_utils::source::snippet_opt;
45
use clippy_utils::{is_direct_expn_of, is_expn_of, match_panic_call};
56
use if_chain::if_chain;
@@ -116,7 +117,7 @@ enum AssertKind {
116117
/// where `message` is any expression and `c` is a constant bool.
117118
fn match_assert_with_message<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<AssertKind> {
118119
if_chain! {
119-
if let ExprKind::If(cond, then, _) = expr.kind;
120+
if let Some(higher::If { cond, then, .. }) = higher::If::hir(expr);
120121
if let ExprKind::Unary(UnOp::Not, expr) = cond.kind;
121122
// bind the first argument of the `assert!` macro
122123
if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.typeck_results(), expr);

0 commit comments

Comments
 (0)