Skip to content

Commit 0e9321d

Browse files
committed
Auto merge of #9516 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
2 parents 0f6932a + d792c3a commit 0e9321d

File tree

103 files changed

+599
-502
lines changed

Some content is hidden

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

103 files changed

+599
-502
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy"
3-
version = "0.1.65"
3+
version = "0.1.66"
44
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
55
repository = "https://github.com/rust-lang/rust-clippy"
66
readme = "README.md"

clippy_dev/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![feature(let_chains)]
2-
#![feature(let_else)]
32
#![feature(once_cell)]
43
#![feature(rustc_private)]
54
#![cfg_attr(feature = "deny-warnings", deny(warnings))]

clippy_dev/src/new_lint.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,17 @@ fn add_lint(lint: &LintData<'_>, enable_msrv: bool) -> io::Result<()> {
120120

121121
let new_lint = if enable_msrv {
122122
format!(
123-
"store.register_{lint_pass}_pass(move || Box::new({module_name}::{camel_name}::new(msrv)));\n ",
123+
"store.register_{lint_pass}_pass(move |{ctor_arg}| Box::new({module_name}::{camel_name}::new(msrv)));\n ",
124124
lint_pass = lint.pass,
125+
ctor_arg = if lint.pass == "late" { "_" } else { "" },
125126
module_name = lint.name,
126127
camel_name = to_camel_case(lint.name),
127128
)
128129
} else {
129130
format!(
130-
"store.register_{lint_pass}_pass(|| Box::new({module_name}::{camel_name}));\n ",
131+
"store.register_{lint_pass}_pass(|{ctor_arg}| Box::new({module_name}::{camel_name}));\n ",
131132
lint_pass = lint.pass,
133+
ctor_arg = if lint.pass == "late" { "_" } else { "" },
132134
module_name = lint.name,
133135
camel_name = to_camel_case(lint.name),
134136
)

clippy_lints/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy_lints"
3-
version = "0.1.65"
3+
version = "0.1.66"
44
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
55
repository = "https://github.com/rust-lang/rust-clippy"
66
readme = "README.md"

clippy_lints/src/default.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl<'tcx> LateLintPass<'tcx> for Default {
142142
if adt.is_struct();
143143
let variant = adt.non_enum_variant();
144144
if adt.did().is_local() || !variant.is_field_list_non_exhaustive();
145-
let module_did = cx.tcx.parent_module(stmt.hir_id).to_def_id();
145+
let module_did = cx.tcx.parent_module(stmt.hir_id);
146146
if variant
147147
.fields
148148
.iter()

clippy_lints/src/default_union_representation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
22
use rustc_hir::{self as hir, HirId, Item, ItemKind};
3+
use rustc_hir_analysis::hir_ty_to_ty;
34
use rustc_lint::{LateContext, LateLintPass};
45
use rustc_middle::ty::layout::LayoutOf;
56
use rustc_session::{declare_lint_pass, declare_tool_lint};
67
use rustc_span::sym;
7-
use rustc_typeck::hir_ty_to_ty;
88

99
declare_clippy_lint! {
1010
/// ### What it does

clippy_lints/src/dereference.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_infer::infer::TyCtxtInferExt;
2020
use rustc_lint::{LateContext, LateLintPass};
2121
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability};
2222
use rustc_middle::ty::{
23-
self, subst::Subst, Binder, BoundVariableKind, EarlyBinder, FnSig, GenericArgKind, List, ParamTy, PredicateKind,
23+
self, Binder, BoundVariableKind, EarlyBinder, FnSig, GenericArgKind, List, ParamTy, PredicateKind,
2424
ProjectionPredicate, Ty, TyCtxt, TypeVisitable, TypeckResults,
2525
};
2626
use rustc_semver::RustcVersion;
@@ -704,7 +704,7 @@ fn walk_parents<'tcx>(
704704
span,
705705
..
706706
}) if span.ctxt() == ctxt => {
707-
let ty = cx.tcx.type_of(def_id);
707+
let ty = cx.tcx.type_of(def_id.def_id);
708708
Some(ty_auto_deref_stability(cx, ty, precedence).position_for_result(cx))
709709
},
710710

clippy_lints/src/derive.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_middle::hir::nested_filter;
1515
use rustc_middle::traits::Reveal;
1616
use rustc_middle::ty::{
1717
self, Binder, BoundConstness, GenericParamDefKind, ImplPolarity, ParamEnv, PredicateKind, TraitPredicate, TraitRef,
18-
Ty, TyCtxt, Visibility,
18+
Ty, TyCtxt,
1919
};
2020
use rustc_session::{declare_lint_pass, declare_tool_lint};
2121
use rustc_span::source_map::Span;
@@ -425,7 +425,7 @@ struct UnsafeVisitor<'a, 'tcx> {
425425
impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> {
426426
type NestedFilter = nested_filter::All;
427427

428-
fn visit_fn(&mut self, kind: FnKind<'tcx>, decl: &'tcx FnDecl<'_>, body_id: BodyId, span: Span, id: HirId) {
428+
fn visit_fn(&mut self, kind: FnKind<'tcx>, decl: &'tcx FnDecl<'_>, body_id: BodyId, _: Span, id: HirId) {
429429
if self.has_unsafe {
430430
return;
431431
}
@@ -438,7 +438,7 @@ impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> {
438438
}
439439
}
440440

441-
walk_fn(self, kind, decl, body_id, span, id);
441+
walk_fn(self, kind, decl, body_id, id);
442442
}
443443

444444
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
@@ -464,7 +464,7 @@ impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> {
464464
fn check_partial_eq_without_eq<'tcx>(cx: &LateContext<'tcx>, span: Span, trait_ref: &hir::TraitRef<'_>, ty: Ty<'tcx>) {
465465
if_chain! {
466466
if let ty::Adt(adt, substs) = ty.kind();
467-
if cx.tcx.visibility(adt.did()) == Visibility::Public;
467+
if cx.tcx.visibility(adt.did()).is_public();
468468
if let Some(eq_trait_def_id) = cx.tcx.get_diagnostic_item(sym::Eq);
469469
if let Some(def_id) = trait_ref.trait_def_id();
470470
if cx.tcx.is_diagnostic_item(sym::PartialEq, def_id);

clippy_lints/src/disallowed_types.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
22

33
use rustc_data_structures::fx::FxHashMap;
4-
use rustc_hir::{
5-
def::Res, def_id::DefId, Item, ItemKind, PolyTraitRef, PrimTy, TraitBoundModifier, Ty, TyKind, UseKind,
6-
};
4+
use rustc_hir::{def::Res, def_id::DefId, Item, ItemKind, PolyTraitRef, PrimTy, Ty, TyKind, UseKind};
75
use rustc_lint::{LateContext, LateLintPass};
86
use rustc_session::{declare_tool_lint, impl_lint_pass};
97
use rustc_span::Span;
@@ -120,7 +118,7 @@ impl<'tcx> LateLintPass<'tcx> for DisallowedTypes {
120118
}
121119
}
122120

123-
fn check_poly_trait_ref(&mut self, cx: &LateContext<'tcx>, poly: &'tcx PolyTraitRef<'tcx>, _: TraitBoundModifier) {
121+
fn check_poly_trait_ref(&mut self, cx: &LateContext<'tcx>, poly: &'tcx PolyTraitRef<'tcx>) {
124122
self.check_res_emit(cx, &poly.trait_ref.path.res, poly.trait_ref.path.span);
125123
}
126124
}

clippy_lints/src/doc.rs

+21-5
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,19 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
233233
let body = cx.tcx.hir().body(body_id);
234234
let mut fpu = FindPanicUnwrap {
235235
cx,
236-
typeck_results: cx.tcx.typeck(item.def_id),
236+
typeck_results: cx.tcx.typeck(item.def_id.def_id),
237237
panic_span: None,
238238
};
239239
fpu.visit_expr(body.value);
240-
lint_for_missing_headers(cx, item.def_id, item.span, sig, headers, Some(body_id), fpu.panic_span);
240+
lint_for_missing_headers(
241+
cx,
242+
item.def_id.def_id,
243+
item.span,
244+
sig,
245+
headers,
246+
Some(body_id),
247+
fpu.panic_span,
248+
);
241249
}
242250
},
243251
hir::ItemKind::Impl(impl_) => {
@@ -268,7 +276,7 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
268276
let headers = check_attrs(cx, &self.valid_idents, attrs);
269277
if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind {
270278
if !in_external_macro(cx.tcx.sess, item.span) {
271-
lint_for_missing_headers(cx, item.def_id, item.span, sig, headers, None, None);
279+
lint_for_missing_headers(cx, item.def_id.def_id, item.span, sig, headers, None, None);
272280
}
273281
}
274282
}
@@ -283,11 +291,19 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
283291
let body = cx.tcx.hir().body(body_id);
284292
let mut fpu = FindPanicUnwrap {
285293
cx,
286-
typeck_results: cx.tcx.typeck(item.def_id),
294+
typeck_results: cx.tcx.typeck(item.def_id.def_id),
287295
panic_span: None,
288296
};
289297
fpu.visit_expr(body.value);
290-
lint_for_missing_headers(cx, item.def_id, item.span, sig, headers, Some(body_id), fpu.panic_span);
298+
lint_for_missing_headers(
299+
cx,
300+
item.def_id.def_id,
301+
item.span,
302+
sig,
303+
headers,
304+
Some(body_id),
305+
fpu.panic_span,
306+
);
291307
}
292308
}
293309
}

