Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 379342c

Browse files
committed
Auto merge of rust-lang#12331 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
2 parents d554bca + 8a58b76 commit 379342c

File tree

106 files changed

+528
-600
lines changed

Some content is hidden

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

106 files changed

+528
-600
lines changed

clippy_config/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#![allow(
55
clippy::must_use_candidate,
66
clippy::missing_panics_doc,
7+
rustc::diagnostic_outside_of_impl,
8+
rustc::untranslatable_diagnostic,
79
rustc::untranslatable_diagnostic_trivial
810
)]
911

clippy_lints/src/absolute_paths.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl LateLintPass<'_> for AbsolutePaths {
6262
} = self;
6363

6464
if !path.span.from_expansion()
65-
&& let Some(node) = cx.tcx.opt_hir_node(hir_id)
65+
&& let node = cx.tcx.hir_node(hir_id)
6666
&& !matches!(node, Node::Item(item) if matches!(item.kind, ItemKind::Use(_, _)))
6767
&& let [first, rest @ ..] = path.segments
6868
// Handle `::std`

clippy_lints/src/assertions_on_constants.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,10 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnConstants {
4646
return;
4747
};
4848
if let ConstantSource::Constant = source
49-
&& let Some(node) = cx.tcx.hir().find_parent(e.hir_id)
5049
&& let Node::Item(Item {
5150
kind: ItemKind::Const(..),
5251
..
53-
}) = node
52+
}) = cx.tcx.parent_hir_node(e.hir_id)
5453
{
5554
return;
5655
}

