Skip to content

Commit 1db89a1

Browse files
authored
Rustup (#15341)
r? @ghost changelog: none
2 parents e85b1dd + d0fa808 commit 1db89a1

File tree

88 files changed

+972
-457
lines changed

Some content is hidden

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

88 files changed

+972
-457
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ out
1919

2020
# Generated by Cargo
2121
*Cargo.lock
22+
!/clippy_test_deps/Cargo.lock
2223
/target
2324
/clippy_lints/target
25+
/clippy_lints_internal/target
2426
/clippy_utils/target
2527
/clippy_dev/target
2628
/lintcheck/target

clippy_dev/src/fmt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::utils::{
33
walk_dir_no_dot_or_target,
44
};
55
use itertools::Itertools;
6-
use rustc_lexer::{TokenKind, tokenize};
6+
use rustc_lexer::{FrontmatterAllowed, TokenKind, tokenize};
77
use std::fmt::Write;
88
use std::fs;
99
use std::io::{self, Read};
@@ -92,7 +92,7 @@ fn fmt_conf(check: bool) -> Result<(), Error> {
9292
let mut fields = Vec::new();
9393
let mut state = State::Start;
9494

95-
for (i, t) in tokenize(conf)
95+
for (i, t) in tokenize(conf, FrontmatterAllowed::No)
9696
.map(|x| {
9797
let start = pos;
9898
pos += x.len;

clippy_lints/src/arbitrary_source_item_ordering.rs

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ use clippy_utils::diagnostics::span_lint_and_note;
88
use clippy_utils::is_cfg_test;
99
use rustc_attr_data_structures::AttributeKind;
1010
use rustc_hir::{
11-
AssocItemKind, Attribute, FieldDef, HirId, ImplItemRef, IsAuto, Item, ItemKind, Mod, QPath, TraitItemRef, TyKind,
12-
Variant, VariantData,
11+
Attribute, FieldDef, HirId, ImplItemId, IsAuto, Item, ItemKind, Mod, OwnerId, QPath, TraitItemId, TyKind, Variant,
12+
VariantData,
1313
};
1414
use rustc_lint::{LateContext, LateLintPass, LintContext};
15+
use rustc_middle::ty::AssocKind;
1516
use rustc_session::impl_lint_pass;
17+
use rustc_span::Ident;
1618

1719
declare_clippy_lint! {
1820
/// ### What it does
@@ -194,22 +196,22 @@ impl ArbitrarySourceItemOrdering {
194196
}
195197

196198
/// Produces a linting warning for incorrectly ordered impl items.
197-
fn lint_impl_item<T: LintContext>(&self, cx: &T, item: &ImplItemRef, before_item: &ImplItemRef) {
199+
fn lint_impl_item(&self, cx: &LateContext<'_>, item: ImplItemId, before_item: ImplItemId) {
198200
span_lint_and_note(
199201
cx,
200202
ARBITRARY_SOURCE_ITEM_ORDERING,
201-
item.span,
203+
cx.tcx.def_span(item.owner_id),
202204
format!(
203205
"incorrect ordering of impl items (defined order: {:?})",
204206
self.assoc_types_order
205207
),
206-
Some(before_item.span),
207-
format!("should be placed before `{}`", before_item.ident.name),
208+
Some(cx.tcx.def_span(before_item.owner_id)),
209+
format!("should be placed before `{}`", cx.tcx.item_name(before_item.owner_id)),
208210
);
209211
}
210212

211213
/// Produces a linting warning for incorrectly ordered item members.
212-
fn lint_member_name<T: LintContext>(cx: &T, ident: &rustc_span::Ident, before_ident: &rustc_span::Ident) {
214+
fn lint_member_name<T: LintContext>(cx: &T, ident: Ident, before_ident: Ident) {
213215
span_lint_and_note(
214216
cx,
215217
ARBITRARY_SOURCE_ITEM_ORDERING,
@@ -220,7 +222,7 @@ impl ArbitrarySourceItemOrdering {
220222
);
221223
}
222224

223-
fn lint_member_item<T: LintContext>(cx: &T, item: &Item<'_>, before_item: &Item<'_>, msg: &'static str) {
225+
fn lint_member_item(cx: &LateContext<'_>, item: &Item<'_>, before_item: &Item<'_>, msg: &'static str) {
224226
let span = if let Some(ident) = item.kind.ident() {
225227
ident.span
226228
} else {
@@ -245,17 +247,17 @@ impl ArbitrarySourceItemOrdering {
245247
}
246248

247249
/// Produces a linting warning for incorrectly ordered trait items.
248-
fn lint_trait_item<T: LintContext>(&self, cx: &T, item: &TraitItemRef, before_item: &TraitItemRef) {
250+
fn lint_trait_item(&self, cx: &LateContext<'_>, item: TraitItemId, before_item: TraitItemId) {
249251
span_lint_and_note(
250252
cx,
251253
ARBITRARY_SOURCE_ITEM_ORDERING,
252-
item.span,
254+
cx.tcx.def_span(item.owner_id),
253255
format!(
254256
"incorrect ordering of trait items (defined order: {:?})",
255257
self.assoc_types_order
256258
),
257-
Some(before_item.span),
258-
format!("should be placed before `{}`", before_item.ident.name),
259+
Some(cx.tcx.def_span(before_item.owner_id)),
260+
format!("should be placed before `{}`", cx.tcx.item_name(before_item.owner_id)),
259261
);
260262
}
261263
}
@@ -283,7 +285,7 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
283285
&& cur_v.ident.name.as_str() > variant.ident.name.as_str()
284286
&& cur_v.span != variant.span
285287
{
286-
Self::lint_member_name(cx, &variant.ident, &cur_v.ident);
288+
Self::lint_member_name(cx, variant.ident, cur_v.ident);
287289
}
288290
cur_v = Some(variant);
289291
}
@@ -299,57 +301,61 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
299301
&& cur_f.ident.name.as_str() > field.ident.name.as_str()
300302
&& cur_f.span != field.span
301303
{
302-
Self::lint_member_name(cx, &field.ident, &cur_f.ident);
304+
Self::lint_member_name(cx, field.ident, cur_f.ident);
303305
}
304306
cur_f = Some(field);
305307
}
306308
},
307-
ItemKind::Trait(is_auto, _safety, _ident, _generics, _generic_bounds, item_ref)
309+
ItemKind::Trait(_constness, is_auto, _safety, _ident, _generics, _generic_bounds, item_ref)
308310
if self.enable_ordering_for_trait && *is_auto == IsAuto::No =>
309311
{
310-
let mut cur_t: Option<&TraitItemRef> = None;
312+
let mut cur_t: Option<(TraitItemId, Ident)> = None;
311313

312-
for item in *item_ref {
313-
if item.span.in_external_macro(cx.sess().source_map()) {
314+
for &item in *item_ref {
315+
let span = cx.tcx.def_span(item.owner_id);
316+
let ident = cx.tcx.item_ident(item.owner_id);
317+
if span.in_external_macro(cx.sess().source_map()) {
314318
continue;
315319
}
316320

317-
if let Some(cur_t) = cur_t {
318-
let cur_t_kind = convert_assoc_item_kind(cur_t.kind);
321+
if let Some((cur_t, cur_ident)) = cur_t {
322+
let cur_t_kind = convert_assoc_item_kind(cx, cur_t.owner_id);
319323
let cur_t_kind_index = self.assoc_types_order.index_of(&cur_t_kind);
320-
let item_kind = convert_assoc_item_kind(item.kind);
324+
let item_kind = convert_assoc_item_kind(cx, item.owner_id);
321325
let item_kind_index = self.assoc_types_order.index_of(&item_kind);
322326

323-
if cur_t_kind == item_kind && cur_t.ident.name.as_str() > item.ident.name.as_str() {
324-
Self::lint_member_name(cx, &item.ident, &cur_t.ident);
327+
if cur_t_kind == item_kind && cur_ident.name.as_str() > ident.name.as_str() {
328+
Self::lint_member_name(cx, ident, cur_ident);
325329
} else if cur_t_kind_index > item_kind_index {
326330
self.lint_trait_item(cx, item, cur_t);
327331
}
328332
}
329-
cur_t = Some(item);
333+
cur_t = Some((item, ident));
330334
}
331335
},
332336
ItemKind::Impl(trait_impl) if self.enable_ordering_for_impl => {
333-
let mut cur_t: Option<&ImplItemRef> = None;
337+
let mut cur_t: Option<(ImplItemId, Ident)> = None;
334338

335-
for item in trait_impl.items {
336-
if item.span.in_external_macro(cx.sess().source_map()) {
339+
for &item in trait_impl.items {
340+
let span = cx.tcx.def_span(item.owner_id);
341+
let ident = cx.tcx.item_ident(item.owner_id);
342+
if span.in_external_macro(cx.sess().source_map()) {
337343
continue;
338344
}
339345

340-
if let Some(cur_t) = cur_t {
341-
let cur_t_kind = convert_assoc_item_kind(cur_t.kind);
346+
if let Some((cur_t, cur_ident)) = cur_t {
347+
let cur_t_kind = convert_assoc_item_kind(cx, cur_t.owner_id);
342348
let cur_t_kind_index = self.assoc_types_order.index_of(&cur_t_kind);
343-
let item_kind = convert_assoc_item_kind(item.kind);
349+
let item_kind = convert_assoc_item_kind(cx, item.owner_id);
344350
let item_kind_index = self.assoc_types_order.index_of(&item_kind);
345351

346-
if cur_t_kind == item_kind && cur_t.ident.name.as_str() > item.ident.name.as_str() {
347-
Self::lint_member_name(cx, &item.ident, &cur_t.ident);
352+
if cur_t_kind == item_kind && cur_ident.name.as_str() > ident.name.as_str() {
353+
Self::lint_member_name(cx, ident, cur_ident);
348354
} else if cur_t_kind_index > item_kind_index {
349355
self.lint_impl_item(cx, item, cur_t);
350356
}
351357
}
352-
cur_t = Some(item);
358+
cur_t = Some((item, ident));
353359
}
354360
},
355361
_ => {}, // Catch-all for `ItemKinds` that don't have fields.
@@ -458,18 +464,20 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
458464
}
459465
}
460466

461-
/// Converts a [`rustc_hir::AssocItemKind`] to a
462-
/// [`SourceItemOrderingTraitAssocItemKind`].
467+
/// Converts a [`ty::AssocKind`] to a [`SourceItemOrderingTraitAssocItemKind`].
463468
///
464469
/// This is implemented here because `rustc_hir` is not a dependency of
465470
/// `clippy_config`.
466-
fn convert_assoc_item_kind(value: AssocItemKind) -> SourceItemOrderingTraitAssocItemKind {
471+
fn convert_assoc_item_kind(cx: &LateContext<'_>, owner_id: OwnerId) -> SourceItemOrderingTraitAssocItemKind {
467472
#[allow(clippy::enum_glob_use)] // Very local glob use for legibility.
468473
use SourceItemOrderingTraitAssocItemKind::*;
469-
match value {
470-
AssocItemKind::Const => Const,
471-
AssocItemKind::Type => Type,
472-
AssocItemKind::Fn { .. } => Fn,
474+
475+
let kind = cx.tcx.associated_item(owner_id.def_id).kind;
476+
477+
match kind {
478+
AssocKind::Const { .. } => Const,
479+
AssocKind::Type { .. } => Type,
480+
AssocKind::Fn { .. } => Fn,
473481
}
474482
}
475483

clippy_lints/src/booleans.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use clippy_config::Conf;
22
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_hir_and_then};
3+
use clippy_utils::higher::has_let_expr;
34
use clippy_utils::msrvs::{self, Msrv};
45
use clippy_utils::source::SpanRangeExt;
56
use clippy_utils::sugg::Sugg;
@@ -646,7 +647,9 @@ impl<'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'_, 'tcx> {
646647
fn visit_expr(&mut self, e: &'tcx Expr<'_>) {
647648
if !e.span.from_expansion() {
648649
match &e.kind {
649-
ExprKind::Binary(binop, _, _) if binop.node == BinOpKind::Or || binop.node == BinOpKind::And => {
650+
ExprKind::Binary(binop, _, _)
651+
if binop.node == BinOpKind::Or || binop.node == BinOpKind::And && !has_let_expr(e) =>
652+
{
650653
self.bool_expr(e);
651654
},
652655
ExprKind::Unary(UnOp::Not, inner) => {

clippy_lints/src/copies.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use clippy_config::Conf;
22
use clippy_utils::diagnostics::{span_lint, span_lint_and_note, span_lint_and_then};
3+
use clippy_utils::higher::has_let_expr;
34
use clippy_utils::source::{IntoSpan, SpanRangeExt, first_line_of_span, indent_of, reindent_multiline, snippet};
45
use clippy_utils::ty::{InteriorMut, needs_ordered_drop};
56
use clippy_utils::visitors::for_each_expr_without_closures;
@@ -11,7 +12,7 @@ use clippy_utils::{
1112
use core::iter;
1213
use core::ops::ControlFlow;
1314
use rustc_errors::Applicability;
14-
use rustc_hir::{BinOpKind, Block, Expr, ExprKind, HirId, HirIdSet, LetStmt, Node, Stmt, StmtKind, intravisit};
15+
use rustc_hir::{Block, Expr, ExprKind, HirId, HirIdSet, LetStmt, Node, Stmt, StmtKind, intravisit};
1516
use rustc_lint::{LateContext, LateLintPass};
1617
use rustc_middle::ty::TyCtxt;
1718
use rustc_session::impl_lint_pass;
@@ -189,24 +190,13 @@ impl<'tcx> LateLintPass<'tcx> for CopyAndPaste<'tcx> {
189190
}
190191
}
191192

192-
/// Checks if the given expression is a let chain.
193-
fn contains_let(e: &Expr<'_>) -> bool {
194-
match e.kind {
195-
ExprKind::Let(..) => true,
196-
ExprKind::Binary(op, lhs, rhs) if op.node == BinOpKind::And => {
197-
matches!(lhs.kind, ExprKind::Let(..)) || contains_let(rhs)
198-
},
199-
_ => false,
200-
}
201-
}
202-
203193
fn lint_if_same_then_else(cx: &LateContext<'_>, conds: &[&Expr<'_>], blocks: &[&Block<'_>]) -> bool {
204194
let mut eq = SpanlessEq::new(cx);
205195
blocks
206196
.array_windows::<2>()
207197
.enumerate()
208198
.fold(true, |all_eq, (i, &[lhs, rhs])| {
209-
if eq.eq_block(lhs, rhs) && !contains_let(conds[i]) && conds.get(i + 1).is_none_or(|e| !contains_let(e)) {
199+
if eq.eq_block(lhs, rhs) && !has_let_expr(conds[i]) && conds.get(i + 1).is_none_or(|e| !has_let_expr(e)) {
210200
span_lint_and_note(
211201
cx,
212202
IF_SAME_THEN_ELSE,

clippy_lints/src/derivable_impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
192192
&& !item.span.from_expansion()
193193
&& let Some(def_id) = trait_ref.trait_def_id()
194194
&& cx.tcx.is_diagnostic_item(sym::Default, def_id)
195-
&& let impl_item_hir = child.id.hir_id()
195+
&& let impl_item_hir = child.hir_id()
196196
&& let Node::ImplItem(impl_item) = cx.tcx.hir_node(impl_item_hir)
197197
&& let ImplItemKind::Fn(_, b) = &impl_item.kind
198198
&& let Body { value: func_expr, .. } = cx.tcx.hir_body(*b)

clippy_lints/src/doc/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ impl<'tcx> LateLintPass<'tcx> for Documentation {
740740
);
741741
}
742742
},
743-
ItemKind::Trait(_, unsafety, ..) => match (headers.safety, unsafety) {
743+
ItemKind::Trait(_, _, unsafety, ..) => match (headers.safety, unsafety) {
744744
(false, Safety::Unsafe) => span_lint(
745745
cx,
746746
MISSING_SAFETY_DOC,

clippy_lints/src/empty_drop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl LateLintPass<'_> for EmptyDrop {
4141
..
4242
}) = item.kind
4343
&& trait_ref.trait_def_id() == cx.tcx.lang_items().drop_trait()
44-
&& let impl_item_hir = child.id.hir_id()
44+
&& let impl_item_hir = child.hir_id()
4545
&& let Node::ImplItem(impl_item) = cx.tcx.hir_node(impl_item_hir)
4646
&& let ImplItemKind::Fn(_, b) = &impl_item.kind
4747
&& let Body { value: func_expr, .. } = cx.tcx.hir_body(*b)

clippy_lints/src/escape.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use clippy_config::Conf;
22
use clippy_utils::diagnostics::span_lint_hir;
33
use rustc_abi::ExternAbi;
4-
use rustc_hir::{AssocItemKind, Body, FnDecl, HirId, HirIdSet, Impl, ItemKind, Node, Pat, PatKind, intravisit};
4+
use rustc_hir::def::DefKind;
5+
use rustc_hir::{Body, FnDecl, HirId, HirIdSet, Node, Pat, PatKind, intravisit};
56
use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
67
use rustc_lint::{LateContext, LateLintPass};
78
use rustc_middle::mir::FakeReadCause;
@@ -84,23 +85,16 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
8485
.def_id;
8586

8687
let mut trait_self_ty = None;
87-
if let Node::Item(item) = cx.tcx.hir_node_by_def_id(parent_id) {
88+
match cx.tcx.def_kind(parent_id) {
8889
// If the method is an impl for a trait, don't warn.
89-
if let ItemKind::Impl(Impl { of_trait: Some(_), .. }) = item.kind {
90-
return;
91-
}
90+
DefKind::Impl { of_trait: true } => return,
9291

9392
// find `self` ty for this trait if relevant
94-
if let ItemKind::Trait(_, _, _, _, _, items) = item.kind {
95-
for trait_item in items {
96-
if trait_item.id.owner_id.def_id == fn_def_id
97-
// be sure we have `self` parameter in this function
98-
&& trait_item.kind == (AssocItemKind::Fn { has_self: true })
99-
{
100-
trait_self_ty = Some(TraitRef::identity(cx.tcx, trait_item.id.owner_id.to_def_id()).self_ty());
101-
}
102-
}
103-
}
93+
DefKind::Trait => {
94+
trait_self_ty = Some(TraitRef::identity(cx.tcx, parent_id.to_def_id()).self_ty());
95+
},
96+
97+
_ => {},
10498
}
10599

106100
let mut v = EscapeDelegate {

0 commit comments

Comments
 (0)