Skip to content

Commit ac4c209

Browse files
committed
Auto merge of #12038 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
2 parents 7343db9 + 2a4c7d2 commit ac4c209

Some content is hidden

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

41 files changed

+202
-128
lines changed

Cargo.toml

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

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

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)