Skip to content

Commit 209696d

Browse files
committed
submodules: update clippy from 39bd844 to c63b634
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 ````
1 parent 0d30b1a commit 209696d

File tree

79 files changed

+1202
-593
lines changed

Some content is hidden

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

79 files changed

+1202
-593
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ matrix:
7171
if: repo =~ /^rust-lang\/rust-clippy$/
7272
- env: INTEGRATION=hyperium/hyper
7373
if: repo =~ /^rust-lang\/rust-clippy$/
74+
- env: INTEGRATION=bluss/rust-itertools
75+
if: repo =~ /^rust-lang\/rust-clippy$/
7476
allow_failures:
7577
- os: windows
7678
env: CARGO_INCREMENTAL=0 BASE_TESTS=true

CONTRIBUTING.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@ Therefore you should use `tests/ui/update-all-references.sh` (after running
156156
`cargo test`) and check whether the output looks as you expect with `git diff`. Commit all
157157
`*.stderr` files, too.
158158

159+
If the lint you are working on is making use of structured suggestions, the
160+
test file should include a `// run-rustfix` comment at the top. This will
161+
additionally run [rustfix](https://github.com/rust-lang-nursery/rustfix) for
162+
that test. Rustfix will apply the suggestions from the lint to the code of the
163+
test file and compare that to the contents of a `.fixed` file.
164+
165+
Use `tests/ui/update-all-references.sh` to automatically generate the
166+
`.fixed` file after running `cargo test`.
167+
159168
### Running rustfmt
160169

161170
[Rustfmt](https://github.com/rust-lang/rustfmt) is a tool for formatting Rust code according

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ clippy_lints = { version = "0.0.212", path = "clippy_lints" }
4343
# end automatic update
4444
regex = "1"
4545
semver = "0.9"
46-
rustc_tools_util = { version = "0.1.0", path = "rustc_tools_util"}
46+
rustc_tools_util = { version = "0.1.1", path = "rustc_tools_util"}
4747

4848
[dev-dependencies]
4949
clippy_dev = { version = "0.0.1", path = "clippy_dev" }
5050
cargo_metadata = "0.6.2"
51-
compiletest_rs = "0.3.16"
51+
compiletest_rs = "0.3.18"
5252
lazy_static = "1.0"
5353
serde_derive = "1.0"
5454
clippy-mini-macro-test = { version = "0.2", path = "mini-macro" }
@@ -61,7 +61,7 @@ derive-new = "0.5"
6161
rustc-workspace-hack = "1.0.0"
6262

6363
[build-dependencies]
64-
rustc_tools_util = { version = "0.1.0", path = "rustc_tools_util"}
64+
rustc_tools_util = { version = "0.1.1", path = "rustc_tools_util"}
6565

6666
[features]
6767
debugging = []

clippy_lints/src/blacklisted_name.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::utils::span_lint;
1111
use rustc::hir::*;
1212
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
1313
use rustc::{declare_tool_lint, lint_array};
14+
use rustc_data_structures::fx::FxHashSet;
1415

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

3334
#[derive(Clone, Debug)]
3435
pub struct BlackListedName {
35-
blacklist: Vec<String>,
36+
blacklist: FxHashSet<String>,
3637
}
3738

3839
impl BlackListedName {
39-
pub fn new(blacklist: Vec<String>) -> Self {
40+
pub fn new(blacklist: FxHashSet<String>) -> Self {
4041
Self { blacklist }
4142
}
4243
}
@@ -50,7 +51,7 @@ impl LintPass for BlackListedName {
5051
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlackListedName {
5152
fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) {
5253
if let PatKind::Binding(_, _, ident, _) = pat.node {
53-
if self.blacklist.iter().any(|s| ident.name == *s) {
54+
if self.blacklist.contains(&ident.name.to_string()) {
5455
span_lint(
5556
cx,
5657
BLACKLISTED_NAME,

clippy_lints/src/consts.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ use rustc::lint::LateContext;
1717
use rustc::ty::subst::{Subst, Substs};
1818
use rustc::ty::{self, Instance, Ty, TyCtxt};
1919
use rustc::{bug, span_bug};
20+
use rustc_data_structures::sync::Lrc;
2021
use std::cmp::Ordering::{self, Equal};
2122
use std::cmp::PartialOrd;
2223
use std::convert::TryInto;
2324
use std::hash::{Hash, Hasher};
24-
use std::rc::Rc;
2525
use syntax::ast::{FloatTy, LitKind};
2626
use syntax::ptr::P;
2727

@@ -31,7 +31,7 @@ pub enum Constant {
3131
/// a String "abc"
3232
Str(String),
3333
/// a Binary String b"abc"
34-
Binary(Rc<Vec<u8>>),
34+
Binary(Lrc<Vec<u8>>),
3535
/// a single char 'a'
3636
Char(char),
3737
/// an integer's bit representation
@@ -156,7 +156,7 @@ pub fn lit_to_constant<'tcx>(lit: &LitKind, ty: Ty<'tcx>) -> Constant {
156156
match *lit {
157157
LitKind::Str(ref is, _) => Constant::Str(is.to_string()),
158158
LitKind::Byte(b) => Constant::Int(u128::from(b)),
159-
LitKind::ByteStr(ref s) => Constant::Binary(Rc::clone(s)),
159+
LitKind::ByteStr(ref s) => Constant::Binary(Lrc::clone(s)),
160160
LitKind::Char(c) => Constant::Char(c),
161161
LitKind::Int(n, _) => Constant::Int(n),
162162
LitKind::Float(ref is, _) | LitKind::FloatUnsuffixed(ref is) => match ty.sty {
@@ -304,7 +304,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
304304
};
305305

306306
let result = self.tcx.const_eval(self.param_env.and(gid)).ok()?;
307-
let ret = miri_to_const(self.tcx, result);
307+
let ret = miri_to_const(self.tcx, &result);
308308
if ret.is_some() {
309309
self.needed_resolution = true;
310310
}

clippy_lints/src/doc.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use itertools::Itertools;
1212
use pulldown_cmark;
1313
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
1414
use rustc::{declare_tool_lint, lint_array};
15+
use rustc_data_structures::fx::FxHashSet;
1516
use syntax::ast;
1617
use syntax::source_map::{BytePos, Span};
1718
use syntax_pos::Pos;
@@ -43,11 +44,11 @@ declare_clippy_lint! {
4344

4445
#[derive(Clone)]
4546
pub struct Doc {
46-
valid_idents: Vec<String>,
47+
valid_idents: FxHashSet<String>,
4748
}
4849

4950
impl Doc {
50-
pub fn new(valid_idents: Vec<String>) -> Self {
51+
pub fn new(valid_idents: FxHashSet<String>) -> Self {
5152
Self { valid_idents }
5253
}
5354
}
@@ -144,7 +145,7 @@ pub fn strip_doc_comment_decoration(comment: &str, span: Span) -> (String, Vec<(
144145
panic!("not a doc-comment: {}", comment);
145146
}
146147

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

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

193194
fn check_doc<'a, Events: Iterator<Item = (usize, pulldown_cmark::Event<'a>)>>(
194195
cx: &EarlyContext<'_>,
195-
valid_idents: &[String],
196+
valid_idents: &FxHashSet<String>,
196197
docs: Events,
197198
spans: &[(usize, Span)],
198199
) {
@@ -237,14 +238,14 @@ fn check_doc<'a, Events: Iterator<Item = (usize, pulldown_cmark::Event<'a>)>>(
237238
}
238239
}
239240

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

247-
if valid_idents.iter().any(|i| i == word) {
248+
if valid_idents.contains(word) {
248249
continue;
249250
}
250251

clippy_lints/src/enum_clike.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant {
7070
promoted: None,
7171
};
7272
let constant = cx.tcx.const_eval(param_env.and(c_id)).ok();
73-
if let Some(Constant::Int(val)) = constant.and_then(|c| miri_to_const(cx.tcx, c)) {
73+
if let Some(Constant::Int(val)) = constant.and_then(|c| miri_to_const(cx.tcx, &c)) {
7474
let mut ty = cx.tcx.type_of(def_id);
7575
if let ty::Adt(adt, _) = ty.sty {
7676
if adt.is_enum() {

clippy_lints/src/enum_variants.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc::lint::{EarlyContext, EarlyLintPass, Lint, LintArray, LintPass};
1515
use rustc::{declare_tool_lint, lint_array};
1616
use syntax::ast::*;
1717
use syntax::source_map::Span;
18-
use syntax::symbol::LocalInternedString;
18+
use syntax::symbol::{InternedString, LocalInternedString};
1919

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

113113
pub struct EnumVariantNames {
114-
modules: Vec<(LocalInternedString, String)>,
114+
modules: Vec<(InternedString, String)>,
115115
threshold: u64,
116116
}
117117

@@ -308,6 +308,6 @@ impl EarlyLintPass for EnumVariantNames {
308308
};
309309
check_variant(cx, self.threshold, def, &item_name, item_name_chars, item.span, lint);
310310
}
311-
self.modules.push((item_name, item_camel));
311+
self.modules.push((item_name.as_interned_str(), item_camel));
312312
}
313313
}

clippy_lints/src/infinite_iter.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

10-
use crate::utils::{get_trait_def_id, higher, implements_trait, match_qpath, paths, span_lint};
10+
use crate::utils::{get_trait_def_id, higher, implements_trait, match_qpath, match_type, paths, span_lint};
1111
use rustc::hir::*;
1212
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
1313
use rustc::{declare_tool_lint, lint_array};
@@ -200,7 +200,6 @@ static POSSIBLY_COMPLETING_METHODS: &[(&str, usize)] = &[
200200
/// their iterators
201201
static COMPLETING_METHODS: &[(&str, usize)] = &[
202202
("count", 1),
203-
("collect", 1),
204203
("fold", 3),
205204
("for_each", 2),
206205
("partition", 2),
@@ -214,6 +213,18 @@ static COMPLETING_METHODS: &[(&str, usize)] = &[
214213
("product", 1),
215214
];
216215

216+
/// the paths of types that are known to be infinitely allocating
217+
static INFINITE_COLLECTORS: &[&[&str]] = &[
218+
&paths::BINARY_HEAP,
219+
&paths::BTREEMAP,
220+
&paths::BTREESET,
221+
&paths::HASHMAP,
222+
&paths::HASHSET,
223+
&paths::LINKED_LIST,
224+
&paths::VEC,
225+
&paths::VEC_DEQUE,
226+
];
227+
217228
fn complete_infinite_iter(cx: &LateContext<'_, '_>, expr: &Expr) -> Finiteness {
218229
match expr.node {
219230
ExprKind::MethodCall(ref method, _, ref args) => {
@@ -233,6 +244,11 @@ fn complete_infinite_iter(cx: &LateContext<'_, '_>, expr: &Expr) -> Finiteness {
233244
if not_double_ended {
234245
return is_infinite(cx, &args[0]);
235246
}
247+
} else if method.ident.name == "collect" {
248+
let ty = cx.tables.expr_ty(expr);
249+
if INFINITE_COLLECTORS.iter().any(|path| match_type(cx, ty, path)) {
250+
return is_infinite(cx, &args[0]);
251+
}
236252
}
237253
},
238254
ExprKind::Binary(op, ref l, ref r) => {

clippy_lints/src/len_zero.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,15 @@ fn has_is_empty(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
302302

303303
let ty = &walk_ptrs_ty(cx.tables.expr_ty(expr));
304304
match ty.sty {
305-
ty::Dynamic(ref tt, ..) => cx
306-
.tcx
307-
.associated_items(tt.principal().def_id())
308-
.any(|item| is_is_empty(cx, &item)),
305+
ty::Dynamic(ref tt, ..) => {
306+
if let Some(principal) = tt.principal() {
307+
cx.tcx
308+
.associated_items(principal.def_id())
309+
.any(|item| is_is_empty(cx, &item))
310+
} else {
311+
false
312+
}
313+
},
309314
ty::Projection(ref proj) => has_is_empty_impl(cx, proj.item_def_id),
310315
ty::Adt(id, _) => has_is_empty_impl(cx, id.did),
311316
ty::Array(..) | ty::Slice(..) | ty::Str => true,

clippy_lints/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,11 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
423423
reg.register_late_lint_pass(box overflow_check_conditional::OverflowCheckConditional);
424424
reg.register_late_lint_pass(box unused_label::UnusedLabel);
425425
reg.register_late_lint_pass(box new_without_default::NewWithoutDefault::default());
426-
reg.register_late_lint_pass(box blacklisted_name::BlackListedName::new(conf.blacklisted_names.clone()));
426+
reg.register_late_lint_pass(box blacklisted_name::BlackListedName::new(
427+
conf.blacklisted_names.iter().cloned().collect()
428+
));
427429
reg.register_late_lint_pass(box functions::Functions::new(conf.too_many_arguments_threshold));
428-
reg.register_early_lint_pass(box doc::Doc::new(conf.doc_valid_idents.clone()));
430+
reg.register_early_lint_pass(box doc::Doc::new(conf.doc_valid_idents.iter().cloned().collect()));
429431
reg.register_late_lint_pass(box neg_multiply::NegMultiply);
430432
reg.register_early_lint_pass(box unsafe_removed_from_name::UnsafeNameRemoval);
431433
reg.register_late_lint_pass(box mem_discriminant::MemDiscriminant);

clippy_lints/src/no_effect.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,6 @@ fn has_no_effect(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
9898
false
9999
}
100100
},
101-
ExprKind::Assign(ref left, ref right) => {
102-
if has_no_effect(cx, left) {
103-
let mut left = left;
104-
while let ExprKind::Field(f, _) | ExprKind::Index(f, _) = &left.node {
105-
left = f;
106-
}
107-
if let ExprKind::Path(qpath) = &left.node {
108-
if let Def::Const(..) = cx.tables.qpath_def(qpath, left.hir_id) {
109-
return has_no_effect(cx, right);
110-
}
111-
}
112-
}
113-
false
114-
},
115101
_ => false,
116102
}
117103
}

clippy_lints/src/question_mark.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl Pass {
113113
fn moves_by_default(cx: &LateContext<'_, '_>, expression: &Expr) -> bool {
114114
let expr_ty = cx.tables.expr_ty(expression);
115115

116-
expr_ty.moves_by_default(cx.tcx, cx.param_env, expression.span)
116+
!expr_ty.is_copy_modulo_regions(cx.tcx, cx.param_env, expression.span)
117117
}
118118

119119
fn is_option(cx: &LateContext<'_, '_>, expression: &Expr) -> bool {

clippy_lints/src/reference.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl LintPass for DerefPass {
9898
impl EarlyLintPass for DerefPass {
9999
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &Expr) {
100100
if_chain! {
101-
if let ExprKind::Field(ref object, ref field_name) = e.node;
101+
if let ExprKind::Field(ref object, _) = e.node;
102102
if let ExprKind::Paren(ref parened) = object.node;
103103
if let ExprKind::AddrOf(_, ref inner) = parened.node;
104104
then {
@@ -109,11 +109,7 @@ impl EarlyLintPass for DerefPass {
109109
object.span,
110110
"Creating a reference that is immediately dereferenced.",
111111
"try this",
112-
format!(
113-
"{}.{}",
114-
snippet_with_applicability(cx, inner.span, "_", &mut applicability),
115-
snippet_with_applicability(cx, field_name.span, "_", &mut applicability)
116-
),
112+
snippet_with_applicability(cx, inner.span, "_", &mut applicability).to_string(),
117113
applicability,
118114
);
119115
}

clippy_lints/src/temporary_assignment.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use crate::utils::is_adjusted;
1111
use crate::utils::span_lint;
12+
use rustc::hir::def::Def;
1213
use rustc::hir::{Expr, ExprKind};
1314
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
1415
use rustc::{declare_tool_lint, lint_array};
@@ -31,9 +32,16 @@ declare_clippy_lint! {
3132
"assignments to temporaries"
3233
}
3334

34-
fn is_temporary(expr: &Expr) -> bool {
35-
match expr.node {
35+
fn is_temporary(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
36+
match &expr.node {
3637
ExprKind::Struct(..) | ExprKind::Tup(..) => true,
38+
ExprKind::Path(qpath) => {
39+
if let Def::Const(..) = cx.tables.qpath_def(qpath, expr.hir_id) {
40+
true
41+
} else {
42+
false
43+
}
44+
},
3745
_ => false,
3846
}
3947
}
@@ -49,11 +57,13 @@ impl LintPass for Pass {
4957

5058
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
5159
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
52-
if let ExprKind::Assign(ref target, _) = expr.node {
53-
if let ExprKind::Field(ref base, _) = target.node {
54-
if is_temporary(base) && !is_adjusted(cx, base) {
55-
span_lint(cx, TEMPORARY_ASSIGNMENT, expr.span, "assignment to temporary");
56-
}
60+
if let ExprKind::Assign(target, _) = &expr.node {
61+
let mut base = target;
62+
while let ExprKind::Field(f, _) | ExprKind::Index(f, _) = &base.node {
63+
base = f;
64+
}
65+
if is_temporary(cx, base) && !is_adjusted(cx, base) {
66+
span_lint(cx, TEMPORARY_ASSIGNMENT, expr.span, "assignment to temporary");
5767
}
5868
}
5969
}

0 commit comments

Comments
 (0)