Skip to content

Commit 97a5daa

Browse files
committed
Auto merge of rust-lang#8272 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
2 parents 60e68d6 + 6ad05bc commit 97a5daa

27 files changed

+139
-93
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.59"
3+
version = "0.1.60"
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/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy_lints"
3-
version = "0.1.59"
3+
version = "0.1.60"
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"
@@ -13,7 +13,7 @@ cargo_metadata = "0.14"
1313
clippy_utils = { path = "../clippy_utils" }
1414
if_chain = "1.0"
1515
itertools = "0.10"
16-
pulldown-cmark = { version = "0.8", default-features = false }
16+
pulldown-cmark = { version = "0.9", default-features = false }
1717
quine-mc_cluskey = "0.2"
1818
regex-syntax = "0.6"
1919
serde = { version = "1.0", features = ["derive"] }

clippy_lints/src/default.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl<'tcx> LateLintPass<'tcx> for Default {
198198
let ext_with_default = !variant
199199
.fields
200200
.iter()
201-
.all(|field| assigned_fields.iter().any(|(a, _)| a == &field.ident.name));
201+
.all(|field| assigned_fields.iter().any(|(a, _)| a == &field.name));
202202

203203
let field_list = assigned_fields
204204
.into_iter()

clippy_lints/src/default_numeric_fallback.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
161161
fields_def
162162
.iter()
163163
.find_map(|f_def| {
164-
if f_def.ident == field.ident
164+
if f_def.ident(self.cx.tcx) == field.ident
165165
{ Some(self.cx.tcx.type_of(f_def.did)) }
166166
else { None }
167167
});

clippy_lints/src/doc.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -543,16 +543,16 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
543543
},
544544
Start(Link(_, url, _)) => in_link = Some(url),
545545
End(Link(..)) => in_link = None,
546-
Start(Heading(_) | Paragraph | Item) => {
547-
if let Start(Heading(_)) = event {
546+
Start(Heading(_, _, _) | Paragraph | Item) => {
547+
if let Start(Heading(_, _, _)) = event {
548548
in_heading = true;
549549
}
550550
ticks_unbalanced = false;
551551
let (_, span) = get_current_span(spans, range.start);
552552
paragraph_span = first_line_of_span(cx, span);
553553
},
554-
End(Heading(_) | Paragraph | Item) => {
555-
if let End(Heading(_)) = event {
554+
End(Heading(_, _, _) | Paragraph | Item) => {
555+
if let End(Heading(_, _, _)) = event {
556556
in_heading = false;
557557
}
558558
if ticks_unbalanced {

clippy_lints/src/inconsistent_struct_constructor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl<'tcx> LateLintPass<'tcx> for InconsistentStructConstructor {
7676
then {
7777
let mut def_order_map = FxHashMap::default();
7878
for (idx, field) in variant.fields.iter().enumerate() {
79-
def_order_map.insert(field.ident.name, idx);
79+
def_order_map.insert(field.name, idx);
8080
}
8181

8282
if is_consistent_order(fields, &def_order_map) {

clippy_lints/src/len_zero.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,14 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items
214214
{
215215
let mut current_and_super_traits = DefIdSet::default();
216216
fill_trait_set(visited_trait.def_id.to_def_id(), &mut current_and_super_traits, cx);
217+
let is_empty = sym!(is_empty);
217218

218219
let is_empty_method_found = current_and_super_traits
219220
.iter()
220-
.flat_map(|&i| cx.tcx.associated_items(i).in_definition_order())
221+
.flat_map(|&i| cx.tcx.associated_items(i).filter_by_name_unhygienic(is_empty))
221222
.any(|i| {
222223
i.kind == ty::AssocKind::Fn
223224
&& i.fn_has_self_parameter
224-
&& i.ident.name == sym!(is_empty)
225225
&& cx.tcx.fn_sig(i.def_id).inputs().skip_binder().len() == 1
226226
});
227227

@@ -458,7 +458,7 @@ fn is_empty_array(expr: &Expr<'_>) -> bool {
458458
fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
459459
/// Gets an `AssocItem` and return true if it matches `is_empty(self)`.
460460
fn is_is_empty(cx: &LateContext<'_>, item: &ty::AssocItem) -> bool {
461-
if item.kind == ty::AssocKind::Fn && item.ident.name.as_str() == "is_empty" {
461+
if item.kind == ty::AssocKind::Fn {
462462
let sig = cx.tcx.fn_sig(item.def_id);
463463
let ty = sig.skip_binder();
464464
ty.inputs().len() == 1
@@ -469,20 +469,22 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
469469

470470
/// Checks the inherent impl's items for an `is_empty(self)` method.
471471
fn has_is_empty_impl(cx: &LateContext<'_>, id: DefId) -> bool {
472+
let is_empty = sym!(is_empty);
472473
cx.tcx.inherent_impls(id).iter().any(|imp| {
473474
cx.tcx
474475
.associated_items(*imp)
475-
.in_definition_order()
476+
.filter_by_name_unhygienic(is_empty)
476477
.any(|item| is_is_empty(cx, item))
477478
})
478479
}
479480

480481
let ty = &cx.typeck_results().expr_ty(expr).peel_refs();
481482
match ty.kind() {
482483
ty::Dynamic(tt, ..) => tt.principal().map_or(false, |principal| {
484+
let is_empty = sym!(is_empty);
483485
cx.tcx
484486
.associated_items(principal.def_id())
485-
.in_definition_order()
487+
.filter_by_name_unhygienic(is_empty)
486488
.any(|item| is_is_empty(cx, item))
487489
}),
488490
ty::Projection(ref proj) => has_is_empty_impl(cx, proj.item_def_id),

clippy_lints/src/macro_use.rs

+7-12
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use rustc_errors::Applicability;
88
use rustc_hir as hir;
99
use rustc_lint::{LateContext, LateLintPass, LintContext};
1010
use rustc_session::{declare_tool_lint, impl_lint_pass};
11-
use rustc_span::hygiene::ExpnKind;
1211
use rustc_span::{edition::Edition, sym, Span};
1312

1413
declare_clippy_lint! {
@@ -97,42 +96,42 @@ impl<'tcx> LateLintPass<'tcx> for MacroUseImports {
9796
if let Res::Def(DefKind::Mod, id) = path.res;
9897
if !id.is_local();
9998
then {
100-
for kid in cx.tcx.item_children(id).iter() {
99+
for kid in cx.tcx.module_children(id).iter() {
101100
if let Res::Def(DefKind::Macro(_mac_type), mac_id) = kid.res {
102101
let span = mac_attr.span;
103102
let def_path = cx.tcx.def_path_str(mac_id);
104103
self.imports.push((def_path, span));
105104
}
106105
}
107106
} else {
108-
if in_macro(item.span) {
107+
if item.span.from_expansion() {
109108
self.push_unique_macro_pat_ty(cx, item.span);
110109
}
111110
}
112111
}
113112
}
114113
fn check_attribute(&mut self, cx: &LateContext<'_>, attr: &ast::Attribute) {
115-
if in_macro(attr.span) {
114+
if attr.span.from_expansion() {
116115
self.push_unique_macro(cx, attr.span);
117116
}
118117
}
119118
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &hir::Expr<'_>) {
120-
if in_macro(expr.span) {
119+
if expr.span.from_expansion() {
121120
self.push_unique_macro(cx, expr.span);
122121
}
123122
}
124123
fn check_stmt(&mut self, cx: &LateContext<'_>, stmt: &hir::Stmt<'_>) {
125-
if in_macro(stmt.span) {
124+
if stmt.span.from_expansion() {
126125
self.push_unique_macro(cx, stmt.span);
127126
}
128127
}
129128
fn check_pat(&mut self, cx: &LateContext<'_>, pat: &hir::Pat<'_>) {
130-
if in_macro(pat.span) {
129+
if pat.span.from_expansion() {
131130
self.push_unique_macro_pat_ty(cx, pat.span);
132131
}
133132
}
134133
fn check_ty(&mut self, cx: &LateContext<'_>, ty: &hir::Ty<'_>) {
135-
if in_macro(ty.span) {
134+
if ty.span.from_expansion() {
136135
self.push_unique_macro_pat_ty(cx, ty.span);
137136
}
138137
}
@@ -214,7 +213,3 @@ impl<'tcx> LateLintPass<'tcx> for MacroUseImports {
214213
}
215214
}
216215
}
217-
218-
fn in_macro(span: Span) -> bool {
219-
span.from_expansion() && !matches!(span.ctxt().outer_expn_data().kind, ExpnKind::Desugaring(..))
220-
}

clippy_lints/src/matches.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ fn check_wild_enum_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>])
11381138
s.push_str("::");
11391139
s
11401140
},
1141-
variant.ident.name,
1141+
variant.name,
11421142
match variant.ctor_kind {
11431143
CtorKind::Fn if variant.fields.len() == 1 => "(_)",
11441144
CtorKind::Fn => "(..)",

clippy_lints/src/non_copy_const.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ use rustc_hir::def_id::DefId;
1212
use rustc_hir::{
1313
BodyId, Expr, ExprKind, HirId, Impl, ImplItem, ImplItemKind, Item, ItemKind, Node, TraitItem, TraitItemKind, UnOp,
1414
};
15-
use rustc_infer::traits::specialization_graph;
1615
use rustc_lint::{LateContext, LateLintPass, Lint};
1716
use rustc_middle::mir::interpret::{ConstValue, ErrorHandled};
1817
use rustc_middle::ty::adjustment::Adjust;
19-
use rustc_middle::ty::{self, AssocKind, Const, Ty};
18+
use rustc_middle::ty::{self, Const, Ty};
2019
use rustc_session::{declare_lint_pass, declare_tool_lint};
2120
use rustc_span::{InnerSpan, Span, DUMMY_SP};
2221
use rustc_typeck::hir_ty_to_ty;
@@ -293,8 +292,10 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst {
293292
// Lint a trait impl item only when the definition is a generic type,
294293
// assuming an assoc const is not meant to be an interior mutable type.
295294
if let Some(of_trait_def_id) = of_trait_ref.trait_def_id();
296-
if let Some(of_assoc_item) = specialization_graph::Node::Trait(of_trait_def_id)
297-
.item(cx.tcx, impl_item.ident, AssocKind::Const, of_trait_def_id);
295+
if let Some(of_assoc_item) = cx
296+
.tcx
297+
.associated_item(impl_item.def_id)
298+
.trait_item_def_id;
298299
if cx
299300
.tcx
300301
.layout_of(cx.tcx.param_env(of_trait_def_id).and(
@@ -303,7 +304,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst {
303304
// and, in that case, the definition is *not* generic.
304305
cx.tcx.normalize_erasing_regions(
305306
cx.tcx.param_env(of_trait_def_id),
306-
cx.tcx.type_of(of_assoc_item.def_id),
307+
cx.tcx.type_of(of_assoc_item),
307308
),
308309
))
309310
.is_err();

clippy_lints/src/trailing_empty_array.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn is_struct_with_trailing_zero_sized_array(cx: &LateContext<'_>, item: &Item<'_
5858
// First check if last field is an array
5959
if let ItemKind::Struct(data, _) = &item.kind;
6060
if let Some(last_field) = data.fields().last();
61-
if let rustc_hir::TyKind::Array(_, length) = last_field.ty.kind;
61+
if let rustc_hir::TyKind::Array(_, rustc_hir::ArrayLen::Body(length)) = last_field.ty.kind;
6262

6363
// Then check if that that array zero-sized
6464
let length_ldid = cx.tcx.hir().local_def_id(length.hir_id);

clippy_lints/src/use_self.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use rustc_hir::{
1313
};
1414
use rustc_lint::{LateContext, LateLintPass, LintContext};
1515
use rustc_middle::hir::map::Map;
16-
use rustc_middle::ty::AssocKind;
1716
use rustc_semver::RustcVersion;
1817
use rustc_session::{declare_tool_lint, impl_lint_pass};
1918
use rustc_span::Span;
@@ -143,10 +142,10 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
143142
// trait, not in the impl of the trait.
144143
let trait_method = cx
145144
.tcx
146-
.associated_items(impl_trait_ref.def_id)
147-
.find_by_name_and_kind(cx.tcx, impl_item.ident, AssocKind::Fn, impl_trait_ref.def_id)
145+
.associated_item(impl_item.def_id)
146+
.trait_item_def_id
148147
.expect("impl method matches a trait method");
149-
let trait_method_sig = cx.tcx.fn_sig(trait_method.def_id);
148+
let trait_method_sig = cx.tcx.fn_sig(trait_method);
150149
let trait_method_sig = cx.tcx.erase_late_bound_regions(trait_method_sig);
151150

152151
// `impl_inputs_outputs` is an iterator over the types (`hir::Ty`) declared in the

clippy_lints/src/utils/author.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_ast::ast::{LitFloatType, LitKind};
66
use rustc_ast::LitIntType;
77
use rustc_data_structures::fx::FxHashMap;
88
use rustc_hir as hir;
9-
use rustc_hir::{ExprKind, FnRetTy, HirId, Lit, PatKind, QPath, StmtKind, TyKind};
9+
use rustc_hir::{ArrayLen, ExprKind, FnRetTy, HirId, Lit, PatKind, QPath, StmtKind, TyKind};
1010
use rustc_lint::{LateContext, LateLintPass, LintContext};
1111
use rustc_session::{declare_lint_pass, declare_tool_lint};
1212
use rustc_span::symbol::{Ident, Symbol};
@@ -567,7 +567,14 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
567567
bind!(self, value, length);
568568
kind!("Repeat({value}, {length})");
569569
self.expr(value);
570-
self.body(field!(length.body));
570+
match length.value {
571+
ArrayLen::Infer(..) => out!("if let ArrayLen::Infer(..) = length;"),
572+
ArrayLen::Body(anon_const) => {
573+
bind!(self, anon_const);
574+
out!("if let ArrayLen::Body({anon_const}) = {length};");
575+
self.body(field!(anon_const.body));
576+
},
577+
}
571578
},
572579
ExprKind::Err => kind!("Err"),
573580
ExprKind::DropTemps(expr) => {

clippy_lints/src/utils/inspector.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,17 @@ fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) {
334334
println!("{}anon_const:", ind);
335335
print_expr(cx, &cx.tcx.hir().body(anon_const.body).value, indent + 1);
336336
},
337-
hir::ExprKind::Repeat(val, ref anon_const) => {
337+
hir::ExprKind::Repeat(val, length) => {
338338
println!("{}Repeat", ind);
339339
println!("{}value:", ind);
340340
print_expr(cx, val, indent + 1);
341341
println!("{}repeat count:", ind);
342-
print_expr(cx, &cx.tcx.hir().body(anon_const.body).value, indent + 1);
342+
match length {
343+
hir::ArrayLen::Infer(_, _) => println!("{}repeat count: _", ind),
344+
hir::ArrayLen::Body(anon_const) => {
345+
print_expr(cx, &cx.tcx.hir().body(anon_const.body).value, indent + 1);
346+
},
347+
}
343348
},
344349
hir::ExprKind::Err => {
345350
println!("{}Err", ind);

clippy_lints/src/utils/internal_lints.rs

+15-4
Original file line numberDiff line numberDiff line change
@@ -929,9 +929,20 @@ pub fn check_path(cx: &LateContext<'_>, path: &[&str]) -> bool {
929929
let lang_item_path = cx.get_def_path(*item_def_id);
930930
if path_syms.starts_with(&lang_item_path) {
931931
if let [item] = &path_syms[lang_item_path.len()..] {
932-
for child in cx.tcx.item_children(*item_def_id) {
933-
if child.ident.name == *item {
934-
return true;
932+
if matches!(
933+
cx.tcx.def_kind(*item_def_id),
934+
DefKind::Mod | DefKind::Enum | DefKind::Trait
935+
) {
936+
for child in cx.tcx.module_children(*item_def_id) {
937+
if child.ident.name == *item {
938+
return true;
939+
}
940+
}
941+
} else {
942+
for child in cx.tcx.associated_item_def_ids(*item_def_id) {
943+
if cx.tcx.item_name(*child) == *item {
944+
return true;
945+
}
935946
}
936947
}
937948
}
@@ -989,7 +1000,7 @@ impl<'tcx> LateLintPass<'tcx> for InterningDefinedSymbol {
9891000

9901001
for &module in &[&paths::KW_MODULE, &paths::SYM_MODULE] {
9911002
if let Some(def_id) = path_to_res(cx, module).opt_def_id() {
992-
for item in cx.tcx.item_children(def_id).iter() {
1003+
for item in cx.tcx.module_children(def_id).iter() {
9931004
if_chain! {
9941005
if let Res::Def(DefKind::Const, item_def_id) = item.res;
9951006
let ty = cx.tcx.type_of(item_def_id);

clippy_utils/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy_utils"
3-
version = "0.1.59"
3+
version = "0.1.60"
44
edition = "2021"
55
publish = false
66

0 commit comments

Comments
 (0)