Skip to content

Commit df090fe

Browse files
Merge branch 'master' into cast-ref-to-mut
2 parents f239f7d + c63b634 commit df090fe

Some content is hidden

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

69 files changed

+894
-487
lines changed

.travis.yml

+2
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

CHANGELOG.md

-1
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,6 @@ All notable changes to this project will be documented in this file.
815815
[`ptr_offset_with_cast`]: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_offset_with_cast
816816
[`pub_enum_variant_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#pub_enum_variant_names
817817
[`question_mark`]: https://rust-lang.github.io/rust-clippy/master/index.html#question_mark
818-
[`random_state`]: https://rust-lang.github.io/rust-clippy/master/index.html#random_state
819818
[`range_minus_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#range_minus_one
820819
[`range_plus_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#range_plus_one
821820
[`range_step_by_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#range_step_by_zero

CONTRIBUTING.md

+9
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

+3-3
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 = []

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 292 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
10+
[There are 291 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

clippy_lints/src/consts.rs

+4-4
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/enum_clike.rs

+1-1
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

+3-3
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/len_zero.rs

+9-4
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

-3
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ pub mod precedence;
180180
pub mod ptr;
181181
pub mod ptr_offset_with_cast;
182182
pub mod question_mark;
183-
pub mod random_state;
184183
pub mod ranges;
185184
pub mod redundant_clone;
186185
pub mod redundant_field_names;
@@ -487,7 +486,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
487486
reg.register_late_lint_pass(box ptr_offset_with_cast::Pass);
488487
reg.register_late_lint_pass(box redundant_clone::RedundantClone);
489488
reg.register_late_lint_pass(box slow_vector_initialization::Pass);
490-
reg.register_late_lint_pass(box random_state::Pass);
491489
reg.register_late_lint_pass(box types::RefToMut);
492490

493491
reg.register_lint_group("clippy::restriction", Some("clippy_restriction"), vec![
@@ -1028,7 +1026,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
10281026
fallible_impl_from::FALLIBLE_IMPL_FROM,
10291027
mutex_atomic::MUTEX_INTEGER,
10301028
needless_borrow::NEEDLESS_BORROW,
1031-
random_state::RANDOM_STATE,
10321029
redundant_clone::REDUNDANT_CLONE,
10331030
types::CAST_REF_TO_MUT,
10341031
unwrap::PANICKING_UNWRAP,

clippy_lints/src/no_effect.rs

-14
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

+1-1
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/random_state.rs

-50
This file was deleted.

clippy_lints/src/reference.rs

+2-6
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

+17-7
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
}

clippy_lints/src/use_self.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

10-
use crate::utils::{in_macro, span_lint_and_sugg};
10+
use crate::utils::span_lint_and_sugg;
1111
use if_chain::if_chain;
1212
use rustc::hir::def::{CtorKind, Def};
1313
use rustc::hir::intravisit::{walk_path, walk_ty, NestedVisitorMap, Visitor};
1414
use rustc::hir::*;
15-
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
15+
use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass};
1616
use rustc::ty;
1717
use rustc::{declare_tool_lint, lint_array};
1818
use rustc_errors::Applicability;
@@ -172,7 +172,7 @@ fn check_trait_method_impl_decl<'a, 'tcx: 'a>(
172172

173173
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UseSelf {
174174
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
175-
if in_macro(item.span) {
175+
if in_external_macro(cx.sess(), item.span) {
176176
return;
177177
}
178178
if_chain! {

clippy_lints/src/utils/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ use rustc::ty::{
2525
subst::Kind,
2626
Binder, Ty, TyCtxt,
2727
};
28+
use rustc_data_structures::sync::Lrc;
2829
use rustc_errors::{Applicability, CodeSuggestion, Substitution, SubstitutionPart};
2930
use std::borrow::Cow;
3031
use std::env;
3132
use std::mem;
32-
use std::rc::Rc;
3333
use std::str::FromStr;
3434
use syntax::ast::{self, LitKind};
3535
use syntax::attr;
@@ -223,7 +223,7 @@ pub fn path_to_def(cx: &LateContext<'_, '_>, path: &[&str]) -> Option<def::Def>
223223
None => return None,
224224
};
225225

226-
for item in mem::replace(&mut items, Rc::new(vec![])).iter() {
226+
for item in mem::replace(&mut items, Lrc::new(vec![])).iter() {
227227
if item.ident.name == *segment {
228228
if path_it.peek().is_none() {
229229
return Some(item.def);
@@ -271,7 +271,7 @@ pub fn implements_trait<'a, 'tcx>(
271271
);
272272
cx.tcx
273273
.infer_ctxt()
274-
.enter(|infcx| infcx.predicate_must_hold(&obligation))
274+
.enter(|infcx| infcx.predicate_must_hold_modulo_regions(&obligation))
275275
}
276276

277277
/// Check whether this type implements Drop.
@@ -884,7 +884,7 @@ pub fn type_is_unsafe_function<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx
884884
}
885885

886886
pub fn is_copy<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool {
887-
!ty.moves_by_default(cx.tcx.global_tcx(), cx.param_env, DUMMY_SP)
887+
ty.is_copy_modulo_regions(cx.tcx.global_tcx(), cx.param_env, DUMMY_SP)
888888
}
889889

890890
/// Return whether a pattern is refutable.

0 commit comments

Comments
 (0)