clippy_lints/src/enum_variants.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ impl LateLintPass<'_> for EnumVariantNames {
296296
}
297297
}
298298
if let ItemKind::Enum(ref def, _) = item.kind {
299-
if !(self.avoid_breaking_exported_api && cx.access_levels.is_exported(item.def_id)) {
299+
if !(self.avoid_breaking_exported_api && cx.access_levels.is_exported(item.def_id.def_id)) {
300300
check_variant(cx, self.threshold, def, item_name, item.span);
301301
}
302302
}

clippy_lints/src/equatable_if_let.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn unary_pattern(pat: &Pat<'_>) -> bool {
5151
false
5252
},
5353
PatKind::Struct(_, a, etc) => !etc && a.iter().all(|x| unary_pattern(x.pat)),
54-
PatKind::Tuple(a, etc) | PatKind::TupleStruct(_, a, etc) => !etc.is_some() && array_rec(a),
54+
PatKind::Tuple(a, etc) | PatKind::TupleStruct(_, a, etc) => etc.as_opt_usize().is_none() && array_rec(a),
5555
PatKind::Ref(x, _) | PatKind::Box(x) => unary_pattern(x),
5656
PatKind::Path(_) | PatKind::Lit(_) => true,
5757
}

clippy_lints/src/escape.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_hir;
22
use rustc_hir::intravisit;
33
use rustc_hir::{self, AssocItemKind, Body, FnDecl, HirId, HirIdSet, Impl, ItemKind, Node, Pat, PatKind};
4+
use rustc_hir_analysis::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
45
use rustc_infer::infer::TyCtxtInferExt;
56
use rustc_lint::{LateContext, LateLintPass};
67
use rustc_middle::mir::FakeReadCause;
@@ -10,7 +11,6 @@ use rustc_session::{declare_tool_lint, impl_lint_pass};
1011
use rustc_span::source_map::Span;
1112
use rustc_span::symbol::kw;
1213
use rustc_target::spec::abi::Abi;
13-
use rustc_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
1414

