Skip to content

Commit

Permalink
Merged from upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
HarrisonMc555 committed May 20, 2019
2 parents 42e7536 + 14f7ce1 commit a74055b
Show file tree
Hide file tree
Showing 105 changed files with 1,544 additions and 1,362 deletions.
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,36 @@ All notable changes to this project will be documented in this file.

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

* New lints: [`find_map`], [`filter_map_next`] [#4039](https://github.com/rust-lang/rust-clippy/pull/4039)
* New lint: [`path_buf_push_overwrite`] [#3954](https://github.com/rust-lang/rust-clippy/pull/3954)
* Move `path_buf_push_overwrite` to the nursery [#4013](https://github.com/rust-lang/rust-clippy/pull/4013)
* Split [`redundant_closure`] into [`redundant_closure`] and [`redundant_closure_for_method_calls`] [#4110](https://github.com/rust-lang/rust-clippy/pull/4101)
* Allow allowing of [`toplevel_ref_arg`] lint [#4007](https://github.com/rust-lang/rust-clippy/pull/4007)
* Fix false negative in [`or_fun_call`] pertaining to nested constructors [#4084](https://github.com/rust-lang/rust-clippy/pull/4084)
* Fixed false positive in [`or_fn_call`] pertaining to enum variant constructors [#4018](https://github.com/rust-lang/rust-clippy/pull/4018)
* Fix false positive in [`useless_let_if_seq`] pertaining to interior mutability [#4035](https://github.com/rust-lang/rust-clippy/pull/4035)
* Fix false positive in [`redundant_closure`] pertaining to non-function types [#4008](https://github.com/rust-lang/rust-clippy/pull/4008)
* Fix false positive in [`let_and_return`] pertaining to attributes on `let`s [#4024](https://github.com/rust-lang/rust-clippy/pull/4024)
* Fix false positive in [`module_name_repetitions`] lint pertaining to attributes [#4006](https://github.com/rust-lang/rust-clippy/pull/4006)
* Fix false positive on [`assertions_on_constants`] pertaining to `debug_assert!` [#3989](https://github.com/rust-lang/rust-clippy/pull/3989)
* 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)
* Improve suggestion for [`search_is_some`] [#4049](https://github.com/rust-lang/rust-clippy/pull/4049)
* Improve suggestion applicability for [`naive_bytecount`] [#3984](https://github.com/rust-lang/rust-clippy/pull/3984)
* Improve suggestion applicability for [`while_let_loop`] [#3975](https://github.com/rust-lang/rust-clippy/pull/3975)
* Improve diagnostics for [`too_many_arguments`] [#4053](https://github.com/rust-lang/rust-clippy/pull/4053)
* Improve diagnostics for [`cast_lossless`] [#4021](https://github.com/rust-lang/rust-clippy/pull/4021)
* Deal with macro checks in desugarings better [#4082](https://github.com/rust-lang/rust-clippy/pull/4082)
* Add macro check for [`unnecessary_cast`] [#4026](https://github.com/rust-lang/rust-clippy/pull/4026)
* Remove [`approx_constant`]'s documentation's "Known problems" section. [#4027](https://github.com/rust-lang/rust-clippy/pull/4027)
* Fix ICE in [`suspicious_else_formatting`] [#3960](https://github.com/rust-lang/rust-clippy/pull/3960)
* Fix ICE in [`decimal_literal_representation`] [#3931](https://github.com/rust-lang/rust-clippy/pull/3931)


## Rust 1.35 (beta)
[1fac380..37f5c1e](https://github.com/rust-lang/rust-clippy/compare/1fac380...37f5c1e)

* New lint: [`drop_bounds`] to detect `T: Drop` bounds
* Split [`redundant_closure`] into [`redundant_closure`] and [`redundant_closure_for_method_calls`] [#4110](https://github.com/rust-lang/rust-clippy/pull/4101)
* Rename `cyclomatic_complexity` to [`cognitive_complexity`], start work on making lint more practical for Rust code
* Move [`get_unwrap`] to the restriction category
* Improve suggestions for [`iter_cloned_collect`]
Expand Down Expand Up @@ -846,6 +872,7 @@ All notable changes to this project will be documented in this file.
[`char_lit_as_u8`]: https://rust-lang.github.io/rust-clippy/master/index.html#char_lit_as_u8
[`chars_last_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#chars_last_cmp
[`chars_next_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#chars_next_cmp
[`checked_conversions`]: https://rust-lang.github.io/rust-clippy/master/index.html#checked_conversions
[`clone_double_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#clone_double_ref
[`clone_on_copy`]: https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy
[`clone_on_ref_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_ref_ptr
Expand Down Expand Up @@ -1036,6 +1063,7 @@ All notable changes to this project will be documented in this file.
[`redundant_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone
[`redundant_closure`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure
[`redundant_closure_call`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_call
[`redundant_closure_for_method_calls`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_for_method_calls
[`redundant_field_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names
[`redundant_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern
[`redundant_pattern_matching`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

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

[There are 302 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
[There are 304 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)

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

Expand Down
1 change: 1 addition & 0 deletions ci/base-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export CARGO_TARGET_DIR=`pwd`/target/

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

# Check running clippy-driver without cargo
Expand Down
12 changes: 10 additions & 2 deletions clippy_dev/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ extern crate clap;
extern crate clippy_dev;
extern crate regex;

use clap::{App, AppSettings, Arg, SubCommand};
use clap::{App, Arg, SubCommand};
use clippy_dev::*;
mod stderr_length_check;

#[derive(PartialEq)]
enum UpdateMode {
Expand All @@ -13,7 +14,6 @@ enum UpdateMode {

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

if matches.is_present("limit-stderr-length") {
stderr_length_check::check();
}
if let Some(matches) = matches.subcommand_matches("update_lints") {
if matches.is_present("print-only") {
print_lints();
Expand Down
54 changes: 54 additions & 0 deletions clippy_dev/src/stderr_length_check.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use std::ffi::OsStr;
use walkdir::WalkDir;

use std::fs::File;
use std::io::prelude::*;

// The maximum length allowed for stderr files.
//
// We limit this because small files are easier to deal with than bigger files.
const LIMIT: usize = 320;

pub fn check() {
let stderr_files = stderr_files();
let exceeding_files = exceeding_stderr_files(stderr_files).collect::<Vec<String>>();

if !exceeding_files.is_empty() {
eprintln!("Error: stderr files exceeding limit of {} lines:", LIMIT);
for path in exceeding_files {
println!("{}", path);
}
std::process::exit(1);
}
}

fn exceeding_stderr_files(files: impl Iterator<Item = walkdir::DirEntry>) -> impl Iterator<Item = String> {
files
.filter_map(|file| {
let path = file.path().to_str().expect("Could not convert path to str").to_string();
let linecount = count_linenumbers(&path);
if linecount > LIMIT {
Some(path)
} else {
None
}
})
}

fn stderr_files() -> impl Iterator<Item = walkdir::DirEntry> {
// We use `WalkDir` instead of `fs::read_dir` here in order to recurse into subdirectories.
WalkDir::new("../tests/ui")
.into_iter()
.filter_map(std::result::Result::ok)
.filter(|f| f.path().extension() == Some(OsStr::new("stderr")))
}

fn count_linenumbers(filepath: &str) -> usize {
if let Ok(mut file) = File::open(filepath) {
let mut content = String::new();
file.read_to_string(&mut content).expect("Failed to read file?");
content.lines().count()
} else {
0
}
}
41 changes: 18 additions & 23 deletions clippy_lints/src/approx_const.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
use crate::utils::span_lint;
use crate::utils::sym;
use lazy_static::lazy_static;
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint_pass, declare_tool_lint};
use std::f64::consts as f64;
use syntax::ast::{FloatTy, LitKind};
use syntax::symbol;
use syntax::symbol::Symbol;

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

lazy_static! {
// Tuples are of the form (constant, name, min_digits)
static ref KNOWN_CONSTS: [(f64, Symbol, usize); 16] = [
(f64::E, *sym::E, 4),
(f64::FRAC_1_PI, *sym::FRAC_1_PI, 4),
(f64::FRAC_1_SQRT_2, *sym::FRAC_1_SQRT_2, 5),
(f64::FRAC_2_PI, *sym::FRAC_2_PI, 5),
(f64::FRAC_2_SQRT_PI, *sym::FRAC_2_SQRT_PI, 5),
(f64::FRAC_PI_2, *sym::FRAC_PI_2, 5),
(f64::FRAC_PI_3, *sym::FRAC_PI_3, 5),
(f64::FRAC_PI_4, *sym::FRAC_PI_4, 5),
(f64::FRAC_PI_6, *sym::FRAC_PI_6, 5),
(f64::FRAC_PI_8, *sym::FRAC_PI_8, 5),
(f64::LN_10, *sym::LN_10, 5),
(f64::LN_2, *sym::LN_2, 5),
(f64::LOG10_E, *sym::LOG10_E, 5),
(f64::LOG2_E, *sym::LOG2_E, 5),
(f64::PI, *sym::PI, 3),
(f64::SQRT_2, *sym::SQRT_2, 5),
const KNOWN_CONSTS: [(f64, &str, usize); 16] = [
(f64::E, "E", 4),
(f64::FRAC_1_PI, "FRAC_1_PI", 4),
(f64::FRAC_1_SQRT_2, "FRAC_1_SQRT_2", 5),
(f64::FRAC_2_PI, "FRAC_2_PI", 5),
(f64::FRAC_2_SQRT_PI, "FRAC_2_SQRT_PI", 5),
(f64::FRAC_PI_2, "FRAC_PI_2", 5),
(f64::FRAC_PI_3, "FRAC_PI_3", 5),
(f64::FRAC_PI_4, "FRAC_PI_4", 5),
(f64::FRAC_PI_6, "FRAC_PI_6", 5),
(f64::FRAC_PI_8, "FRAC_PI_8", 5),
(f64::LN_10, "LN_10", 5),
(f64::LN_2, "LN_2", 5),
(f64::LOG10_E, "LOG10_E", 5),
(f64::LOG2_E, "LOG2_E", 5),
(f64::PI, "PI", 3),
(f64::SQRT_2, "SQRT_2", 5),
];
}

declare_lint_pass!(ApproxConstant => [APPROX_CONSTANT]);

Expand All @@ -77,7 +72,7 @@ fn check_lit(cx: &LateContext<'_, '_>, lit: &LitKind, e: &Expr) {
fn check_known_consts(cx: &LateContext<'_, '_>, e: &Expr, s: symbol::Symbol, module: &str) {
let s = s.as_str();
if s.parse::<f64>().is_ok() {
for &(constant, name, min_digits) in KNOWN_CONSTS.iter() {
for &(constant, name, min_digits) in &KNOWN_CONSTS {
if is_approx_const(constant, &s, min_digits) {
span_lint(
cx,
Expand Down
5 changes: 2 additions & 3 deletions clippy_lints/src/assertions_on_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use rustc::{declare_lint_pass, declare_tool_lint};
use syntax_pos::Span;

use crate::consts::{constant, Constant};
use crate::utils::sym;
use crate::utils::{in_macro_or_desugar, is_direct_expn_of, span_help_and_lint};

declare_clippy_lint! {
Expand Down Expand Up @@ -41,9 +40,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
!in_macro_or_desugar(span)
};
if_chain! {
if let Some(assert_span) = is_direct_expn_of(e.span, *sym::assert);
if let Some(assert_span) = is_direct_expn_of(e.span, "assert");
if !in_macro_or_desugar(assert_span)
|| is_direct_expn_of(assert_span, *sym::debug_assert)
|| is_direct_expn_of(assert_span, "debug_assert")
.map_or(false, debug_assert_not_in_macro_or_desugar);
if let ExprKind::Unary(_, ref lit) = e.node;
if let Some(bool_const) = constant(cx, cx.tables, lit);
Expand Down
8 changes: 2 additions & 6 deletions clippy_lints/src/assign_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::utils::{
get_trait_def_id, implements_trait, snippet_opt, span_lint_and_then, trait_ref_of_method, SpanlessEq,
};
use crate::utils::{higher, sugg};
use syntax::symbol::Symbol;

declare_clippy_lint! {
/// **What it does:** Checks for `a = a op b` or `a = b commutative_op a`
Expand Down Expand Up @@ -89,11 +88,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
$($trait_name:ident),+) => {
match $op {
$(hir::BinOpKind::$trait_name => {
let [krate, module] = *crate::utils::paths::OPS_MODULE;
let ident = {
*crate::utils::sym::assign::$trait_name
};
let path: [Symbol; 3] = [krate, module, ident];
let [krate, module] = crate::utils::paths::OPS_MODULE;
let path: [&str; 3] = [krate, module, concat!(stringify!($trait_name), "Assign")];
let trait_id = if let Some(trait_id) = get_trait_def_id($cx, &path) {
trait_id
} else {
Expand Down
Loading

0 comments on commit a74055b

Please sign in to comment.