Skip to content

Commit 682a42e

Browse files
committed
Auto merge of rust-lang#3270 - rust-lang:rustup-2024-01-21, r=RalfJung
Automatic Rustup
2 parents 1efd900 + f581b72 commit 682a42e

28 files changed

+149
-105
lines changed

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/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/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
{
@@ -450,12 +451,12 @@ fn check_partial_eq_without_eq<'tcx>(cx: &LateContext<'tcx>, span: Span, trait_r
450451
&& let Some(def_id) = trait_ref.trait_def_id()
451452
&& cx.tcx.is_diagnostic_item(sym::PartialEq, def_id)
452453
&& let param_env = param_env_for_derived_eq(cx.tcx, adt.did(), eq_trait_def_id)
453-
&& !implements_trait_with_env(cx.tcx, param_env, ty, eq_trait_def_id, adt.did(),&[])
454+
&& !implements_trait_with_env(cx.tcx, param_env, ty, eq_trait_def_id, None, &[])
454455
// If all of our fields implement `Eq`, we can implement `Eq` too
455456
&& adt
456457
.all_fields()
457458
.map(|f| f.ty(cx.tcx, args))
458-
.all(|ty| implements_trait_with_env(cx.tcx, param_env, ty, eq_trait_def_id, adt.did(), &[]))
459+
.all(|ty| implements_trait_with_env(cx.tcx, param_env, ty, eq_trait_def_id, None, &[]))
459460
{
460461
span_lint_and_sugg(
461462
cx,

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/inherent_impl.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ 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 { return };
5657
let inherent_impls = cx
5758
.tcx
58-
.with_stable_hashing_context(|hcx| cx.tcx.crate_inherent_impls(()).inherent_impls.to_sorted(&hcx, true));
59+
.with_stable_hashing_context(|hcx| impls.inherent_impls.to_sorted(&hcx, true));
5960

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

clippy_lints/src/iter_without_into_iter.rs

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

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

Lines changed: 1 addition & 1 deletion
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/matches/match_same_arms.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_hir::{Arm, Expr, ExprKind, HirId, HirIdMap, HirIdMapEntry, HirIdSet, P
1111
use rustc_lint::builtin::NON_EXHAUSTIVE_OMITTED_PATTERNS;
1212
use rustc_lint::LateContext;
1313
use rustc_middle::ty;
14-
use rustc_span::Symbol;
14+
use rustc_span::{ErrorGuaranteed, Symbol};
1515

1616
use super::MATCH_SAME_ARMS;
1717

@@ -167,6 +167,8 @@ enum NormalizedPat<'a> {
167167
/// contains everything afterwards. Note that either side, or both sides, may contain zero
168168
/// patterns.
169169
Slice(&'a [Self], Option<&'a [Self]>),
170+
/// A placeholder for a pattern that wasn't well formed in some way.
171+
Err(ErrorGuaranteed),
170172
}
171173

172174
#[derive(Clone, Copy)]
@@ -329,6 +331,7 @@ impl<'a> NormalizedPat<'a> {
329331
arena.alloc_from_iter(front.iter().map(|pat| Self::from_pat(cx, arena, pat))),
330332
wild_pat.map(|_| &*arena.alloc_from_iter(back.iter().map(|pat| Self::from_pat(cx, arena, pat)))),
331333
),
334+
PatKind::Err(guar) => Self::Err(guar),
332335
}
333336
}
334337

0 commit comments

Comments
 (0)