Skip to content

Commit 14f7ce1

Browse files
committed
Merge branch 'master' of github.com:rust-lang/rust-clippy
2 parents 6a45414 + 2cc23a5 commit 14f7ce1

File tree

105 files changed

+1544
-1362
lines changed

Some content is hidden

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

105 files changed

+1544
-1362
lines changed

CHANGELOG.md

+28
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,36 @@ All notable changes to this project will be documented in this file.
66

77
[eb9f9b1...master](https://github.com/rust-lang/rust-clippy/compare/eb9f9b1...master)
88

9+
* New lints: [`find_map`], [`filter_map_next`] [#4039](https://github.com/rust-lang/rust-clippy/pull/4039)
10+
* New lint: [`path_buf_push_overwrite`] [#3954](https://github.com/rust-lang/rust-clippy/pull/3954)
11+
* Move `path_buf_push_overwrite` to the nursery [#4013](https://github.com/rust-lang/rust-clippy/pull/4013)
12+
* Split [`redundant_closure`] into [`redundant_closure`] and [`redundant_closure_for_method_calls`] [#4110](https://github.com/rust-lang/rust-clippy/pull/4101)
13+
* Allow allowing of [`toplevel_ref_arg`] lint [#4007](https://github.com/rust-lang/rust-clippy/pull/4007)
14+
* Fix false negative in [`or_fun_call`] pertaining to nested constructors [#4084](https://github.com/rust-lang/rust-clippy/pull/4084)
15+
* Fixed false positive in [`or_fn_call`] pertaining to enum variant constructors [#4018](https://github.com/rust-lang/rust-clippy/pull/4018)
16+
* Fix false positive in [`useless_let_if_seq`] pertaining to interior mutability [#4035](https://github.com/rust-lang/rust-clippy/pull/4035)
17+
* Fix false positive in [`redundant_closure`] pertaining to non-function types [#4008](https://github.com/rust-lang/rust-clippy/pull/4008)
18+
* Fix false positive in [`let_and_return`] pertaining to attributes on `let`s [#4024](https://github.com/rust-lang/rust-clippy/pull/4024)
19+
* Fix false positive in [`module_name_repetitions`] lint pertaining to attributes [#4006](https://github.com/rust-lang/rust-clippy/pull/4006)
20+
* Fix false positive on [`assertions_on_constants`] pertaining to `debug_assert!` [#3989](https://github.com/rust-lang/rust-clippy/pull/3989)
21+
* Improve suggestion in [`map_clone`] to suggest `.copied()` where applicable [#3970](https://github.com/rust-lang/rust-clippy/pull/3970) [#4043](https://github.com/rust-lang/rust-clippy/pull/4043)
22+
* Improve suggestion for [`search_is_some`] [#4049](https://github.com/rust-lang/rust-clippy/pull/4049)
23+
* Improve suggestion applicability for [`naive_bytecount`] [#3984](https://github.com/rust-lang/rust-clippy/pull/3984)
24+
* Improve suggestion applicability for [`while_let_loop`] [#3975](https://github.com/rust-lang/rust-clippy/pull/3975)
25+
* Improve diagnostics for [`too_many_arguments`] [#4053](https://github.com/rust-lang/rust-clippy/pull/4053)
26+
* Improve diagnostics for [`cast_lossless`] [#4021](https://github.com/rust-lang/rust-clippy/pull/4021)
27+
* Deal with macro checks in desugarings better [#4082](https://github.com/rust-lang/rust-clippy/pull/4082)
28+
* Add macro check for [`unnecessary_cast`] [#4026](https://github.com/rust-lang/rust-clippy/pull/4026)
29+
* Remove [`approx_constant`]'s documentation's "Known problems" section. [#4027](https://github.com/rust-lang/rust-clippy/pull/4027)
30+
* Fix ICE in [`suspicious_else_formatting`] [#3960](https://github.com/rust-lang/rust-clippy/pull/3960)
31+
* Fix ICE in [`decimal_literal_representation`] [#3931](https://github.com/rust-lang/rust-clippy/pull/3931)
32+
33+
934
## Rust 1.35 (beta)
1035
[1fac380..37f5c1e](https://github.com/rust-lang/rust-clippy/compare/1fac380...37f5c1e)
1136

1237
* New lint: [`drop_bounds`] to detect `T: Drop` bounds
38+
* Split [`redundant_closure`] into [`redundant_closure`] and [`redundant_closure_for_method_calls`] [#4110](https://github.com/rust-lang/rust-clippy/pull/4101)
1339
* Rename `cyclomatic_complexity` to [`cognitive_complexity`], start work on making lint more practical for Rust code
1440
* Move [`get_unwrap`] to the restriction category
1541
* Improve suggestions for [`iter_cloned_collect`]
@@ -846,6 +872,7 @@ All notable changes to this project will be documented in this file.
846872
[`char_lit_as_u8`]: https://rust-lang.github.io/rust-clippy/master/index.html#char_lit_as_u8
847873
[`chars_last_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#chars_last_cmp
848874
[`chars_next_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#chars_next_cmp
875+
[`checked_conversions`]: https://rust-lang.github.io/rust-clippy/master/index.html#checked_conversions
849876
[`clone_double_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#clone_double_ref
850877
[`clone_on_copy`]: https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy
851878
[`clone_on_ref_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_ref_ptr
@@ -1035,6 +1062,7 @@ All notable changes to this project will be documented in this file.
10351062
[`redundant_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone
10361063
[`redundant_closure`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure
10371064
[`redundant_closure_call`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_call
1065+
[`redundant_closure_for_method_calls`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_for_method_calls
10381066
[`redundant_field_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names
10391067
[`redundant_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern
10401068
[`redundant_pattern_matching`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
99

10-
[There are 301 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
10+
[There are 303 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
1111

1212
We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you:
1313

ci/base-tests.sh

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export CARGO_TARGET_DIR=`pwd`/target/
2323

2424
# Perform various checks for lint registration
2525
./util/dev update_lints --check
26+
./util/dev --limit-stderr-length
2627
cargo +nightly fmt --all -- --check
2728

2829
# Check running clippy-driver without cargo

clippy_dev/src/main.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ extern crate clap;
22
extern crate clippy_dev;
33
extern crate regex;
44

5-
use clap::{App, AppSettings, Arg, SubCommand};
5+
use clap::{App, Arg, SubCommand};
66
use clippy_dev::*;
7+
mod stderr_length_check;
78

89
#[derive(PartialEq)]
910
enum UpdateMode {
@@ -13,7 +14,6 @@ enum UpdateMode {
1314

1415
fn main() {
1516
let matches = App::new("Clippy developer tooling")
16-
.setting(AppSettings::SubcommandRequiredElseHelp)
1717
.subcommand(
1818
SubCommand::with_name("update_lints")
1919
.about("Updates lint registration and information from the source code")
@@ -36,8 +36,16 @@ fn main() {
3636
.help("Checks that util/dev update_lints has been run. Used on CI."),
3737
),
3838
)
39+
.arg(
40+
Arg::with_name("limit-stderr-length")
41+
.long("limit-stderr-length")
42+
.help("Ensures that stderr files do not grow longer than a certain amount of lines."),
43+
)
3944
.get_matches();
4045

46+
if matches.is_present("limit-stderr-length") {
47+
stderr_length_check::check();
48+
}
4149
if let Some(matches) = matches.subcommand_matches("update_lints") {
4250
if matches.is_present("print-only") {
4351
print_lints();

clippy_dev/src/stderr_length_check.rs

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
use std::ffi::OsStr;
2+
use walkdir::WalkDir;
3+
4+
use std::fs::File;
5+
use std::io::prelude::*;
6+
7+
// The maximum length allowed for stderr files.
8+
//
9+
// We limit this because small files are easier to deal with than bigger files.
10+
const LIMIT: usize = 320;
11+
12+
pub fn check() {
13+
let stderr_files = stderr_files();
14+
let exceeding_files = exceeding_stderr_files(stderr_files).collect::<Vec<String>>();
15+
16+
if !exceeding_files.is_empty() {
17+
eprintln!("Error: stderr files exceeding limit of {} lines:", LIMIT);
18+
for path in exceeding_files {
19+
println!("{}", path);
20+
}
21+
std::process::exit(1);
22+
}
23+
}
24+
25+
fn exceeding_stderr_files(files: impl Iterator<Item = walkdir::DirEntry>) -> impl Iterator<Item = String> {
26+
files
27+
.filter_map(|file| {
28+
let path = file.path().to_str().expect("Could not convert path to str").to_string();
29+
let linecount = count_linenumbers(&path);
30+
if linecount > LIMIT {
31+
Some(path)
32+
} else {
33+
None
34+
}
35+
})
36+
}
37+
38+
fn stderr_files() -> impl Iterator<Item = walkdir::DirEntry> {
39+
// We use `WalkDir` instead of `fs::read_dir` here in order to recurse into subdirectories.
40+
WalkDir::new("../tests/ui")
41+
.into_iter()
42+
.filter_map(std::result::Result::ok)
43+
.filter(|f| f.path().extension() == Some(OsStr::new("stderr")))
44+
}
45+
46+
fn count_linenumbers(filepath: &str) -> usize {
47+
if let Ok(mut file) = File::open(filepath) {
48+
let mut content = String::new();
49+
file.read_to_string(&mut content).expect("Failed to read file?");
50+
content.lines().count()
51+
} else {
52+
0
53+
}
54+
}

clippy_lints/src/approx_const.rs

+18-23
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
use crate::utils::span_lint;
2-
use crate::utils::sym;
3-
use lazy_static::lazy_static;
42
use rustc::hir::*;
53
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
64
use rustc::{declare_lint_pass, declare_tool_lint};
75
use std::f64::consts as f64;
86
use syntax::ast::{FloatTy, LitKind};
97
use syntax::symbol;
10-
use syntax::symbol::Symbol;
118

129
declare_clippy_lint! {
1310
/// **What it does:** Checks for floating point literals that approximate
@@ -33,27 +30,25 @@ declare_clippy_lint! {
3330
"the approximate of a known float constant (in `std::fXX::consts`)"
3431
}
3532

36-
lazy_static! {
3733
// Tuples are of the form (constant, name, min_digits)
38-
static ref KNOWN_CONSTS: [(f64, Symbol, usize); 16] = [
39-
(f64::E, *sym::E, 4),
40-
(f64::FRAC_1_PI, *sym::FRAC_1_PI, 4),
41-
(f64::FRAC_1_SQRT_2, *sym::FRAC_1_SQRT_2, 5),
42-
(f64::FRAC_2_PI, *sym::FRAC_2_PI, 5),
43-
(f64::FRAC_2_SQRT_PI, *sym::FRAC_2_SQRT_PI, 5),
44-
(f64::FRAC_PI_2, *sym::FRAC_PI_2, 5),
45-
(f64::FRAC_PI_3, *sym::FRAC_PI_3, 5),
46-
(f64::FRAC_PI_4, *sym::FRAC_PI_4, 5),
47-
(f64::FRAC_PI_6, *sym::FRAC_PI_6, 5),
48-
(f64::FRAC_PI_8, *sym::FRAC_PI_8, 5),
49-
(f64::LN_10, *sym::LN_10, 5),
50-
(f64::LN_2, *sym::LN_2, 5),
51-
(f64::LOG10_E, *sym::LOG10_E, 5),
52-
(f64::LOG2_E, *sym::LOG2_E, 5),
53-
(f64::PI, *sym::PI, 3),
54-
(f64::SQRT_2, *sym::SQRT_2, 5),
34+
const KNOWN_CONSTS: [(f64, &str, usize); 16] = [
35+
(f64::E, "E", 4),
36+
(f64::FRAC_1_PI, "FRAC_1_PI", 4),
37+
(f64::FRAC_1_SQRT_2, "FRAC_1_SQRT_2", 5),
38+
(f64::FRAC_2_PI, "FRAC_2_PI", 5),
39+
(f64::FRAC_2_SQRT_PI, "FRAC_2_SQRT_PI", 5),
40+
(f64::FRAC_PI_2, "FRAC_PI_2", 5),
41+
(f64::FRAC_PI_3, "FRAC_PI_3", 5),
42+
(f64::FRAC_PI_4, "FRAC_PI_4", 5),
43+
(f64::FRAC_PI_6, "FRAC_PI_6", 5),
44+
(f64::FRAC_PI_8, "FRAC_PI_8", 5),
45+
(f64::LN_10, "LN_10", 5),
46+
(f64::LN_2, "LN_2", 5),
47+
(f64::LOG10_E, "LOG10_E", 5),
48+
(f64::LOG2_E, "LOG2_E", 5),
49+
(f64::PI, "PI", 3),
50+
(f64::SQRT_2, "SQRT_2", 5),
5551
];
56-
}
5752

5853
declare_lint_pass!(ApproxConstant => [APPROX_CONSTANT]);
5954

@@ -77,7 +72,7 @@ fn check_lit(cx: &LateContext<'_, '_>, lit: &LitKind, e: &Expr) {
7772
fn check_known_consts(cx: &LateContext<'_, '_>, e: &Expr, s: symbol::Symbol, module: &str) {
7873
let s = s.as_str();
7974
if s.parse::<f64>().is_ok() {
80-
for &(constant, name, min_digits) in KNOWN_CONSTS.iter() {
75+
for &(constant, name, min_digits) in &KNOWN_CONSTS {
8176
if is_approx_const(constant, &s, min_digits) {
8277
span_lint(
8378
cx,

clippy_lints/src/assertions_on_constants.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use rustc::{declare_lint_pass, declare_tool_lint};
55
use syntax_pos::Span;
66

77
use crate::consts::{constant, Constant};
8-
use crate::utils::sym;
98
use crate::utils::{in_macro_or_desugar, is_direct_expn_of, span_help_and_lint};
109

1110
declare_clippy_lint! {
@@ -41,9 +40,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
4140
!in_macro_or_desugar(span)
4241
};
4342
if_chain! {
44-
if let Some(assert_span) = is_direct_expn_of(e.span, *sym::assert);
43+
if let Some(assert_span) = is_direct_expn_of(e.span, "assert");
4544
if !in_macro_or_desugar(assert_span)
46-
|| is_direct_expn_of(assert_span, *sym::debug_assert)
45+
|| is_direct_expn_of(assert_span, "debug_assert")
4746
.map_or(false, debug_assert_not_in_macro_or_desugar);
4847
if let ExprKind::Unary(_, ref lit) = e.node;
4948
if let Some(bool_const) = constant(cx, cx.tables, lit);

clippy_lints/src/assign_ops.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use crate::utils::{
99
get_trait_def_id, implements_trait, snippet_opt, span_lint_and_then, trait_ref_of_method, SpanlessEq,
1010
};
1111
use crate::utils::{higher, sugg};
12-
use syntax::symbol::Symbol;
1312

1413
declare_clippy_lint! {
1514
/// **What it does:** Checks for `a = a op b` or `a = b commutative_op a`
@@ -89,11 +88,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
8988
$($trait_name:ident),+) => {
9089
match $op {
9190
$(hir::BinOpKind::$trait_name => {
92-
let [krate, module] = *crate::utils::paths::OPS_MODULE;
93-
let ident = {
94-
*crate::utils::sym::assign::$trait_name
95-
};
96-
let path: [Symbol; 3] = [krate, module, ident];
91+
let [krate, module] = crate::utils::paths::OPS_MODULE;
92+
let path: [&str; 3] = [krate, module, concat!(stringify!($trait_name), "Assign")];
9793
let trait_id = if let Some(trait_id) = get_trait_def_id($cx, &path) {
9894
trait_id
9995
} else {

0 commit comments

Comments
 (0)