Skip to content

Commit 4191258

Browse files
authored
Merge branch 'rust-lang:master' into 12007-detect-empty-enums-with-brackets
2 parents ab28d90 + 8b22471 commit 4191258

Some content is hidden

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

42 files changed

+207
-132
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy"
3-
version = "0.1.76"
3+
version = "0.1.77"
44
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
55
repository = "https://github.com/rust-lang/rust-clippy"
66
readme = "README.md"

clippy_config/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy_config"
3-
version = "0.1.76"
3+
version = "0.1.77"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

clippy_config/src/conf.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -636,11 +636,12 @@ impl Conf {
636636
match path {
637637
Ok((_, warnings)) => {
638638
for warning in warnings {
639-
sess.warn(warning.clone());
639+
sess.dcx().warn(warning.clone());
640640
}
641641
},
642642
Err(error) => {
643-
sess.err(format!("error finding Clippy's configuration file: {error}"));
643+
sess.dcx()
644+
.err(format!("error finding Clippy's configuration file: {error}"));
644645
},
645646
}
646647

@@ -652,7 +653,7 @@ impl Conf {
652653
Ok((Some(path), _)) => match sess.source_map().load_file(path) {
653654
Ok(file) => deserialize(&file),
654655
Err(error) => {
655-
sess.err(format!("failed to read `{}`: {error}", path.display()));
656+
sess.dcx().err(format!("failed to read `{}`: {error}", path.display()));
656657
TryConf::default()
657658
},
658659
},
@@ -663,14 +664,14 @@ impl Conf {
663664

664665
// all conf errors are non-fatal, we just use the default conf in case of error
665666
for error in errors {
666-
sess.span_err(
667+
sess.dcx().span_err(
667668
error.span,
668669
format!("error reading Clippy's configuration file: {}", error.message),
669670
);
670671
}
671672

672673
for warning in warnings {
673-
sess.span_warn(
674+
sess.dcx().span_warn(
674675
warning.span,
675676
format!("error reading Clippy's configuration file: {}", warning.message),
676677
);

clippy_config/src/msrvs.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl Msrv {
8484
(None, Some(cargo_msrv)) => self.stack = vec![cargo_msrv],
8585
(Some(clippy_msrv), Some(cargo_msrv)) => {
8686
if clippy_msrv != cargo_msrv {
87-
sess.warn(format!(
87+
sess.dcx().warn(format!(
8888
"the MSRV in `clippy.toml` and `Cargo.toml` differ; using `{clippy_msrv}` from `clippy.toml`"
8989
));
9090
}
@@ -107,7 +107,8 @@ impl Msrv {
107107

108108
if let Some(msrv_attr) = msrv_attrs.next() {
109109
if let Some(duplicate) = msrv_attrs.last() {
110-
sess.struct_span_err(duplicate.span, "`clippy::msrv` is defined multiple times")
110+
sess.dcx()
111+
.struct_span_err(duplicate.span, "`clippy::msrv` is defined multiple times")
111112
.span_note(msrv_attr.span, "first definition found here")
112113
.emit();
113114
}
@@ -117,9 +118,10 @@ impl Msrv {
117118
return Some(version);
118119
}
119120

120-
sess.span_err(msrv_attr.span, format!("`{msrv}` is not a valid Rust version"));
121+
sess.dcx()
122+
.span_err(msrv_attr.span, format!("`{msrv}` is not a valid Rust version"));
121123
} else {
122-
sess.span_err(msrv_attr.span, "bad clippy attribute");
124+
sess.dcx().span_err(msrv_attr.span, "bad clippy attribute");
123125
}
124126
}
125127

clippy_lints/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy_lints"
3-
version = "0.1.76"
3+
version = "0.1.77"
44
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
55
repository = "https://github.com/rust-lang/rust-clippy"
66
readme = "README.md"

clippy_lints/src/async_yields_async.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_hir_and_then;
22
use clippy_utils::source::snippet;
33
use clippy_utils::ty::implements_trait;
44
use rustc_errors::Applicability;
5-
use rustc_hir::{Body, BodyId, CoroutineKind, CoroutineSource, ExprKind, QPath};
5+
use rustc_hir::{Closure, ClosureKind, CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, ExprKind, QPath};
66
use rustc_lint::{LateContext, LateLintPass};
77
use rustc_session::declare_lint_pass;
88

@@ -44,16 +44,22 @@ declare_clippy_lint! {
4444
declare_lint_pass!(AsyncYieldsAsync => [ASYNC_YIELDS_ASYNC]);
4545

4646
impl<'tcx> LateLintPass<'tcx> for AsyncYieldsAsync {
47-
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) {
48-
use CoroutineSource::{Block, Closure};
47+
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
4948
// For functions, with explicitly defined types, don't warn.
5049
// XXXkhuey maybe we should?
51-
if let Some(CoroutineKind::Async(Block | Closure)) = body.coroutine_kind {
50+
if let ExprKind::Closure(Closure {
51+
kind:
52+
ClosureKind::Coroutine(CoroutineKind::Desugared(
53+
CoroutineDesugaring::Async,
54+
CoroutineSource::Block | CoroutineSource::Closure,
55+
)),
56+
body: body_id,
57+
..
58+
}) = expr.kind
59+
{
5260
if let Some(future_trait_def_id) = cx.tcx.lang_items().future_trait() {
53-
let body_id = BodyId {
54-
hir_id: body.value.hir_id,
55-
};
56-
let typeck_results = cx.tcx.typeck_body(body_id);
61+
let typeck_results = cx.tcx.typeck_body(*body_id);
62+
let body = cx.tcx.hir().body(*body_id);
5763
let expr_ty = typeck_results.expr_ty(body.value);
5864

5965
if implements_trait(cx, expr_ty, future_trait_def_id, &[]) {

clippy_lints/src/await_holding_invalid.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use clippy_config::types::DisallowedPath;
22
use clippy_utils::diagnostics::span_lint_and_then;
33
use clippy_utils::{match_def_path, paths};
44
use rustc_data_structures::fx::FxHashMap;
5+
use rustc_hir as hir;
56
use rustc_hir::def_id::DefId;
6-
use rustc_hir::{Body, CoroutineKind, CoroutineSource};
77
use rustc_lint::{LateContext, LateLintPass};
88
use rustc_middle::mir::CoroutineLayout;
99
use rustc_session::impl_lint_pass;
@@ -183,8 +183,8 @@ impl AwaitHolding {
183183
}
184184
}
185185

186-
impl LateLintPass<'_> for AwaitHolding {
187-
fn check_crate(&mut self, cx: &LateContext<'_>) {
186+
impl<'tcx> LateLintPass<'tcx> for AwaitHolding {
187+
fn check_crate(&mut self, cx: &LateContext<'tcx>) {
188188
for conf in &self.conf_invalid_types {
189189
let segs: Vec<_> = conf.path().split("::").collect();
190190
for id in clippy_utils::def_path_def_ids(cx, &segs) {
@@ -193,11 +193,14 @@ impl LateLintPass<'_> for AwaitHolding {
193193
}
194194
}
195195

196-
fn check_body(&mut self, cx: &LateContext<'_>, body: &'_ Body<'_>) {
197-
use CoroutineSource::{Block, Closure, Fn};
198-
if let Some(CoroutineKind::Async(Block | Closure | Fn)) = body.coroutine_kind {
199-
let def_id = cx.tcx.hir().body_owner_def_id(body.id());
200-
if let Some(coroutine_layout) = cx.tcx.mir_coroutine_witnesses(def_id) {
196+
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) {
197+
if let hir::ExprKind::Closure(hir::Closure {
198+
kind: hir::ClosureKind::Coroutine(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _)),
199+
def_id,
200+
..
201+
}) = expr.kind
202+
{
203+
if let Some(coroutine_layout) = cx.tcx.mir_coroutine_witnesses(*def_id) {
201204
self.check_interior_types(cx, coroutine_layout);
202205
}
203206
}

clippy_lints/src/doc/needless_doctest_main.rs

+4-4
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::EmitterWriter;
9-
use rustc_errors::Handler;
9+
use rustc_errors::DiagCtxt;
1010
use rustc_lint::LateContext;
1111
use rustc_parse::maybe_new_parser_from_source_str;
1212
use rustc_parse::parser::ForceCollect;
@@ -45,10 +45,10 @@ pub fn check(
4545
let fallback_bundle =
4646
rustc_errors::fallback_fluent_bundle(rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(), false);
4747
let emitter = EmitterWriter::new(Box::new(io::sink()), fallback_bundle);
48-
let handler = Handler::with_emitter(Box::new(emitter)).disable_warnings();
49-
#[expect(clippy::arc_with_non_send_sync)] // `Lrc` is expected by with_span_handler
48+
let dcx = DiagCtxt::with_emitter(Box::new(emitter)).disable_warnings();
49+
#[expect(clippy::arc_with_non_send_sync)] // `Lrc` is expected by with_dcx
5050
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
51-
let sess = ParseSess::with_span_handler(handler, sm);
51+
let sess = ParseSess::with_dcx(dcx, sm);
5252

5353
let mut parser = match maybe_new_parser_from_source_str(&sess, filename, code) {
5454
Ok(p) => p,

clippy_lints/src/item_name_repetitions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ impl LateLintPass<'_> for ItemNameRepetitions {
436436
{
437437
match item.kind {
438438
ItemKind::Enum(def, _) => check_variant(cx, self.enum_threshold, &def, item_name, item.span),
439-
ItemKind::Struct(VariantData::Struct(fields, _), _) => {
439+
ItemKind::Struct(VariantData::Struct { fields, .. }, _) => {
440440
check_fields(cx, self.struct_threshold, item, fields);
441441
},
442442
_ => (),

clippy_lints/src/len_zero.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use rustc_hir::def::Res;
88
use rustc_hir::def_id::{DefId, DefIdSet};
99
use rustc_hir::{
1010
AssocItemKind, BinOpKind, Expr, ExprKind, FnRetTy, GenericArg, GenericBound, ImplItem, ImplItemKind,
11-
ImplicitSelfKind, Item, ItemKind, LangItem, Mutability, Node, PatKind, PathSegment, PrimTy, QPath, TraitItemRef,
12-
TyKind, TypeBindingKind,
11+
ImplicitSelfKind, Item, ItemKind, Mutability, Node, OpaqueTyOrigin, PatKind, PathSegment, PrimTy, QPath,
12+
TraitItemRef, TyKind, TypeBindingKind,
1313
};
1414
use rustc_lint::{LateContext, LateLintPass};
1515
use rustc_middle::ty::{self, AssocKind, FnSig, Ty};
@@ -289,8 +289,10 @@ fn extract_future_output<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<&
289289
kind: ItemKind::OpaqueTy(opaque),
290290
..
291291
} = item
292-
&& opaque.bounds.len() == 1
293-
&& let GenericBound::LangItemTrait(LangItem::Future, _, _, generic_args) = &opaque.bounds[0]
292+
&& let OpaqueTyOrigin::AsyncFn(_) = opaque.origin
293+
&& let [GenericBound::Trait(trait_ref, _)] = &opaque.bounds
294+
&& let Some(segment) = trait_ref.trait_ref.path.segments.last()
295+
&& let Some(generic_args) = segment.args
294296
&& generic_args.bindings.len() == 1
295297
&& let TypeBindingKind::Equality {
296298
term:

clippy_lints/src/manual_async_fn.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ use clippy_utils::source::{position_before_rarrow, snippet_block, snippet_opt};
33
use rustc_errors::Applicability;
44
use rustc_hir::intravisit::FnKind;
55
use rustc_hir::{
6-
Block, Body, Closure, CoroutineKind, CoroutineSource, Expr, ExprKind, FnDecl, FnRetTy, GenericArg, GenericBound,
7-
ImplItem, Item, ItemKind, LifetimeName, Node, Term, TraitRef, Ty, TyKind, TypeBindingKind,
6+
Block, Body, Closure, ClosureKind, CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, ExprKind, FnDecl,
7+
FnRetTy, GenericArg, GenericBound, ImplItem, Item, ItemKind, LifetimeName, Node, Term, TraitRef, Ty, TyKind,
8+
TypeBindingKind,
89
};
910
use rustc_lint::{LateContext, LateLintPass};
1011
use rustc_session::declare_lint_pass;
@@ -172,15 +173,14 @@ fn captures_all_lifetimes(inputs: &[Ty<'_>], output_lifetimes: &[LifetimeName])
172173
}
173174

174175
fn desugared_async_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>) -> Option<&'tcx Body<'tcx>> {
175-
if let Some(block_expr) = block.expr
176-
&& let Expr {
177-
kind: ExprKind::Closure(&Closure { body, .. }),
178-
..
179-
} = block_expr
180-
&& let closure_body = cx.tcx.hir().body(body)
181-
&& closure_body.coroutine_kind == Some(CoroutineKind::Async(CoroutineSource::Block))
176+
if let Some(Expr {
177+
kind: ExprKind::Closure(&Closure { kind, body, .. }),
178+
..
179+
}) = block.expr
180+
&& let ClosureKind::Coroutine(CoroutineKind::Desugared(CoroutineDesugaring::Async, CoroutineSource::Block)) =
181+
kind
182182
{
183-
return Some(closure_body);
183+
return Some(cx.tcx.hir().body(body));
184184
}
185185

186186
None

clippy_lints/src/manual_non_exhaustive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl EarlyLintPass for ManualNonExhaustiveStruct {
103103

104104
if let ast::ItemKind::Struct(variant_data, _) = &item.kind {
105105
let (fields, delimiter) = match variant_data {
106-
ast::VariantData::Struct(fields, _) => (&**fields, '{'),
106+
ast::VariantData::Struct { fields, .. } => (&**fields, '{'),
107107
ast::VariantData::Tuple(fields, _) => (&**fields, '('),
108108
ast::VariantData::Unit(_) => return,
109109
};

clippy_lints/src/methods/iter_kv_map.rs

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ pub(super) fn check<'tcx>(
3232
&& let Body {
3333
params: [p],
3434
value: body_expr,
35-
coroutine_kind: _,
3635
} = cx.tcx.hir().body(c.body)
3736
&& let PatKind::Tuple([key_pat, val_pat], _) = p.pat.kind
3837
&& let (replacement_kind, annotation, bound_ident) = match (&key_pat.kind, &val_pat.kind) {

clippy_lints/src/methods/unnecessary_to_owned.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -445,11 +445,12 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
445445
{
446446
let bound_fn_sig = cx.tcx.fn_sig(callee_def_id);
447447
let fn_sig = bound_fn_sig.skip_binder();
448-
if let Some(arg_index) = recv.into_iter().chain(call_args).position(|arg| arg.hir_id == expr.hir_id)
448+
if let Some(arg_index) = recv
449+
.into_iter()
450+
.chain(call_args)
451+
.position(|arg| arg.hir_id == expr.hir_id)
449452
&& let param_ty = fn_sig.input(arg_index).skip_binder()
450-
&& let ty::Param(ParamTy { index: param_index , ..}) = *param_ty.kind()
451-
// https://github.com/rust-lang/rust-clippy/issues/9504 and https://github.com/rust-lang/rust-clippy/issues/10021
452-
&& (param_index as usize) < call_generic_args.len()
453+
&& let ty::Param(ParamTy { index: param_index, .. }) = *param_ty.kind()
453454
{
454455
if fn_sig
455456
.skip_binder()

clippy_lints/src/missing_const_for_fn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn {
153153

154154
if let Err((span, err)) = is_min_const_fn(cx.tcx, mir, &self.msrv) {
155155
if cx.tcx.is_const_fn_raw(def_id.to_def_id()) {
156-
cx.tcx.sess.span_err(span, err);
156+
cx.tcx.dcx().span_err(span, err);
157157
}
158158
} else {
159159
span_lint(cx, MISSING_CONST_FOR_FN, span, "this could be a `const fn`");

clippy_lints/src/needless_continue.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,11 @@ where
220220
F: FnMut(&ast::Block, Option<&ast::Label>),
221221
{
222222
if let ast::ExprKind::While(_, loop_block, label)
223-
| ast::ExprKind::ForLoop(_, _, loop_block, label)
223+
| ast::ExprKind::ForLoop {
224+
body: loop_block,
225+
label,
226+
..
227+
}
224228
| ast::ExprKind::Loop(loop_block, label, ..) = &expr.kind
225229
{
226230
func(loop_block, label.as_ref());

clippy_lints/src/needless_question_mark.rs

+15-17
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use clippy_utils::path_res;
33
use clippy_utils::source::snippet;
44
use rustc_errors::Applicability;
55
use rustc_hir::def::{DefKind, Res};
6-
use rustc_hir::{Block, Body, CoroutineKind, CoroutineSource, Expr, ExprKind, LangItem, MatchSource, QPath};
6+
use rustc_hir::{Block, Body, Expr, ExprKind, LangItem, MatchSource, QPath};
77
use rustc_lint::{LateContext, LateLintPass};
88
use rustc_session::declare_lint_pass;
99

@@ -86,22 +86,20 @@ impl LateLintPass<'_> for NeedlessQuestionMark {
8686
}
8787

8888
fn check_body(&mut self, cx: &LateContext<'_>, body: &'_ Body<'_>) {
89-
if let Some(CoroutineKind::Async(CoroutineSource::Fn)) = body.coroutine_kind {
90-
if let ExprKind::Block(
91-
Block {
92-
expr:
93-
Some(Expr {
94-
kind: ExprKind::DropTemps(async_body),
95-
..
96-
}),
97-
..
98-
},
99-
_,
100-
) = body.value.kind
101-
{
102-
if let ExprKind::Block(Block { expr: Some(expr), .. }, ..) = async_body.kind {
103-
check(cx, expr);
104-
}
89+
if let ExprKind::Block(
90+
Block {
91+
expr:
92+
Some(Expr {
93+
kind: ExprKind::DropTemps(async_body),
94+
..
95+
}),
96+
..
97+
},
98+
_,
99+
) = body.value.kind
100+
{
101+
if let ExprKind::Block(Block { expr: Some(expr), .. }, ..) = async_body.kind {
102+
check(cx, expr.peel_blocks());
105103
}
106104
} else {
107105
check(cx, body.value.peel_blocks());

clippy_lints/src/redundant_async_block.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ use clippy_utils::source::{snippet, walk_span_to_context};
66
use clippy_utils::ty::implements_trait;
77
use clippy_utils::visitors::for_each_expr;
88
use rustc_errors::Applicability;
9-
use rustc_hir::{Closure, CoroutineKind, CoroutineSource, Expr, ExprKind, MatchSource};
9+
use rustc_hir::{
10+
Closure, ClosureKind, CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, ExprKind, MatchSource,
11+
};
1012
use rustc_lint::{LateContext, LateLintPass};
1113
use rustc_middle::lint::in_external_macro;
1214
use rustc_middle::ty::UpvarCapture;
@@ -73,9 +75,15 @@ impl<'tcx> LateLintPass<'tcx> for RedundantAsyncBlock {
7375
/// If `expr` is a desugared `async` block, return the original expression if it does not capture
7476
/// any variable by ref.
7577
fn desugar_async_block<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> {
76-
if let ExprKind::Closure(Closure { body, def_id, .. }) = expr.kind
78+
if let ExprKind::Closure(Closure { body, def_id, kind, .. }) = expr.kind
7779
&& let body = cx.tcx.hir().body(*body)
78-
&& matches!(body.coroutine_kind, Some(CoroutineKind::Async(CoroutineSource::Block)))
80+
&& matches!(
81+
kind,
82+
ClosureKind::Coroutine(CoroutineKind::Desugared(
83+
CoroutineDesugaring::Async,
84+
CoroutineSource::Block
85+
))
86+
)
7987
{
8088
cx.typeck_results()
8189
.closure_min_captures

0 commit comments

Comments
 (0)