1515
#[derive(Copy, Clone)]
1616
pub struct BoxedLocal {
@@ -71,7 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
7171
}
7272
}
7373

74-
let parent_id = cx.tcx.hir().get_parent_item(hir_id);
74+
let parent_id = cx.tcx.hir().get_parent_item(hir_id).def_id;
7575
let parent_node = cx.tcx.hir().find_by_def_id(parent_id);
7676

7777
let mut trait_self_ty = None;
@@ -177,7 +177,13 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
177177
}
178178
}
179179

180-
fn fake_read(&mut self, _: &rustc_typeck::expr_use_visitor::PlaceWithHirId<'tcx>, _: FakeReadCause, _: HirId) {}
180+
fn fake_read(
181+
&mut self,
182+
_: &rustc_hir_analysis::expr_use_visitor::PlaceWithHirId<'tcx>,
183+
_: FakeReadCause,
184+
_: HirId,
185+
) {
186+
}
181187
}
182188

183189
impl<'a, 'tcx> EscapeDelegate<'a, 'tcx> {

clippy_lints/src/eta_reduction.rs

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use rustc_hir::{Closure, Expr, ExprKind, Param, PatKind, Unsafety};
1111
use rustc_lint::{LateContext, LateLintPass};
1212
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow};
1313
use rustc_middle::ty::binding::BindingMode;
14-
use rustc_middle::ty::subst::Subst;
1514
use rustc_middle::ty::{self, ClosureKind, Ty, TypeVisitable};
1615
use rustc_session::{declare_lint_pass, declare_tool_lint};
1716
use rustc_span::symbol::sym;

