Skip to content

Commit 66c29b9

Browse files
committed
Auto merge of #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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 60 additions & 38 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 4 additions & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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;

0 commit comments

Comments
 (0)