Skip to content

Commit

Permalink
submodules: update clippy from 39bd844 to c63b634
Browse files Browse the repository at this point in the history
Changes:
````
Revert "tests: used_underscore_binding_macro: disable random_state lint."
Revert "Auto merge of rust-lang#3603 - xfix:random-state-lint, r=phansch"
rustup rust-lang/rust#56837
rustup (don't know the exact PR unfortunately)
Add itertools to integration tests
tests: used_underscore_binding_macro: disable random_state lint.
Trigger `use_self` lint in local macros
Add run-rustfix where it already passes
rustup: rust-lang/rust#55517
Make clippy work with parallel rustc
Add ui/for_kv_map test for false positive in rust-lang#1279
Update to latest compiletest-rs release
add testcase for rust-lang#3462
deps: bump rustc_tools_util version from 0.1.0 to 0.1.1 just in case...
Use compiletest's aux-build header instead of include macro
rustc_tool_utils: fix failure to create proper non-repo version string when used in crates on crates.io, bump version
rustfmt
UI test cleanup: Extract ifs_same_cond tests
Extract IteratorFalsePositives into option_helpers.rs
UI test cleanup: Extract for_kv_map lint tests
UI test cleanup: Extract lint from methods.rs test
Fix test for rust-lang/rust#57250
Limit infinite_iter collect() check to known types
Some improvements to util documentation
Use hashset for name blacklist
Reformat random_state tests
Use node_id_to_type_opt instead of node_it_to_type in random_state
Check pattern equality while checking declaration equality
random_state lint
Move constant write checks to temporary_assignment lint
Use an FxHashSet for valid idents in documentation lint
Fix suggestion for unnecessary_ref lint
Update CONTRIBUTING.md for rustfix tests
Update .fixed files via update-references.sh
Run rustfix on first UI test
Use WIP branch for compiletest_rs
````
  • Loading branch information
matthiaskrgr committed Jan 7, 2019
1 parent 0d30b1a commit 209696d
Show file tree
Hide file tree
Showing 79 changed files with 1,202 additions and 593 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ matrix:
if: repo =~ /^rust-lang\/rust-clippy$/
- env: INTEGRATION=hyperium/hyper
if: repo =~ /^rust-lang\/rust-clippy$/
- env: INTEGRATION=bluss/rust-itertools
if: repo =~ /^rust-lang\/rust-clippy$/
allow_failures:
- os: windows
env: CARGO_INCREMENTAL=0 BASE_TESTS=true
Expand Down
9 changes: 9 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ Therefore you should use `tests/ui/update-all-references.sh` (after running
`cargo test`) and check whether the output looks as you expect with `git diff`. Commit all
`*.stderr` files, too.

If the lint you are working on is making use of structured suggestions, the
test file should include a `// run-rustfix` comment at the top. This will
additionally run [rustfix](https://github.com/rust-lang-nursery/rustfix) for
that test. Rustfix will apply the suggestions from the lint to the code of the
test file and compare that to the contents of a `.fixed` file.

Use `tests/ui/update-all-references.sh` to automatically generate the
`.fixed` file after running `cargo test`.

### Running rustfmt

[Rustfmt](https://github.com/rust-lang/rustfmt) is a tool for formatting Rust code according
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ clippy_lints = { version = "0.0.212", path = "clippy_lints" }
# end automatic update
regex = "1"
semver = "0.9"
rustc_tools_util = { version = "0.1.0", path = "rustc_tools_util"}
rustc_tools_util = { version = "0.1.1", path = "rustc_tools_util"}

[dev-dependencies]
clippy_dev = { version = "0.0.1", path = "clippy_dev" }
cargo_metadata = "0.6.2"
compiletest_rs = "0.3.16"
compiletest_rs = "0.3.18"
lazy_static = "1.0"
serde_derive = "1.0"
clippy-mini-macro-test = { version = "0.2", path = "mini-macro" }
Expand All @@ -61,7 +61,7 @@ derive-new = "0.5"
rustc-workspace-hack = "1.0.0"

[build-dependencies]
rustc_tools_util = { version = "0.1.0", path = "rustc_tools_util"}
rustc_tools_util = { version = "0.1.1", path = "rustc_tools_util"}

[features]
debugging = []
7 changes: 4 additions & 3 deletions clippy_lints/src/blacklisted_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::utils::span_lint;
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use rustc_data_structures::fx::FxHashSet;

/// **What it does:** Checks for usage of blacklisted names for variables, such
/// as `foo`.
Expand All @@ -32,11 +33,11 @@ declare_clippy_lint! {

#[derive(Clone, Debug)]
pub struct BlackListedName {
blacklist: Vec<String>,
blacklist: FxHashSet<String>,
}

impl BlackListedName {
pub fn new(blacklist: Vec<String>) -> Self {
pub fn new(blacklist: FxHashSet<String>) -> Self {
Self { blacklist }
}
}
Expand All @@ -50,7 +51,7 @@ impl LintPass for BlackListedName {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlackListedName {
fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) {
if let PatKind::Binding(_, _, ident, _) = pat.node {
if self.blacklist.iter().any(|s| ident.name == *s) {
if self.blacklist.contains(&ident.name.to_string()) {
span_lint(
cx,
BLACKLISTED_NAME,
Expand Down
8 changes: 4 additions & 4 deletions clippy_lints/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ use rustc::lint::LateContext;
use rustc::ty::subst::{Subst, Substs};
use rustc::ty::{self, Instance, Ty, TyCtxt};
use rustc::{bug, span_bug};
use rustc_data_structures::sync::Lrc;
use std::cmp::Ordering::{self, Equal};
use std::cmp::PartialOrd;
use std::convert::TryInto;
use std::hash::{Hash, Hasher};
use std::rc::Rc;
use syntax::ast::{FloatTy, LitKind};
use syntax::ptr::P;

Expand All @@ -31,7 +31,7 @@ pub enum Constant {
/// a String "abc"
Str(String),
/// a Binary String b"abc"
Binary(Rc<Vec<u8>>),
Binary(Lrc<Vec<u8>>),
/// a single char 'a'
Char(char),
/// an integer's bit representation
Expand Down Expand Up @@ -156,7 +156,7 @@ pub fn lit_to_constant<'tcx>(lit: &LitKind, ty: Ty<'tcx>) -> Constant {
match *lit {
LitKind::Str(ref is, _) => Constant::Str(is.to_string()),
LitKind::Byte(b) => Constant::Int(u128::from(b)),
LitKind::ByteStr(ref s) => Constant::Binary(Rc::clone(s)),
LitKind::ByteStr(ref s) => Constant::Binary(Lrc::clone(s)),
LitKind::Char(c) => Constant::Char(c),
LitKind::Int(n, _) => Constant::Int(n),
LitKind::Float(ref is, _) | LitKind::FloatUnsuffixed(ref is) => match ty.sty {
Expand Down Expand Up @@ -304,7 +304,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
};

let result = self.tcx.const_eval(self.param_env.and(gid)).ok()?;
let ret = miri_to_const(self.tcx, result);
let ret = miri_to_const(self.tcx, &result);
if ret.is_some() {
self.needed_resolution = true;
}
Expand Down
13 changes: 7 additions & 6 deletions clippy_lints/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use itertools::Itertools;
use pulldown_cmark;
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use rustc_data_structures::fx::FxHashSet;
use syntax::ast;
use syntax::source_map::{BytePos, Span};
use syntax_pos::Pos;
Expand Down Expand Up @@ -43,11 +44,11 @@ declare_clippy_lint! {

#[derive(Clone)]
pub struct Doc {
valid_idents: Vec<String>,
valid_idents: FxHashSet<String>,
}

impl Doc {
pub fn new(valid_idents: Vec<String>) -> Self {
pub fn new(valid_idents: FxHashSet<String>) -> Self {
Self { valid_idents }
}
}
Expand Down Expand Up @@ -144,7 +145,7 @@ pub fn strip_doc_comment_decoration(comment: &str, span: Span) -> (String, Vec<(
panic!("not a doc-comment: {}", comment);
}

pub fn check_attrs<'a>(cx: &EarlyContext<'_>, valid_idents: &[String], attrs: &'a [ast::Attribute]) {
pub fn check_attrs<'a>(cx: &EarlyContext<'_>, valid_idents: &FxHashSet<String>, attrs: &'a [ast::Attribute]) {
let mut doc = String::new();
let mut spans = vec![];

Expand Down Expand Up @@ -192,7 +193,7 @@ pub fn check_attrs<'a>(cx: &EarlyContext<'_>, valid_idents: &[String], attrs: &'

fn check_doc<'a, Events: Iterator<Item = (usize, pulldown_cmark::Event<'a>)>>(
cx: &EarlyContext<'_>,
valid_idents: &[String],
valid_idents: &FxHashSet<String>,
docs: Events,
spans: &[(usize, Span)],
) {
Expand Down Expand Up @@ -237,14 +238,14 @@ fn check_doc<'a, Events: Iterator<Item = (usize, pulldown_cmark::Event<'a>)>>(
}
}

fn check_text(cx: &EarlyContext<'_>, valid_idents: &[String], text: &str, span: Span) {
fn check_text(cx: &EarlyContext<'_>, valid_idents: &FxHashSet<String>, text: &str, span: Span) {
for word in text.split(|c: char| c.is_whitespace() || c == '\'') {
// Trim punctuation as in `some comment (see foo::bar).`
// ^^
// Or even as in `_foo bar_` which is emphasized.
let word = word.trim_matches(|c: char| !c.is_alphanumeric());

if valid_idents.iter().any(|i| i == word) {
if valid_idents.contains(word) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/enum_clike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant {
promoted: None,
};
let constant = cx.tcx.const_eval(param_env.and(c_id)).ok();
if let Some(Constant::Int(val)) = constant.and_then(|c| miri_to_const(cx.tcx, c)) {
if let Some(Constant::Int(val)) = constant.and_then(|c| miri_to_const(cx.tcx, &c)) {
let mut ty = cx.tcx.type_of(def_id);
if let ty::Adt(adt, _) = ty.sty {
if adt.is_enum() {
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/enum_variants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use rustc::lint::{EarlyContext, EarlyLintPass, Lint, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use syntax::ast::*;
use syntax::source_map::Span;
use syntax::symbol::LocalInternedString;
use syntax::symbol::{InternedString, LocalInternedString};

/// **What it does:** Detects enumeration variants that are prefixed or suffixed
/// by the same characters.
Expand Down Expand Up @@ -111,7 +111,7 @@ declare_clippy_lint! {
}

pub struct EnumVariantNames {
modules: Vec<(LocalInternedString, String)>,
modules: Vec<(InternedString, String)>,
threshold: u64,
}

Expand Down Expand Up @@ -308,6 +308,6 @@ impl EarlyLintPass for EnumVariantNames {
};
check_variant(cx, self.threshold, def, &item_name, item_name_chars, item.span, lint);
}
self.modules.push((item_name, item_camel));
self.modules.push((item_name.as_interned_str(), item_camel));
}
}
20 changes: 18 additions & 2 deletions clippy_lints/src/infinite_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use crate::utils::{get_trait_def_id, higher, implements_trait, match_qpath, paths, span_lint};
use crate::utils::{get_trait_def_id, higher, implements_trait, match_qpath, match_type, paths, span_lint};
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
Expand Down Expand Up @@ -200,7 +200,6 @@ static POSSIBLY_COMPLETING_METHODS: &[(&str, usize)] = &[
/// their iterators
static COMPLETING_METHODS: &[(&str, usize)] = &[
("count", 1),
("collect", 1),
("fold", 3),
("for_each", 2),
("partition", 2),
Expand All @@ -214,6 +213,18 @@ static COMPLETING_METHODS: &[(&str, usize)] = &[
("product", 1),
];

/// the paths of types that are known to be infinitely allocating
static INFINITE_COLLECTORS: &[&[&str]] = &[
&paths::BINARY_HEAP,
&paths::BTREEMAP,
&paths::BTREESET,
&paths::HASHMAP,
&paths::HASHSET,
&paths::LINKED_LIST,
&paths::VEC,
&paths::VEC_DEQUE,
];

fn complete_infinite_iter(cx: &LateContext<'_, '_>, expr: &Expr) -> Finiteness {
match expr.node {
ExprKind::MethodCall(ref method, _, ref args) => {
Expand All @@ -233,6 +244,11 @@ fn complete_infinite_iter(cx: &LateContext<'_, '_>, expr: &Expr) -> Finiteness {
if not_double_ended {
return is_infinite(cx, &args[0]);
}
} else if method.ident.name == "collect" {
let ty = cx.tables.expr_ty(expr);
if INFINITE_COLLECTORS.iter().any(|path| match_type(cx, ty, path)) {
return is_infinite(cx, &args[0]);
}
}
},
ExprKind::Binary(op, ref l, ref r) => {
Expand Down
13 changes: 9 additions & 4 deletions clippy_lints/src/len_zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,15 @@ fn has_is_empty(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {

let ty = &walk_ptrs_ty(cx.tables.expr_ty(expr));
match ty.sty {
ty::Dynamic(ref tt, ..) => cx
.tcx
.associated_items(tt.principal().def_id())
.any(|item| is_is_empty(cx, &item)),
ty::Dynamic(ref tt, ..) => {
if let Some(principal) = tt.principal() {
cx.tcx
.associated_items(principal.def_id())
.any(|item| is_is_empty(cx, &item))
} else {
false
}
},
ty::Projection(ref proj) => has_is_empty_impl(cx, proj.item_def_id),
ty::Adt(id, _) => has_is_empty_impl(cx, id.did),
ty::Array(..) | ty::Slice(..) | ty::Str => true,
Expand Down
6 changes: 4 additions & 2 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,11 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
reg.register_late_lint_pass(box overflow_check_conditional::OverflowCheckConditional);
reg.register_late_lint_pass(box unused_label::UnusedLabel);
reg.register_late_lint_pass(box new_without_default::NewWithoutDefault::default());
reg.register_late_lint_pass(box blacklisted_name::BlackListedName::new(conf.blacklisted_names.clone()));
reg.register_late_lint_pass(box blacklisted_name::BlackListedName::new(
conf.blacklisted_names.iter().cloned().collect()
));
reg.register_late_lint_pass(box functions::Functions::new(conf.too_many_arguments_threshold));
reg.register_early_lint_pass(box doc::Doc::new(conf.doc_valid_idents.clone()));
reg.register_early_lint_pass(box doc::Doc::new(conf.doc_valid_idents.iter().cloned().collect()));
reg.register_late_lint_pass(box neg_multiply::NegMultiply);
reg.register_early_lint_pass(box unsafe_removed_from_name::UnsafeNameRemoval);
reg.register_late_lint_pass(box mem_discriminant::MemDiscriminant);
Expand Down
14 changes: 0 additions & 14 deletions clippy_lints/src/no_effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,6 @@ fn has_no_effect(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
false
}
},
ExprKind::Assign(ref left, ref right) => {
if has_no_effect(cx, left) {
let mut left = left;
while let ExprKind::Field(f, _) | ExprKind::Index(f, _) = &left.node {
left = f;
}
if let ExprKind::Path(qpath) = &left.node {
if let Def::Const(..) = cx.tables.qpath_def(qpath, left.hir_id) {
return has_no_effect(cx, right);
}
}
}
false
},
_ => false,
}
}
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/question_mark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl Pass {
fn moves_by_default(cx: &LateContext<'_, '_>, expression: &Expr) -> bool {
let expr_ty = cx.tables.expr_ty(expression);

expr_ty.moves_by_default(cx.tcx, cx.param_env, expression.span)
!expr_ty.is_copy_modulo_regions(cx.tcx, cx.param_env, expression.span)
}

fn is_option(cx: &LateContext<'_, '_>, expression: &Expr) -> bool {
Expand Down
8 changes: 2 additions & 6 deletions clippy_lints/src/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl LintPass for DerefPass {
impl EarlyLintPass for DerefPass {
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &Expr) {
if_chain! {
if let ExprKind::Field(ref object, ref field_name) = e.node;
if let ExprKind::Field(ref object, _) = e.node;
if let ExprKind::Paren(ref parened) = object.node;
if let ExprKind::AddrOf(_, ref inner) = parened.node;
then {
Expand All @@ -109,11 +109,7 @@ impl EarlyLintPass for DerefPass {
object.span,
"Creating a reference that is immediately dereferenced.",
"try this",
format!(
"{}.{}",
snippet_with_applicability(cx, inner.span, "_", &mut applicability),
snippet_with_applicability(cx, field_name.span, "_", &mut applicability)
),
snippet_with_applicability(cx, inner.span, "_", &mut applicability).to_string(),
applicability,
);
}
Expand Down
24 changes: 17 additions & 7 deletions clippy_lints/src/temporary_assignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use crate::utils::is_adjusted;
use crate::utils::span_lint;
use rustc::hir::def::Def;
use rustc::hir::{Expr, ExprKind};
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
Expand All @@ -31,9 +32,16 @@ declare_clippy_lint! {
"assignments to temporaries"
}

fn is_temporary(expr: &Expr) -> bool {
match expr.node {
fn is_temporary(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
match &expr.node {
ExprKind::Struct(..) | ExprKind::Tup(..) => true,
ExprKind::Path(qpath) => {
if let Def::Const(..) = cx.tables.qpath_def(qpath, expr.hir_id) {
true
} else {
false
}
},
_ => false,
}
}
Expand All @@ -49,11 +57,13 @@ impl LintPass for Pass {

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if let ExprKind::Assign(ref target, _) = expr.node {
if let ExprKind::Field(ref base, _) = target.node {
if is_temporary(base) && !is_adjusted(cx, base) {
span_lint(cx, TEMPORARY_ASSIGNMENT, expr.span, "assignment to temporary");
}
if let ExprKind::Assign(target, _) = &expr.node {
let mut base = target;
while let ExprKind::Field(f, _) | ExprKind::Index(f, _) = &base.node {
base = f;
}
if is_temporary(cx, base) && !is_adjusted(cx, base) {
span_lint(cx, TEMPORARY_ASSIGNMENT, expr.span, "assignment to temporary");
}
}
}
Expand Down
Loading

0 comments on commit 209696d

Please sign in to comment.