clippy_lints/src/exhaustive_items.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl LateLintPass<'_> for ExhaustiveItems {
7373
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
7474
if_chain! {
7575
if let ItemKind::Enum(..) | ItemKind::Struct(..) = item.kind;
76-
if cx.access_levels.is_exported(item.def_id);
76+
if cx.access_levels.is_exported(item.def_id.def_id);
7777
let attrs = cx.tcx.hir().attrs(item.hir_id());
7878
if !attrs.iter().any(|a| a.has_name(sym::non_exhaustive));
7979
then {

clippy_lints/src/exit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl<'tcx> LateLintPass<'tcx> for Exit {
3333
if let ExprKind::Path(ref path) = path_expr.kind;
3434
if let Some(def_id) = cx.qpath_res(path, path_expr.hir_id).opt_def_id();
3535
if match_def_path(cx, def_id, &paths::EXIT);
36-
let parent = cx.tcx.hir().get_parent_item(e.hir_id);
36+
let parent = cx.tcx.hir().get_parent_item(e.hir_id).def_id;
3737
if let Some(Node::Item(Item{kind: ItemKind::Fn(..), ..})) = cx.tcx.hir().find_by_def_id(parent);
3838
// If the next item up is a function we check if it is an entry point
3939
// and only then emit a linter warning

clippy_lints/src/fallible_impl_from.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[h
107107
let body = cx.tcx.hir().body(body_id);
108108
let mut fpu = FindPanicUnwrap {
109109
lcx: cx,
110-
typeck_results: cx.tcx.typeck(impl_item.id.def_id),
110+
typeck_results: cx.tcx.typeck(impl_item.id.def_id.def_id),
111111
result: Vec::new(),
112112
};
113113
fpu.visit_expr(body.value);

clippy_lints/src/functions/must_use.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>
2121
let attrs = cx.tcx.hir().attrs(item.hir_id());
2222
let attr = cx.tcx.get_attr(item.def_id.to_def_id(), sym::must_use);
2323
if let hir::ItemKind::Fn(ref sig, _generics, ref body_id) = item.kind {
24-
let is_public = cx.access_levels.is_exported(item.def_id);
24+
let is_public = cx.access_levels.is_exported(item.def_id.def_id);
2525
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
2626
if let Some(attr) = attr {
2727
check_needless_must_use(cx, sig.decl, item.hir_id(), item.span, fn_header_span, attr);
@@ -31,7 +31,7 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>
3131
sig.decl,
3232
cx.tcx.hir().body(*body_id),
3333
item.span,
34-
item.def_id,
34+
item.def_id.def_id,
3535
item.span.with_hi(sig.decl.output.span().hi()),
3636
"this function could have a `#[must_use]` attribute",
3737
);
@@ -41,19 +41,20 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>
4141

4242
pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) {
4343
if let hir::ImplItemKind::Fn(ref sig, ref body_id) = item.kind {
44-
let is_public = cx.access_levels.is_exported(item.def_id);
44+
let is_public = cx.access_levels.is_exported(item.def_id.def_id);
4545
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
4646
let attrs = cx.tcx.hir().attrs(item.hir_id());
4747
let attr = cx.tcx.get_attr(item.def_id.to_def_id(), sym::must_use);
4848
if let Some(attr) = attr {
4949
check_needless_must_use(cx, sig.decl, item.hir_id(), item.span, fn_header_span, attr);
50-
} else if is_public && !is_proc_macro(cx.sess(), attrs) && trait_ref_of_method(cx, item.def_id).is_none() {
50+
} else if is_public && !is_proc_macro(cx.sess(), attrs) && trait_ref_of_method(cx, item.def_id.def_id).is_none()
51+
{
5152
check_must_use_candidate(
5253
cx,
5354
sig.decl,
5455
cx.tcx.hir().body(*body_id),
5556
item.span,
56-
item.def_id,
57+
item.def_id.def_id,
5758
item.span.with_hi(sig.decl.output.span().hi()),
5859
"this method could have a `#[must_use]` attribute",
5960
);
@@ -63,7 +64,7 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Imp
6364

6465
pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) {
6566
if let hir::TraitItemKind::Fn(ref sig, ref eid) = item.kind {
66-
let is_public = cx.access_levels.is_exported(item.def_id);
67+
let is_public = cx.access_levels.is_exported(item.def_id.def_id);
6768
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
6869

6970
let attrs = cx.tcx.hir().attrs(item.hir_id());
@@ -78,7 +79,7 @@ pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Tr
7879
sig.decl,
7980
body,
8081
item.span,
81-
item.def_id,
82+
item.def_id.def_id,
8283
item.span.with_hi(sig.decl.output.span().hi()),
8384
"this method could have a `#[must_use]` attribute",
8485
);
@@ -171,7 +172,7 @@ fn is_mutable_pat(cx: &LateContext<'_>, pat: &hir::Pat<'_>, tys: &mut DefIdSet)
171172
return false; // ignore `_` patterns
172173
}
173174
if cx.tcx.has_typeck_results(pat.hir_id.owner.to_def_id()) {
174-
is_mutable_ty(cx, cx.tcx.typeck(pat.hir_id.owner).pat_ty(pat), pat.span, tys)
175+
is_mutable_ty(cx, cx.tcx.typeck(pat.hir_id.owner.def_id).pat_ty(pat), pat.span, tys)
175176
} else {
176177
false
177178
}
@@ -218,7 +219,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> {
218219
if self.cx.tcx.has_typeck_results(arg.hir_id.owner.to_def_id())
219220
&& is_mutable_ty(
220221
self.cx,
221-
self.cx.tcx.typeck(arg.hir_id.owner).expr_ty(arg),
222+
self.cx.tcx.typeck(arg.hir_id.owner.def_id).expr_ty(arg),
222223
arg.span,
223224
&mut tys,
224225
)
@@ -236,7 +237,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> {
236237
if self.cx.tcx.has_typeck_results(arg.hir_id.owner.to_def_id())
237238
&& is_mutable_ty(
238239
self.cx,
239-
self.cx.tcx.typeck(arg.hir_id.owner).expr_ty(arg),
240+
self.cx.tcx.typeck(arg.hir_id.owner.def_id).expr_ty(arg),
240241
arg.span,
241242
&mut tys,
242243
)

clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub(super) fn check_fn<'tcx>(
2828
pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) {
2929
if let hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(eid)) = item.kind {
3030
let body = cx.tcx.hir().body(eid);
31-
check_raw_ptr(cx, sig.header.unsafety, sig.decl, body, item.def_id);
31+
check_raw_ptr(cx, sig.header.unsafety, sig.decl, body, item.def_id.def_id);
3232
}
3333
}
3434

0 commit comments

Comments
 (0)