Skip to content

Commit 2b030eb

Browse files
committed
Auto merge of rust-lang#11694 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
2 parents 23af253 + a585cda commit 2b030eb

File tree

83 files changed

+316
-378
lines changed

Some content is hidden

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

83 files changed

+316
-378
lines changed

clippy_lints/src/async_yields_async.rs

+3-3
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::{AsyncGeneratorKind, Body, BodyId, ExprKind, GeneratorKind, QPath};
5+
use rustc_hir::{AsyncCoroutineKind, Body, BodyId, CoroutineKind, ExprKind, QPath};
66
use rustc_lint::{LateContext, LateLintPass};
77
use rustc_session::{declare_lint_pass, declare_tool_lint};
88

@@ -45,10 +45,10 @@ declare_lint_pass!(AsyncYieldsAsync => [ASYNC_YIELDS_ASYNC]);
4545

4646
impl<'tcx> LateLintPass<'tcx> for AsyncYieldsAsync {
4747
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) {
48-
use AsyncGeneratorKind::{Block, Closure};
48+
use AsyncCoroutineKind::{Block, Closure};
4949
// For functions, with explicitly defined types, don't warn.
5050
// XXXkhuey maybe we should?
51-
if let Some(GeneratorKind::Async(Block | Closure)) = body.generator_kind {
51+
if let Some(CoroutineKind::Async(Block | Closure)) = body.coroutine_kind {
5252
if let Some(future_trait_def_id) = cx.tcx.lang_items().future_trait() {
5353
let body_id = BodyId {
5454
hir_id: body.value.hir_id,

clippy_lints/src/attrs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ declare_clippy_lint! {
183183

184184
declare_clippy_lint! {
185185
/// ### What it does
186-
/// Checks for empty lines after documenation comments.
186+
/// Checks for empty lines after documentation comments.
187187
///
188188
/// ### Why is this bad?
189189
/// The documentation comment was most likely meant to be an inner attribute or regular comment.
@@ -795,7 +795,7 @@ impl EarlyLintPass for EarlyAttributes {
795795

796796
/// Check for empty lines after outer attributes.
797797
///
798-
/// Attributes and documenation comments are both considered outer attributes
798+
/// Attributes and documentation comments are both considered outer attributes
799799
/// by the AST. However, the average user likely considers them to be different.
800800
/// Checking for empty lines after each of these attributes is split into two different
801801
/// lints but can share the same logic.

clippy_lints/src/await_holding_invalid.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use clippy_utils::diagnostics::span_lint_and_then;
22
use clippy_utils::{match_def_path, paths};
33
use rustc_data_structures::fx::FxHashMap;
44
use rustc_hir::def_id::DefId;
5-
use rustc_hir::{AsyncGeneratorKind, Body, GeneratorKind};
5+
use rustc_hir::{AsyncCoroutineKind, Body, CoroutineKind};
66
use rustc_lint::{LateContext, LateLintPass};
7-
use rustc_middle::mir::GeneratorLayout;
7+
use rustc_middle::mir::CoroutineLayout;
88
use rustc_session::{declare_tool_lint, impl_lint_pass};
99
use rustc_span::{sym, Span};
1010

@@ -195,26 +195,26 @@ impl LateLintPass<'_> for AwaitHolding {
195195
}
196196

197197
fn check_body(&mut self, cx: &LateContext<'_>, body: &'_ Body<'_>) {
198-
use AsyncGeneratorKind::{Block, Closure, Fn};
199-
if let Some(GeneratorKind::Async(Block | Closure | Fn)) = body.generator_kind {
198+
use AsyncCoroutineKind::{Block, Closure, Fn};
199+
if let Some(CoroutineKind::Async(Block | Closure | Fn)) = body.coroutine_kind {
200200
let def_id = cx.tcx.hir().body_owner_def_id(body.id());
201-
if let Some(generator_layout) = cx.tcx.mir_generator_witnesses(def_id) {
202-
self.check_interior_types(cx, generator_layout);
201+
if let Some(coroutine_layout) = cx.tcx.mir_coroutine_witnesses(def_id) {
202+
self.check_interior_types(cx, coroutine_layout);
203203
}
204204
}
205205
}
206206
}
207207

208208
impl AwaitHolding {
209-
fn check_interior_types(&self, cx: &LateContext<'_>, generator: &GeneratorLayout<'_>) {
210-
for (ty_index, ty_cause) in generator.field_tys.iter_enumerated() {
209+
fn check_interior_types(&self, cx: &LateContext<'_>, coroutine: &CoroutineLayout<'_>) {
210+
for (ty_index, ty_cause) in coroutine.field_tys.iter_enumerated() {
211211
if let rustc_middle::ty::Adt(adt, _) = ty_cause.ty.kind() {
212212
let await_points = || {
213-
generator
213+
coroutine
214214
.variant_source_info
215215
.iter_enumerated()
216216
.filter_map(|(variant, source_info)| {
217-
generator.variant_fields[variant]
217+
coroutine.variant_fields[variant]
218218
.raw
219219
.contains(&ty_index)
220220
.then_some(source_info.span)
@@ -287,5 +287,8 @@ fn is_mutex_guard(cx: &LateContext<'_>, def_id: DefId) -> bool {
287287
}
288288

289289
fn is_refcell_ref(cx: &LateContext<'_>, def_id: DefId) -> bool {
290-
match_def_path(cx, def_id, &paths::REFCELL_REF) || match_def_path(cx, def_id, &paths::REFCELL_REFMUT)
290+
matches!(
291+
cx.tcx.get_diagnostic_name(def_id),
292+
Some(sym::RefCellRef | sym::RefCellRefMut)
293+
)
291294
}

clippy_lints/src/box_default.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::macros::macro_backtrace;
33
use clippy_utils::ty::expr_sig;
4-
use clippy_utils::{get_parent_node, is_default_equivalent, match_path, path_def_id, paths};
4+
use clippy_utils::{get_parent_node, is_default_equivalent, path_def_id};
55
use rustc_errors::Applicability;
6+
use rustc_hir::def::Res;
67
use rustc_hir::intravisit::{walk_ty, Visitor};
78
use rustc_hir::{Block, Expr, ExprKind, Local, Node, QPath, TyKind};
89
use rustc_lint::{LateContext, LateLintPass, LintContext};
@@ -55,7 +56,7 @@ impl LateLintPass<'_> for BoxDefault {
5556
expr.span,
5657
"`Box::new(_)` of default value",
5758
"try",
58-
if is_plain_default(arg_path) || given_type(cx, expr) {
59+
if is_plain_default(cx, arg_path) || given_type(cx, expr) {
5960
"Box::default()".into()
6061
} else if let Some(arg_ty) = cx.typeck_results().expr_ty(arg).make_suggestable(cx.tcx, true) {
6162
with_forced_trimmed_paths!(format!("Box::<{arg_ty}>::default()"))
@@ -68,11 +69,13 @@ impl LateLintPass<'_> for BoxDefault {
6869
}
6970
}
7071

71-
fn is_plain_default(arg_path: &Expr<'_>) -> bool {
72+
fn is_plain_default(cx: &LateContext<'_>, arg_path: &Expr<'_>) -> bool {
7273
// we need to match the actual path so we don't match e.g. "u8::default"
73-
if let ExprKind::Path(QPath::Resolved(None, path)) = &arg_path.kind {
74+
if let ExprKind::Path(QPath::Resolved(None, path)) = &arg_path.kind
75+
&& let Res::Def(_, def_id) = path.res
76+
{
7477
// avoid generic parameters
75-
match_path(path, &paths::DEFAULT_TRAIT_METHOD) && path.segments.iter().all(|seg| seg.args.is_none())
78+
cx.tcx.is_diagnostic_item(sym::default_fn, def_id) && path.segments.iter().all(|seg| seg.args.is_none())
7679
} else {
7780
false
7881
}

clippy_lints/src/casts/cast_ptr_alignment.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint;
22
use clippy_utils::ty::is_c_void;
3-
use clippy_utils::{get_parent_expr, is_hir_ty_cfg_dependant, match_any_def_paths, paths};
3+
use clippy_utils::{get_parent_expr, is_hir_ty_cfg_dependant};
44
use rustc_hir::{Expr, ExprKind, GenericArg};
55
use rustc_lint::LateContext;
66
use rustc_middle::ty::layout::LayoutOf;
@@ -75,16 +75,17 @@ fn is_used_as_unaligned(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
7575
}
7676
},
7777
ExprKind::Call(func, [arg, ..]) if arg.hir_id == e.hir_id => {
78-
static PATHS: &[&[&str]] = &[
79-
paths::PTR_READ_UNALIGNED.as_slice(),
80-
paths::PTR_UNALIGNED_VOLATILE_LOAD.as_slice(),
81-
paths::PTR_UNALIGNED_VOLATILE_STORE.as_slice(),
82-
];
83-
8478
if let ExprKind::Path(path) = &func.kind
8579
&& let Some(def_id) = cx.qpath_res(path, func.hir_id).opt_def_id()
86-
&& (match_any_def_paths(cx, def_id, PATHS).is_some()
87-
|| cx.tcx.is_diagnostic_item(sym::ptr_write_unaligned, def_id))
80+
&& matches!(
81+
cx.tcx.get_diagnostic_name(def_id),
82+
Some(
83+
sym::ptr_write_unaligned
84+
| sym::ptr_read_unaligned
85+
| sym::intrinsics_unaligned_volatile_load
86+
| sym::intrinsics_unaligned_volatile_store
87+
)
88+
)
8889
{
8990
true
9091
} else {

clippy_lints/src/casts/cast_slice_from_raw_parts.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::msrvs::{self, Msrv};
33
use clippy_utils::source::snippet_with_context;
4-
use clippy_utils::{match_def_path, paths};
54
use if_chain::if_chain;
65
use rustc_errors::Applicability;
76
use rustc_hir::def_id::DefId;
87
use rustc_hir::{Expr, ExprKind};
98
use rustc_lint::LateContext;
109
use rustc_middle::ty::{self, Ty};
10+
use rustc_span::sym;
1111

1212
use super::CAST_SLICE_FROM_RAW_PARTS;
1313

@@ -17,12 +17,10 @@ enum RawPartsKind {
1717
}
1818

1919
fn raw_parts_kind(cx: &LateContext<'_>, did: DefId) -> Option<RawPartsKind> {
20-
if match_def_path(cx, did, &paths::SLICE_FROM_RAW_PARTS) {
21-
Some(RawPartsKind::Immutable)
22-
} else if match_def_path(cx, did, &paths::SLICE_FROM_RAW_PARTS_MUT) {
23-
Some(RawPartsKind::Mutable)
24-
} else {
25-
None
20+
match cx.tcx.get_diagnostic_name(did)? {
21+
sym::slice_from_raw_parts => Some(RawPartsKind::Immutable),
22+
sym::slice_from_raw_parts_mut => Some(RawPartsKind::Mutable),
23+
_ => None,
2624
}
2725
}
2826

clippy_lints/src/create_dir.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::source::snippet;
3-
use clippy_utils::{match_def_path, paths};
43
use if_chain::if_chain;
54
use rustc_errors::Applicability;
65
use rustc_hir::{Expr, ExprKind};
76
use rustc_lint::{LateContext, LateLintPass};
87
use rustc_session::{declare_lint_pass, declare_tool_lint};
8+
use rustc_span::sym;
99

1010
declare_clippy_lint! {
1111
/// ### What it does
@@ -37,7 +37,7 @@ impl LateLintPass<'_> for CreateDir {
3737
if let ExprKind::Call(func, [arg, ..]) = expr.kind;
3838
if let ExprKind::Path(ref path) = func.kind;
3939
if let Some(def_id) = cx.qpath_res(path, func.hir_id).opt_def_id();
40-
if match_def_path(cx, def_id, &paths::STD_FS_CREATE_DIR);
40+
if cx.tcx.is_diagnostic_item(sym::fs_create_dir, def_id);
4141
then {
4242
span_lint_and_sugg(
4343
cx,

clippy_lints/src/default.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use clippy_utils::diagnostics::{span_lint_and_note, span_lint_and_sugg};
22
use clippy_utils::source::snippet_with_context;
33
use clippy_utils::ty::{has_drop, is_copy};
4-
use clippy_utils::{
5-
any_parent_is_automatically_derived, contains_name, get_parent_expr, is_from_proc_macro, match_def_path, paths,
6-
};
4+
use clippy_utils::{any_parent_is_automatically_derived, contains_name, get_parent_expr, is_from_proc_macro};
75
use if_chain::if_chain;
86
use rustc_data_structures::fx::FxHashSet;
97
use rustc_errors::Applicability;
@@ -14,7 +12,7 @@ use rustc_middle::ty;
1412
use rustc_middle::ty::print::with_forced_trimmed_paths;
1513
use rustc_session::{declare_tool_lint, impl_lint_pass};
1614
use rustc_span::symbol::{Ident, Symbol};
17-
use rustc_span::Span;
15+
use rustc_span::{sym, Span};
1816

1917
declare_clippy_lint! {
2018
/// ### What it does
@@ -91,7 +89,7 @@ impl<'tcx> LateLintPass<'tcx> for Default {
9189
if !any_parent_is_automatically_derived(cx.tcx, expr.hir_id);
9290
if let ExprKind::Path(ref qpath) = path.kind;
9391
if let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id();
94-
if match_def_path(cx, def_id, &paths::DEFAULT_TRAIT_METHOD);
92+
if cx.tcx.is_diagnostic_item(sym::default_fn, def_id);
9593
if !is_update_syntax_base(cx, expr);
9694
// Detect and ignore <Foo as Default>::default() because these calls do explicitly name the type.
9795
if let QPath::Resolved(None, _path) = qpath;
@@ -268,7 +266,7 @@ fn is_expr_default<'tcx>(expr: &'tcx Expr<'tcx>, cx: &LateContext<'tcx>) -> bool
268266
if let Res::Def(_, def_id) = cx.qpath_res(qpath, fn_expr.hir_id);
269267
then {
270268
// right hand side of assignment is `Default::default`
271-
match_def_path(cx, def_id, &paths::DEFAULT_TRAIT_METHOD)
269+
cx.tcx.is_diagnostic_item(sym::default_fn, def_id)
272270
} else {
273271
false
274272
}

clippy_lints/src/default_constructed_unit_structs.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
2-
use clippy_utils::{is_ty_alias, match_def_path, paths};
2+
use clippy_utils::is_ty_alias;
33
use hir::def::Res;
44
use hir::ExprKind;
55
use rustc_errors::Applicability;
66
use rustc_hir as hir;
77
use rustc_lint::{LateContext, LateLintPass};
88
use rustc_middle::ty;
99
use rustc_session::{declare_lint_pass, declare_tool_lint};
10+
use rustc_span::sym;
1011

1112
declare_clippy_lint! {
1213
/// ### What it does
@@ -63,7 +64,7 @@ impl LateLintPass<'_> for DefaultConstructedUnitStructs {
6364
// `<Foo as Bar>::Assoc` cannot be used as a constructor
6465
if !is_alias(*base);
6566
if let Res::Def(_, def_id) = cx.qpath_res(qpath, fn_expr.hir_id);
66-
if match_def_path(cx, def_id, &paths::DEFAULT_TRAIT_METHOD);
67+
if cx.tcx.is_diagnostic_item(sym::default_fn, def_id);
6768
// make sure we have a struct with no fields (unit struct)
6869
if let ty::Adt(def, ..) = cx.typeck_results().expr_ty(expr).kind();
6970
if def.is_struct();

clippy_lints/src/default_instead_of_iter_empty.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
2+
use clippy_utils::last_path_segment;
23
use clippy_utils::source::snippet_with_context;
3-
use clippy_utils::{last_path_segment, match_def_path, paths};
44
use rustc_errors::Applicability;
55
use rustc_hir::{def, Expr, ExprKind, GenericArg, QPath, TyKind};
66
use rustc_lint::{LateContext, LateLintPass};
77
use rustc_session::{declare_lint_pass, declare_tool_lint};
8-
use rustc_span::SyntaxContext;
8+
use rustc_span::{sym, SyntaxContext};
99

1010
declare_clippy_lint! {
1111
/// ### What it does
@@ -37,7 +37,7 @@ impl<'tcx> LateLintPass<'tcx> for DefaultIterEmpty {
3737
&& let TyKind::Path(ty_path) = &ty.kind
3838
&& let QPath::Resolved(None, path) = ty_path
3939
&& let def::Res::Def(_, def_id) = &path.res
40-
&& match_def_path(cx, *def_id, &paths::ITER_EMPTY)
40+
&& cx.tcx.is_diagnostic_item(sym::IterEmpty, *def_id)
4141
&& let ctxt = expr.span.ctxt()
4242
&& ty.span.ctxt() == ctxt
4343
{

clippy_lints/src/dereference.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ fn deref_method_same_type<'tcx>(result_ty: Ty<'tcx>, arg_ty: Ty<'tcx>) -> bool {
701701

702702
fn in_postfix_position<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) -> bool {
703703
if let Some(parent) = get_parent_expr(cx, e)
704-
&& parent.span.ctxt() == e.span.ctxt()
704+
&& parent.span.eq_ctxt(e.span)
705705
{
706706
match parent.kind {
707707
ExprKind::Call(child, _) | ExprKind::MethodCall(_, child, _, _) | ExprKind::Index(child, _, _)
@@ -842,8 +842,8 @@ impl TyCoercionStability {
842842
| ty::Adt(..)
843843
| ty::Foreign(_)
844844
| ty::FnDef(..)
845-
| ty::Generator(..)
846-
| ty::GeneratorWitness(..)
845+
| ty::Coroutine(..)
846+
| ty::CoroutineWitness(..)
847847
| ty::Closure(..)
848848
| ty::Never
849849
| ty::Tuple(_)

clippy_lints/src/doc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,8 @@ fn lint_for_missing_headers(
436436
let body = cx.tcx.hir().body(body_id);
437437
let ret_ty = typeck.expr_ty(body.value);
438438
if implements_trait(cx, ret_ty, future, &[]);
439-
if let ty::Generator(_, subs, _) = ret_ty.kind();
440-
if is_type_diagnostic_item(cx, subs.as_generator().return_ty(), sym::Result);
439+
if let ty::Coroutine(_, subs, _) = ret_ty.kind();
440+
if is_type_diagnostic_item(cx, subs.as_coroutine().return_ty(), sym::Result);
441441
then {
442442
span_lint(
443443
cx,

clippy_lints/src/entry.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ fn try_parse_contains<'tcx>(cx: &LateContext<'_>, expr: &'tcx Expr<'_>) -> Optio
241241
},
242242
],
243243
_,
244-
) if key_span.ctxt() == expr.span.ctxt() => {
244+
) if key_span.eq_ctxt(expr.span) => {
245245
let id = cx.typeck_results().type_dependent_def_id(expr.hir_id)?;
246246
let expr = ContainsExpr {
247247
negated,

clippy_lints/src/exit.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use clippy_utils::diagnostics::span_lint;
2-
use clippy_utils::{is_entrypoint_fn, match_def_path, paths};
2+
use clippy_utils::is_entrypoint_fn;
33
use if_chain::if_chain;
44
use rustc_hir::{Expr, ExprKind, Item, ItemKind, Node};
55
use rustc_lint::{LateContext, LateLintPass};
66
use rustc_session::{declare_lint_pass, declare_tool_lint};
7+
use rustc_span::sym;
78

89
declare_clippy_lint! {
910
/// ### What it does
@@ -45,7 +46,7 @@ impl<'tcx> LateLintPass<'tcx> for Exit {
4546
if let ExprKind::Call(path_expr, _args) = e.kind;
4647
if let ExprKind::Path(ref path) = path_expr.kind;
4748
if let Some(def_id) = cx.qpath_res(path, path_expr.hir_id).opt_def_id();
48-
if match_def_path(cx, def_id, &paths::EXIT);
49+
if cx.tcx.is_diagnostic_item(sym::process_exit, def_id);
4950
let parent = cx.tcx.hir().get_parent_item(e.hir_id).def_id;
5051
if let Some(Node::Item(Item{kind: ItemKind::Fn(..), ..})) = cx.tcx.hir().find_by_def_id(parent);
5152
// If the next item up is a function we check if it is an entry point

0 commit comments

Comments
 (0)