Skip to content

Commit ff33e0b

Browse files
committed
Update Clippy
1 parent c955ade commit ff33e0b

Some content is hidden

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

63 files changed

+818
-441
lines changed

CHANGELOG.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,38 @@ All notable changes to this project will be documented in this file.
44

55
## Unreleased / In Rust Beta or Nightly
66

7-
[b2601be...master](https://github.com/rust-lang/rust-clippy/compare/b2601be...master)
7+
[1b89724...master](https://github.com/rust-lang/rust-clippy/compare/1b89724...master)
8+
9+
## Rust 1.33 (2019-02-26)
10+
11+
[b2601be...1b89724](https://github.com/rust-lang/rust-clippy/compare/b2601be...1b89724)
12+
13+
* New lints: [`implicit_return`], [`vec_box`], [`cast_ref_to_mut`]
14+
* The `rust-clippy` repository is now part of the `rust-lang` org.
15+
* Rename `stutter` to `module_name_repetitions`
16+
* Merge `new_without_default_derive` into `new_without_default` lint
17+
* Move `large_digit_groups` from `style` group to `pedantic`
18+
* Expand `bool_comparison` to check for `<`, `<=`, `>`, `>=`, and `!=`
19+
comparisons against booleans
20+
* Expand `no_effect` to detect writes to constants such as `A_CONST.field = 2`
21+
* Expand `redundant_clone` to work on struct fields
22+
* Expand `suspicious_else_formatting` to detect `if .. {..} {..}`
23+
* Expand `use_self` to work on tuple structs and also in local macros
24+
* Fix ICE in `result_map_unit_fn` and `option_map_unit_fn`
25+
* Fix false positives in `implicit_return`
26+
* Fix false positives in `use_self`
27+
* Fix false negative in `clone_on_copy`
28+
* Fix false positive in `doc_markdown`
29+
* Fix false positive in `empty_loop`
30+
* Fix false positive in `if_same_then_else`
31+
* Fix false positive in `infinite_iter`
32+
* Fix false positive in `question_mark`
33+
* Fix false positive in `useless_asref`
34+
* Fix false positive in `wildcard_dependencies`
35+
* Fix false positive in `write_with_newline`
36+
* Add suggestion to `explicit_write`
37+
* Improve suggestions for `question_mark` lint
38+
* Fix incorrect suggestion for `get_unwrap`
839

940
## Rust 1.32 (2019-01-17)
1041

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ rustc_tools_util = { version = "0.1.1", path = "rustc_tools_util"}
4747
[dev-dependencies]
4848
clippy_dev = { version = "0.0.1", path = "clippy_dev" }
4949
cargo_metadata = "0.7.1"
50-
compiletest_rs = "0.3.18"
50+
compiletest_rs = "0.3.19"
5151
lazy_static = "1.0"
5252
serde_derive = "1.0"
5353
clippy-mini-macro-test = { version = "0.2", path = "mini-macro" }

ci/base-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ rustup override set nightly
5959
# avoid loop spam and allow cmds with exit status != 0
6060
set +ex
6161

62-
for file in `find tests -not -path "tests/ui/format.rs" -not -path "tests/ui/formatting.rs" -not -path "tests/ui/empty_line_after_outer_attribute.rs" -not -path "tests/ui/double_parens.rs" -not -path "tests/ui/doc.rs" -not -path "tests/ui/unused_unit.rs" | grep "\.rs$"` ; do
62+
for file in `find tests -not -path "tests/ui/doc.rs" -not -path "tests/ui/unused_unit.rs" | grep "\.rs$"` ; do
6363
rustfmt ${file} --check
6464
if [ $? -ne 0 ]; then
6565
echo "${file} needs reformatting!"

clippy_lints/src/consts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use if_chain::if_chain;
55
use rustc::hir::def::Def;
66
use rustc::hir::*;
77
use rustc::lint::LateContext;
8-
use rustc::ty::subst::{Subst, Substs};
8+
use rustc::ty::subst::{Subst, SubstsRef};
99
use rustc::ty::{self, Instance, Ty, TyCtxt};
1010
use rustc::{bug, span_bug};
1111
use rustc_data_structures::sync::Lrc;
@@ -209,7 +209,7 @@ pub struct ConstEvalLateContext<'a, 'tcx: 'a> {
209209
tables: &'a ty::TypeckTables<'tcx>,
210210
param_env: ty::ParamEnv<'tcx>,
211211
needed_resolution: bool,
212-
substs: &'tcx Substs<'tcx>,
212+
substs: SubstsRef<'tcx>,
213213
}
214214

215215
impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {

clippy_lints/src/copy_iterator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl LintPass for CopyIterator {
4444
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyIterator {
4545
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
4646
if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) = item.node {
47-
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.id));
47+
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id_from_hir_id(item.hir_id));
4848

4949
if is_copy(cx, ty) && match_path(&trait_ref.path, &paths::ITERATOR) {
5050
span_note_and_lint(

clippy_lints/src/derive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl LintPass for Derive {
7777
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Derive {
7878
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
7979
if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) = item.node {
80-
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.id));
80+
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id_from_hir_id(item.hir_id));
8181
let is_automatically_derived = is_automatically_derived(&*item.attrs);
8282

8383
check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived);

clippy_lints/src/empty_enum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl LintPass for EmptyEnum {
3838

3939
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EmptyEnum {
4040
fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item) {
41-
let did = cx.tcx.hir().local_def_id(item.id);
41+
let did = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id);
4242
if let ItemKind::Enum(..) = item.node {
4343
let ty = cx.tcx.type_of(did);
4444
let adt = ty.ty_adt_def().expect("already checked whether this is an enum");

clippy_lints/src/enum_clike.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc::hir::*;
77
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
88
use rustc::mir::interpret::GlobalId;
99
use rustc::ty;
10-
use rustc::ty::subst::Substs;
10+
use rustc::ty::subst::InternalSubsts;
1111
use rustc::ty::util::IntTypeExt;
1212
use rustc::{declare_tool_lint, lint_array};
1313
use syntax::ast::{IntTy, UintTy};
@@ -58,7 +58,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant {
5858
if let Some(ref anon_const) = variant.disr_expr {
5959
let param_env = ty::ParamEnv::empty();
6060
let def_id = cx.tcx.hir().body_owner_def_id(anon_const.body);
61-
let substs = Substs::identity_for_item(cx.tcx.global_tcx(), def_id);
61+
let substs = InternalSubsts::identity_for_item(cx.tcx.global_tcx(), def_id);
6262
let instance = ty::Instance::new(def_id, substs);
6363
let c_id = GlobalId {
6464
instance,

clippy_lints/src/escape.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ use rustc::middle::expr_use_visitor::*;
66
use rustc::middle::mem_categorization::{cmt_, Categorization};
77
use rustc::ty::layout::LayoutOf;
88
use rustc::ty::{self, Ty};
9-
use rustc::util::nodemap::NodeSet;
9+
use rustc::util::nodemap::HirIdSet;
1010
use rustc::{declare_tool_lint, lint_array};
11-
use syntax::ast::NodeId;
1211
use syntax::source_map::Span;
1312

1413
pub struct Pass {
@@ -44,7 +43,7 @@ fn is_non_trait_box(ty: Ty<'_>) -> bool {
4443

4544
struct EscapeDelegate<'a, 'tcx: 'a> {
4645
cx: &'a LateContext<'a, 'tcx>,
47-
set: NodeSet,
46+
set: HirIdSet,
4847
too_large_for_stack: u64,
4948
}
5049

@@ -80,7 +79,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
8079

8180
let mut v = EscapeDelegate {
8281
cx,
83-
set: NodeSet::default(),
82+
set: HirIdSet::default(),
8483
too_large_for_stack: self.too_large_for_stack,
8584
};
8685

@@ -92,7 +91,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
9291
span_lint(
9392
cx,
9493
BOXED_LOCAL,
95-
cx.tcx.hir().span(node),
94+
cx.tcx.hir().span_by_hir_id(node),
9695
"local variable doesn't need to be boxed here",
9796
);
9897
}
@@ -111,13 +110,13 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
111110
fn matched_pat(&mut self, _: &Pat, _: &cmt_<'tcx>, _: MatchMode) {}
112111
fn consume_pat(&mut self, consume_pat: &Pat, cmt: &cmt_<'tcx>, _: ConsumeMode) {
113112
let map = &self.cx.tcx.hir();
114-
if map.is_argument(consume_pat.id) {
113+
if map.is_argument(map.hir_to_node_id(consume_pat.hir_id)) {
115114
// Skip closure arguments
116-
if let Some(Node::Expr(..)) = map.find(map.get_parent_node(consume_pat.id)) {
115+
if let Some(Node::Expr(..)) = map.find_by_hir_id(map.get_parent_node_by_hir_id(consume_pat.hir_id)) {
117116
return;
118117
}
119118
if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) {
120-
self.set.insert(consume_pat.id);
119+
self.set.insert(consume_pat.hir_id);
121120
}
122121
return;
123122
}
@@ -129,7 +128,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
129128
if let ExprKind::Box(..) = ex.node {
130129
if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) {
131130
// let x = box (...)
132-
self.set.insert(consume_pat.id);
131+
self.set.insert(consume_pat.hir_id);
133132
}
134133
// TODO Box::new
135134
// TODO vec![]
@@ -143,7 +142,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
143142
if self.set.contains(&lid) {
144143
// let y = x where x is known
145144
// remove x, insert y
146-
self.set.insert(consume_pat.id);
145+
self.set.insert(consume_pat.hir_id);
147146
self.set.remove(&lid);
148147
}
149148
}
@@ -177,7 +176,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
177176
}
178177
}
179178
}
180-
fn decl_without_init(&mut self, _: NodeId, _: Span) {}
179+
fn decl_without_init(&mut self, _: HirId, _: Span) {}
181180
fn mutate(&mut self, _: HirId, _: Span, _: &cmt_<'tcx>, _: MutateMode) {}
182181
}
183182

clippy_lints/src/eta_reduction.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::utils::{is_adjusted, iter_input_pats, snippet_opt, span_lint_and_then, type_is_unsafe_function};
22
use if_chain::if_chain;
33
use rustc::hir::*;
4-
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
4+
use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass};
55
use rustc::ty;
66
use rustc::{declare_tool_lint, lint_array};
77
use rustc_errors::Applicability;
@@ -45,6 +45,10 @@ impl LintPass for EtaPass {
4545

4646
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EtaPass {
4747
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
48+
if in_external_macro(cx.sess(), expr.span) {
49+
return;
50+
}
51+
4852
match expr.node {
4953
ExprKind::Call(_, ref args) | ExprKind::MethodCall(_, _, ref args) => {
5054
for arg in args {
@@ -129,25 +133,30 @@ fn get_ufcs_type_name(
129133
let actual_type_of_self = &cx.tables.node_type(self_arg.hir_id).sty;
130134

131135
if let Some(trait_id) = cx.tcx.trait_of_item(method_def_id) {
132-
//if the method expectes &self, ufcs requires explicit borrowing so closure can't be removed
133-
return match (expected_type_of_self, actual_type_of_self) {
134-
(ty::Ref(_, _, _), ty::Ref(_, _, _)) => Some(cx.tcx.item_path_str(trait_id)),
135-
(l, r) => match (l, r) {
136-
(ty::Ref(_, _, _), _) | (_, ty::Ref(_, _, _)) => None,
137-
(_, _) => Some(cx.tcx.item_path_str(trait_id)),
138-
},
139-
};
136+
if match_borrow_depth(expected_type_of_self, actual_type_of_self) {
137+
return Some(cx.tcx.item_path_str(trait_id));
138+
}
140139
}
141140

142141
cx.tcx.impl_of_method(method_def_id).and_then(|_| {
143-
//a type may implicitly implement other types methods (e.g. Deref)
142+
//a type may implicitly implement other type's methods (e.g. Deref)
144143
if match_types(expected_type_of_self, actual_type_of_self) {
145144
return Some(get_type_name(cx, &actual_type_of_self));
146145
}
147146
None
148147
})
149148
}
150149

150+
fn match_borrow_depth(lhs: &ty::TyKind<'_>, rhs: &ty::TyKind<'_>) -> bool {
151+
match (lhs, rhs) {
152+
(ty::Ref(_, t1, _), ty::Ref(_, t2, _)) => match_borrow_depth(&t1.sty, &t2.sty),
153+
(l, r) => match (l, r) {
154+
(ty::Ref(_, _, _), _) | (_, ty::Ref(_, _, _)) => false,
155+
(_, _) => true,
156+
},
157+
}
158+
}
159+
151160
fn match_types(lhs: &ty::TyKind<'_>, rhs: &ty::TyKind<'_>) -> bool {
152161
match (lhs, rhs) {
153162
(ty::Bool, ty::Bool)

0 commit comments

Comments
 (0)