clippy_lints/src/attrs.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,9 +1000,7 @@ fn check_clippy_cfg_attr(
10001000
) {
10011001
if cfg_attr.has_name(sym::clippy)
10021002
&& let Some(ident) = behind_cfg_attr.ident()
1003-
// FIXME: replace with `from_symbol` once https://github.com/rust-lang/rust/pull/121230
1004-
// is merged.
1005-
&& Level::from_str(ident.name.as_str()).is_some()
1003+
&& Level::from_symbol(ident.name, Some(attr.id)).is_some()
10061004
&& let Some(items) = behind_cfg_attr.meta_item_list()
10071005
{
10081006
let nb_items = items.len();

clippy_lints/src/box_default.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,25 +101,22 @@ impl<'tcx> Visitor<'tcx> for InferVisitor {
101101

102102
fn given_type(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
103103
match get_parent_node(cx.tcx, expr.hir_id) {
104-
Some(Node::Local(Local { ty: Some(ty), .. })) => {
104+
Node::Local(Local { ty: Some(ty), .. }) => {
105105
let mut v = InferVisitor::default();
106106
v.visit_ty(ty);
107107
!v.0
108108
},
109-
Some(
110-
Node::Expr(Expr {
109+
Node::Expr(Expr {
110+
kind: ExprKind::Call(path, args),
111+
..
112+
})
113+
| Node::Block(Block {
114+
expr: Some(Expr {
111115
kind: ExprKind::Call(path, args),
112116
..
113-
})
114-
| Node::Block(Block {
115-
expr:
116-
Some(Expr {
117-
kind: ExprKind::Call(path, args),
118-
..
119-
}),
120-
..
121117
}),
122-
) => {
118+
..
119+
}) => {
123120
if let Some(index) = args.iter().position(|arg| arg.hir_id == expr.hir_id)
124121
&& let Some(sig) = expr_sig(cx, path)
125122
&& let Some(input) = sig.input(index)

clippy_lints/src/casts/cast_possible_truncation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use clippy_utils::expr_or_init;
44
use clippy_utils::source::snippet;
55
use clippy_utils::sugg::Sugg;
66
use clippy_utils::ty::{get_discriminant_value, is_isize_or_usize};
7-
use rustc_errors::{Applicability, Diagnostic, SuggestionStyle};
7+
use rustc_errors::{Applicability, DiagnosticBuilder, SuggestionStyle};
88
use rustc_hir::def::{DefKind, Res};
99
use rustc_hir::{BinOpKind, Expr, ExprKind};
1010
use rustc_lint::LateContext;
@@ -176,7 +176,7 @@ fn offer_suggestion(
176176
expr: &Expr<'_>,
177177
cast_expr: &Expr<'_>,
178178
cast_to_span: Span,
179-
diag: &mut Diagnostic,
179+
diag: &mut DiagnosticBuilder<'_, ()>,
180180
) {
181181
let cast_to_snip = snippet(cx, cast_to_span, "..");
182182
let suggestion = if cast_to_snip == "_" {

clippy_lints/src/casts/cast_slice_different_sizes.rs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,20 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, msrv: &Msrv
6767
}
6868

6969
fn is_child_of_cast(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
70-
let map = cx.tcx.hir();
71-
if let Some(parent_id) = map.opt_parent_id(expr.hir_id)
72-
&& let Some(parent) = cx.tcx.opt_hir_node(parent_id)
73-
{
74-
let expr = match parent {
75-
Node::Block(block) => {
76-
if let Some(parent_expr) = block.expr {
77-
parent_expr
78-
} else {
79-
return false;
80-
}
81-
},
82-
Node::Expr(expr) => expr,
83-
_ => return false,
84-
};
70+
let parent = cx.tcx.parent_hir_node(expr.hir_id);
71+
let expr = match parent {
72+
Node::Block(block) => {
73+
if let Some(parent_expr) = block.expr {
74+
parent_expr
75+
} else {
76+
return false;
77+
}
78+
},
79+
Node::Expr(expr) => expr,
80+
_ => return false,
81+
};
8582

86-
matches!(expr.kind, ExprKind::Cast(..))
87-
} else {
88-
false
89-
}
83+
matches!(expr.kind, ExprKind::Cast(..))
9084
}
9185

9286
/// Returns the type T of the pointed to *const [T] or *mut [T] and the mutability of the slice if

clippy_lints/src/casts/unnecessary_cast.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub(super) fn check<'tcx>(
6565
&& let ExprKind::Path(qpath) = inner.kind
6666
&& let QPath::Resolved(None, Path { res, .. }) = qpath
6767
&& let Res::Local(hir_id) = res
68-
&& let parent = cx.tcx.hir().get_parent(*hir_id)
68+
&& let parent = cx.tcx.parent_hir_node(*hir_id)
6969
&& let Node::Local(local) = parent
7070
{
7171
if let Some(ty) = local.ty
@@ -144,8 +144,7 @@ pub(super) fn check<'tcx>(
144144

145145
if cast_from.kind() == cast_to.kind() && !in_external_macro(cx.sess(), expr.span) {
146146
if let Some(id) = path_to_local(cast_expr)
147-
&& let Some(span) = cx.tcx.hir().opt_span(id)
148-
&& !span.eq_ctxt(cast_expr.span)
147+
&& !cx.tcx.hir().span(id).eq_ctxt(cast_expr.span)
149148
{
150149
// Binding context is different than the identifiers context.
151150
// Weird macro wizardry could be involved here.
@@ -265,8 +264,7 @@ fn is_cast_from_ty_alias<'tcx>(cx: &LateContext<'tcx>, expr: impl Visitable<'tcx
265264
}
266265
// Local usage
267266
} else if let Res::Local(hir_id) = res
268-
&& let Some(parent) = get_parent_node(cx.tcx, hir_id)
269-
&& let Node::Local(l) = parent
267+
&& let Node::Local(l) = get_parent_node(cx.tcx, hir_id)
270268
{
271269
if let Some(e) = l.init
272270
&& is_cast_from_ty_alias(cx, e, cast_from)

clippy_lints/src/collection_is_never_read.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ fn has_no_read_access<'tcx>(cx: &LateContext<'tcx>, id: HirId, block: &'tcx Bloc
9494
// `id` appearing in the left-hand side of an assignment is not a read access:
9595
//
9696
// id = ...; // Not reading `id`.
97-
if let Some(Node::Expr(parent)) = get_parent_node(cx.tcx, expr.hir_id)
97+
if let Node::Expr(parent) = get_parent_node(cx.tcx, expr.hir_id)
9898
&& let ExprKind::Assign(lhs, ..) = parent.kind
9999
&& path_to_local_id(lhs, id)
100100
{
@@ -108,7 +108,7 @@ fn has_no_read_access<'tcx>(cx: &LateContext<'tcx>, id: HirId, block: &'tcx Bloc
108108
// Only assuming this for "official" methods defined on the type. For methods defined in extension
109109
// traits (identified as local, based on the orphan rule), pessimistically assume that they might
110110
// have side effects, so consider them a read.
111-
if let Some(Node::Expr(parent)) = get_parent_node(cx.tcx, expr.hir_id)
111+
if let Node::Expr(parent) = get_parent_node(cx.tcx, expr.hir_id)
112112
&& let ExprKind::MethodCall(_, receiver, _, _) = parent.kind
113113
&& path_to_local_id(receiver, id)
114114
&& let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(parent.hir_id)
@@ -117,7 +117,7 @@ fn has_no_read_access<'tcx>(cx: &LateContext<'tcx>, id: HirId, block: &'tcx Bloc
117117
// The method call is a statement, so the return value is not used. That's not a read access:
118118
//
119119
// id.foo(args);
120-
if let Some(Node::Stmt(..)) = get_parent_node(cx.tcx, parent.hir_id) {
120+
if let Node::Stmt(..) = get_parent_node(cx.tcx, parent.hir_id) {
121121
return ControlFlow::Continue(());
122122
}
123123

clippy_lints/src/copies.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,8 @@ fn scan_block_for_eq<'tcx>(
511511
for stmt in &stmts[stmts.len() - init..=stmts.len() - offset] {
512512
if let StmtKind::Local(l) = stmt.kind {
513513
l.pat.each_binding_or_first(&mut |_, id, _, _| {
514-
eq.locals.remove(&id);
514+
// FIXME(rust/#120456) - is `swap_remove` correct?
515+
eq.locals.swap_remove(&id);
515516
});
516517
}
517518
}

0 commit comments

Comments
 (0)