Skip to content

Commit 66c29b9

Browse files
committed
Auto merge of rust-lang#12200 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
2 parents 8a17125 + c08c756 commit 66c29b9

Some content is hidden

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

61 files changed

+265
-180
lines changed

clippy.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ avoid-breaking-exported-api = false
22

33
# use the various `span_lint_*` methods instead, which also add a link to the docs
44
disallowed-methods = [
5-
"rustc_lint::context::LintContext::struct_span_lint",
6-
"rustc_middle::ty::context::TyCtxt::struct_span_lint_hir"
5+
"rustc_lint::context::LintContext::span_lint",
6+
"rustc_middle::ty::context::TyCtxt::node_span_lint"
77
]

clippy_lints/src/async_yields_async.rs

+60-38
Original file line numberDiff line numberDiff line change
@@ -45,50 +45,72 @@ declare_lint_pass!(AsyncYieldsAsync => [ASYNC_YIELDS_ASYNC]);
4545

4646
impl<'tcx> LateLintPass<'tcx> for AsyncYieldsAsync {
4747
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
48-
// For functions, with explicitly defined types, don't warn.
49-
// XXXkhuey maybe we should?
50-
if let ExprKind::Closure(Closure {
51-
kind:
52-
ClosureKind::Coroutine(CoroutineKind::Desugared(
53-
CoroutineDesugaring::Async,
54-
CoroutineSource::Block | CoroutineSource::Closure,
55-
)),
48+
let ExprKind::Closure(Closure {
49+
kind: ClosureKind::Coroutine(CoroutineKind::Desugared(CoroutineDesugaring::Async, kind)),
5650
body: body_id,
5751
..
5852
}) = expr.kind
59-
{
60-
if let Some(future_trait_def_id) = cx.tcx.lang_items().future_trait() {
61-
let typeck_results = cx.tcx.typeck_body(*body_id);
62-
let body = cx.tcx.hir().body(*body_id);
63-
let expr_ty = typeck_results.expr_ty(body.value);
53+
else {
54+
return;
55+
};
6456

65-
if implements_trait(cx, expr_ty, future_trait_def_id, &[]) {
66-
let return_expr_span = match &body.value.kind {
67-
// XXXkhuey there has to be a better way.
68-
ExprKind::Block(block, _) => block.expr.map(|e| e.span),
69-
ExprKind::Path(QPath::Resolved(_, path)) => Some(path.span),
70-
_ => None,
71-
};
72-
if let Some(return_expr_span) = return_expr_span {
73-
span_lint_hir_and_then(
74-
cx,
75-
ASYNC_YIELDS_ASYNC,
76-
body.value.hir_id,
57+
let body_expr = match kind {
58+
CoroutineSource::Fn => {
59+
// For functions, with explicitly defined types, don't warn.
60+
// XXXkhuey maybe we should?
61+
return;
62+
},
63+
CoroutineSource::Block => cx.tcx.hir().body(*body_id).value,
64+
CoroutineSource::Closure => {
65+
// Like `async fn`, async closures are wrapped in an additional block
66+
// to move all of the closure's arguments into the future.
67+
68+
let async_closure_body = cx.tcx.hir().body(*body_id).value;
69+
let ExprKind::Block(block, _) = async_closure_body.kind else {
70+
return;
71+
};
72+
let Some(block_expr) = block.expr else {
73+
return;
74+
};
75+
let ExprKind::DropTemps(body_expr) = block_expr.kind else {
76+
return;
77+
};
78+
body_expr
79+
},
80+
};
81+
82+
let Some(future_trait_def_id) = cx.tcx.lang_items().future_trait() else {
83+
return;
84+
};
85+
86+
let typeck_results = cx.tcx.typeck_body(*body_id);
87+
let expr_ty = typeck_results.expr_ty(body_expr);
88+
89+
if implements_trait(cx, expr_ty, future_trait_def_id, &[]) {
90+
let return_expr_span = match &body_expr.kind {
91+
// XXXkhuey there has to be a better way.
92+
ExprKind::Block(block, _) => block.expr.map(|e| e.span),
93+
ExprKind::Path(QPath::Resolved(_, path)) => Some(path.span),
94+
_ => None,
95+
};
96+
if let Some(return_expr_span) = return_expr_span {
97+
span_lint_hir_and_then(
98+
cx,
99+
ASYNC_YIELDS_ASYNC,
100+
body_expr.hir_id,
101+
return_expr_span,
102+
"an async construct yields a type which is itself awaitable",
103+
|db| {
104+
db.span_label(body_expr.span, "outer async construct");
105+
db.span_label(return_expr_span, "awaitable value not awaited");
106+
db.span_suggestion(
77107
return_expr_span,
78-
"an async construct yields a type which is itself awaitable",
79-
|db| {
80-
db.span_label(body.value.span, "outer async construct");
81-
db.span_label(return_expr_span, "awaitable value not awaited");
82-
db.span_suggestion(
83-
return_expr_span,
84-
"consider awaiting this value",
85-
format!("{}.await", snippet(cx, return_expr_span, "..")),
86-
Applicability::MaybeIncorrect,
87-
);
88-
},
108+
"consider awaiting this value",
109+
format!("{}.await", snippet(cx, return_expr_span, "..")),
110+
Applicability::MaybeIncorrect,
89111
);
90-
}
91-
}
112+
},
113+
);
92114
}
93115
}
94116
}

clippy_lints/src/casts/unnecessary_cast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub(super) fn check<'tcx>(
107107
&& let Some(src) = snippet_opt(cx, cast_expr.span)
108108
&& cast_to.is_floating_point()
109109
&& let Some(num_lit) = NumericLiteral::from_lit_kind(&src, &lit.node)
110-
&& let from_nbits = 128 - n.leading_zeros()
110+
&& let from_nbits = 128 - n.get().leading_zeros()
111111
&& let to_nbits = fp_ty_mantissa_nbits(cast_to)
112112
&& from_nbits != 0
113113
&& to_nbits != 0

clippy_lints/src/default_union_representation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl<'tcx> LateLintPass<'tcx> for DefaultUnionRepresentation {
7575
/// (ZST fields having an arbitrary offset is completely inconsequential, and
7676
/// if there is only one field left after ignoring ZST fields then the offset
7777
/// of that field does not matter either.)
78-
fn is_union_with_two_non_zst_fields(cx: &LateContext<'_>, item: &Item<'_>) -> bool {
78+
fn is_union_with_two_non_zst_fields<'tcx>(cx: &LateContext<'tcx>, item: &Item<'tcx>) -> bool {
7979
if let ItemKind::Union(..) = &item.kind
8080
&& let ty::Adt(adt_def, args) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind()
8181
{

clippy_lints/src/dereference.rs

+1
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,7 @@ impl TyCoercionStability {
830830
| TyKind::Infer
831831
| TyKind::Typeof(..)
832832
| TyKind::TraitObject(..)
833+
| TyKind::InferDelegation(..)
833834
| TyKind::Err(_) => Self::Reborrow,
834835
};
835836
}

clippy_lints/src/derive.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,8 @@ fn check_unsafe_derive_deserialize<'tcx>(
386386
&& cx
387387
.tcx
388388
.inherent_impls(def.did())
389-
.iter()
389+
.into_iter()
390+
.flatten()
390391
.map(|imp_did| cx.tcx.hir().expect_item(imp_did.expect_local()))
391392
.any(|imp| has_unsafe(cx, imp))
392393
{
@@ -451,12 +452,12 @@ fn check_partial_eq_without_eq<'tcx>(cx: &LateContext<'tcx>, span: Span, trait_r
451452
&& cx.tcx.is_diagnostic_item(sym::PartialEq, def_id)
452453
&& !has_non_exhaustive_attr(cx.tcx, *adt)
453454
&& let param_env = param_env_for_derived_eq(cx.tcx, adt.did(), eq_trait_def_id)
454-
&& !implements_trait_with_env(cx.tcx, param_env, ty, eq_trait_def_id, adt.did(),&[])
455+
&& !implements_trait_with_env(cx.tcx, param_env, ty, eq_trait_def_id, None, &[])
455456
// If all of our fields implement `Eq`, we can implement `Eq` too
456457
&& adt
457458
.all_fields()
458459
.map(|f| f.ty(cx.tcx, args))
459-
.all(|ty| implements_trait_with_env(cx.tcx, param_env, ty, eq_trait_def_id, adt.did(), &[]))
460+
.all(|ty| implements_trait_with_env(cx.tcx, param_env, ty, eq_trait_def_id, None, &[]))
460461
{
461462
span_lint_and_sugg(
462463
cx,

clippy_lints/src/doc/needless_doctest_main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use clippy_utils::diagnostics::span_lint;
66
use rustc_ast::{CoroutineKind, Fn, FnRetTy, Item, ItemKind};
77
use rustc_data_structures::sync::Lrc;
88
use rustc_errors::emitter::HumanEmitter;
9-
use rustc_errors::DiagCtxt;
9+
use rustc_errors::{DiagCtxt, DiagnosticBuilder};
1010
use rustc_lint::LateContext;
1111
use rustc_parse::maybe_new_parser_from_source_str;
1212
use rustc_parse::parser::ForceCollect;
@@ -53,7 +53,7 @@ pub fn check(
5353
let mut parser = match maybe_new_parser_from_source_str(&sess, filename, code) {
5454
Ok(p) => p,
5555
Err(errs) => {
56-
drop(errs);
56+
errs.into_iter().for_each(DiagnosticBuilder::cancel);
5757
return (false, test_attr_spans);
5858
},
5959
};

clippy_lints/src/equatable_if_let.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ fn unary_pattern(pat: &Pat<'_>) -> bool {
5151
| PatKind::Binding(..)
5252
| PatKind::Wild
5353
| PatKind::Never
54-
| PatKind::Or(_) => false,
54+
| PatKind::Or(_)
55+
| PatKind::Err(_) => false,
5556
PatKind::Struct(_, a, etc) => !etc && a.iter().all(|x| unary_pattern(x.pat)),
5657
PatKind::Tuple(a, etc) | PatKind::TupleStruct(_, a, etc) => etc.as_opt_usize().is_none() && array_rec(a),
5758
PatKind::Ref(x, _) | PatKind::Box(x) => unary_pattern(x),

clippy_lints/src/implicit_hasher.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ enum ImplicitHasherType<'tcx> {
210210

211211
impl<'tcx> ImplicitHasherType<'tcx> {
212212
/// Checks that `ty` is a target type without a `BuildHasher`.
213-
fn new(cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'_>) -> Option<Self> {
213+
fn new(cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'tcx>) -> Option<Self> {
214214
if let TyKind::Path(QPath::Resolved(None, path)) = hir_ty.kind {
215215
let params: Vec<_> = path
216216
.segments

clippy_lints/src/implicit_saturating_add.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg;
33
use clippy_utils::get_parent_expr;
44
use clippy_utils::source::snippet_with_context;
55
use rustc_ast::ast::{LitIntType, LitKind};
6+
use rustc_data_structures::packed::Pu128;
67
use rustc_errors::Applicability;
78
use rustc_hir::{BinOpKind, Block, Expr, ExprKind, Stmt, StmtKind};
89
use rustc_lint::{LateContext, LateLintPass};
@@ -69,7 +70,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingAdd {
6970
&& clippy_utils::SpanlessEq::new(cx).eq_expr(l, target)
7071
&& BinOpKind::Add == op1.node
7172
&& let ExprKind::Lit(lit) = value.kind
72-
&& let LitKind::Int(1, LitIntType::Unsuffixed) = lit.node
73+
&& let LitKind::Int(Pu128(1), LitIntType::Unsuffixed) = lit.node
7374
&& block.expr.is_none()
7475
{
7576
let mut app = Applicability::MachineApplicable;

clippy_lints/src/implicit_saturating_sub.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::{higher, is_integer_literal, peel_blocks_with_stmt, SpanlessEq};
33
use rustc_ast::ast::LitKind;
4+
use rustc_data_structures::packed::Pu128;
45
use rustc_errors::Applicability;
56
use rustc_hir::{BinOpKind, Expr, ExprKind, QPath};
67
use rustc_lint::{LateContext, LateLintPass};
@@ -86,7 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
8687
match cond_num_val.kind {
8788
ExprKind::Lit(cond_lit) => {
8889
// Check if the constant is zero
89-
if let LitKind::Int(0, _) = cond_lit.node {
90+
if let LitKind::Int(Pu128(0), _) = cond_lit.node {
9091
if cx.typeck_results().expr_ty(cond_left).is_signed() {
9192
} else {
9293
print_lint_and_sugg(cx, var_name, expr);

clippy_lints/src/inherent_impl.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@ impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl {
5353
// List of spans to lint. (lint_span, first_span)
5454
let mut lint_spans = Vec::new();
5555

56+
let Ok(impls) = cx.tcx.crate_inherent_impls(()) else {
57+
return;
58+
};
5659
let inherent_impls = cx
5760
.tcx
58-
.with_stable_hashing_context(|hcx| cx.tcx.crate_inherent_impls(()).inherent_impls.to_sorted(&hcx, true));
61+
.with_stable_hashing_context(|hcx| impls.inherent_impls.to_sorted(&hcx, true));
5962

6063
for (_, impl_ids) in inherent_impls.into_iter().filter(|(&id, impls)| {
6164
impls.len() > 1

clippy_lints/src/iter_without_into_iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ fn deref_chain<'cx, 'tcx>(cx: &'cx LateContext<'tcx>, ty: Ty<'tcx>) -> impl Iter
139139

140140
fn adt_has_inherent_method(cx: &LateContext<'_>, ty: Ty<'_>, method_name: Symbol) -> bool {
141141
if let Some(ty_did) = ty.ty_adt_def().map(ty::AdtDef::did) {
142-
cx.tcx.inherent_impls(ty_did).iter().any(|&did| {
142+
cx.tcx.inherent_impls(ty_did).into_iter().flatten().any(|&did| {
143143
cx.tcx
144144
.associated_items(did)
145145
.filter_by_name_unhygienic(method_name)

clippy_lints/src/len_zero.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,8 @@ fn check_for_is_empty(
441441
let is_empty = cx
442442
.tcx
443443
.inherent_impls(impl_ty)
444-
.iter()
444+
.into_iter()
445+
.flatten()
445446
.flat_map(|&id| cx.tcx.associated_items(id).filter_by_name_unhygienic(is_empty))
446447
.find(|item| item.kind == AssocKind::Fn);
447448

@@ -605,7 +606,7 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
605606
/// Checks the inherent impl's items for an `is_empty(self)` method.
606607
fn has_is_empty_impl(cx: &LateContext<'_>, id: DefId) -> bool {
607608
let is_empty = sym!(is_empty);
608-
cx.tcx.inherent_impls(id).iter().any(|imp| {
609+
cx.tcx.inherent_impls(id).into_iter().flatten().any(|imp| {
609610
cx.tcx
610611
.associated_items(*imp)
611612
.filter_by_name_unhygienic(is_empty)

clippy_lints/src/loops/explicit_iter_loop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ fn is_ref_iterable<'tcx>(
118118
.liberate_late_bound_regions(fn_id, cx.tcx.fn_sig(fn_id).skip_binder())
119119
&& let &[req_self_ty, req_res_ty] = &**sig.inputs_and_output
120120
&& let param_env = cx.tcx.param_env(fn_id)
121-
&& implements_trait_with_env(cx.tcx, param_env, req_self_ty, trait_id, fn_id, &[])
121+
&& implements_trait_with_env(cx.tcx, param_env, req_self_ty, trait_id, Some(fn_id), &[])
122122
&& let Some(into_iter_ty) =
123123
make_normalized_projection_with_regions(cx.tcx, param_env, trait_id, sym!(IntoIter), [req_self_ty])
124124
&& let req_res_ty = normalize_with_regions(cx.tcx, param_env, req_res_ty)

clippy_lints/src/loops/manual_memcpy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ fn is_array_length_equal_to_range(cx: &LateContext<'_>, start: &Expr<'_>, end: &
461461
if let ExprKind::Lit(lit) = expr.kind
462462
&& let ast::LitKind::Int(value, _) = lit.node
463463
{
464-
Some(value)
464+
Some(value.get())
465465
} else {
466466
None
467467
}

clippy_lints/src/loops/needless_range_loop.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ fn is_end_eq_array_len<'tcx>(
209209
&& let Some(arr_len) = arr_len_const.try_eval_target_usize(cx.tcx, cx.param_env)
210210
{
211211
return match limits {
212-
ast::RangeLimits::Closed => end_int + 1 >= arr_len.into(),
213-
ast::RangeLimits::HalfOpen => end_int >= arr_len.into(),
212+
ast::RangeLimits::Closed => end_int.get() + 1 >= arr_len.into(),
213+
ast::RangeLimits::HalfOpen => end_int.get() >= arr_len.into(),
214214
};
215215
}
216216

clippy_lints/src/manual_bits.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg;
33
use clippy_utils::get_parent_expr;
44
use clippy_utils::source::snippet_with_context;
55
use rustc_ast::ast::LitKind;
6+
use rustc_data_structures::packed::Pu128;
67
use rustc_errors::Applicability;
78
use rustc_hir::{BinOpKind, Expr, ExprKind, GenericArg, QPath};
89
use rustc_lint::{LateContext, LateLintPass, LintContext};
@@ -62,7 +63,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualBits {
6263
&& let Some((real_ty, resolved_ty, other_expr)) = get_one_size_of_ty(cx, left_expr, right_expr)
6364
&& matches!(resolved_ty.kind(), ty::Int(_) | ty::Uint(_))
6465
&& let ExprKind::Lit(lit) = &other_expr.kind
65-
&& let LitKind::Int(8, _) = lit.node
66+
&& let LitKind::Int(Pu128(8), _) = lit.node
6667
{
6768
let mut app = Applicability::MachineApplicable;
6869
let ty_snip = snippet_with_context(cx, real_ty.span, ctxt, "..", &mut app).0;

clippy_lints/src/manual_range_patterns.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn expr_as_i128(expr: &Expr<'_>) -> Option<i128> {
4545
&& let LitKind::Int(num, _) = lit.node
4646
{
4747
// Intentionally not handling numbers greater than i128::MAX (for u128 literals) for now.
48-
num.try_into().ok()
48+
num.get().try_into().ok()
4949
} else {
5050
None
5151
}

clippy_lints/src/manual_strip.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ fn eq_pattern_length<'tcx>(cx: &LateContext<'tcx>, pattern: &Expr<'_>, expr: &'t
161161
..
162162
}) = expr.kind
163163
{
164-
constant_length(cx, pattern).map_or(false, |length| length == *n)
164+
constant_length(cx, pattern).map_or(false, |length| *n == length)
165165
} else {
166166
len_arg(cx, expr).map_or(false, |arg| eq_expr_value(cx, pattern, arg))
167167
}

0 commit comments

Comments
 (0)