Skip to content

Commit 080b587

Browse files
committed
Auto merge of rust-lang#11398 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
2 parents 202c846 + 9334e5d commit 080b587

25 files changed

+52
-39
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.73"
3+
version = "0.1.74"
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/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.73"
3+
version = "0.1.74"
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/casts/cast_ptr_alignment.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use rustc_hir::{Expr, ExprKind, GenericArg};
55
use rustc_lint::LateContext;
66
use rustc_middle::ty::layout::LayoutOf;
77
use rustc_middle::ty::{self, Ty};
8+
use rustc_span::sym;
89

910
use super::CAST_PTR_ALIGNMENT;
1011

@@ -76,13 +77,14 @@ fn is_used_as_unaligned(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
7677
ExprKind::Call(func, [arg, ..]) if arg.hir_id == e.hir_id => {
7778
static PATHS: &[&[&str]] = &[
7879
paths::PTR_READ_UNALIGNED.as_slice(),
79-
paths::PTR_WRITE_UNALIGNED.as_slice(),
8080
paths::PTR_UNALIGNED_VOLATILE_LOAD.as_slice(),
8181
paths::PTR_UNALIGNED_VOLATILE_STORE.as_slice(),
8282
];
83+
8384
if let ExprKind::Path(path) = &func.kind
8485
&& let Some(def_id) = cx.qpath_res(path, func.hir_id).opt_def_id()
85-
&& match_any_def_paths(cx, def_id, PATHS).is_some()
86+
&& (match_any_def_paths(cx, def_id, PATHS).is_some()
87+
|| cx.tcx.is_diagnostic_item(sym::ptr_write_unaligned, def_id))
8688
{
8789
true
8890
} else {

clippy_lints/src/dereference.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,8 @@ fn in_postfix_position<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) -> boo
802802
match parent.kind {
803803
ExprKind::Call(child, _) | ExprKind::MethodCall(_, child, _, _) | ExprKind::Index(child, _, _)
804804
if child.hir_id == e.hir_id => true,
805-
ExprKind::Field(_, _) | ExprKind::Match(_, _, MatchSource::TryDesugar | MatchSource::AwaitDesugar) => true,
805+
ExprKind::Match(.., MatchSource::TryDesugar(_) | MatchSource::AwaitDesugar)
806+
| ExprKind::Field(_, _) => true,
806807
_ => false,
807808
}
808809
} else {

clippy_lints/src/matches/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ impl<'tcx> LateLintPass<'tcx> for Matches {
10381038
wild_in_or_pats::check(cx, arms);
10391039
}
10401040

1041-
if source == MatchSource::TryDesugar {
1041+
if let MatchSource::TryDesugar(_) = source {
10421042
try_err::check(cx, expr, ex);
10431043
}
10441044

clippy_lints/src/matches/try_err.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, scrutine
8080

8181
/// Finds function return type by examining return expressions in match arms.
8282
fn find_return_type<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx ExprKind<'_>) -> Option<Ty<'tcx>> {
83-
if let ExprKind::Match(_, arms, MatchSource::TryDesugar) = expr {
83+
if let ExprKind::Match(_, arms, MatchSource::TryDesugar(_)) = expr {
8484
for arm in *arms {
8585
if let ExprKind::Ret(Some(ret)) = arm.body.kind {
8686
return Some(cx.typeck_results().expr_ty(ret));

clippy_lints/src/methods/clone_on_copy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub(super) fn check(
6464
ExprKind::Path(QPath::LangItem(rustc_hir::LangItem::TryTraitBranch, _, _))
6565
),
6666
ExprKind::MethodCall(_, self_arg, ..) if expr.hir_id == self_arg.hir_id => true,
67-
ExprKind::Match(_, _, MatchSource::TryDesugar | MatchSource::AwaitDesugar)
67+
ExprKind::Match(_, _, MatchSource::TryDesugar(_) | MatchSource::AwaitDesugar)
6868
| ExprKind::Field(..)
6969
| ExprKind::Index(..) => true,
7070
_ => false,

clippy_lints/src/methods/str_splitn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ fn indirect_usage<'tcx>(
236236
!matches!(
237237
node,
238238
Node::Expr(Expr {
239-
kind: ExprKind::Match(.., MatchSource::TryDesugar),
239+
kind: ExprKind::Match(.., MatchSource::TryDesugar(_)),
240240
..
241241
})
242242
)

clippy_lints/src/missing_inline.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ fn is_executable_or_proc_macro(cx: &LateContext<'_>) -> bool {
7474
use rustc_session::config::CrateType;
7575

7676
cx.tcx
77-
.sess
7877
.crate_types()
7978
.iter()
8079
.any(|t: &CrateType| matches!(t, CrateType::Executable | CrateType::ProcMacro))

clippy_lints/src/needless_question_mark.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
122122
} else {
123123
return;
124124
};
125-
if let ExprKind::Match(inner_expr_with_q, _, MatchSource::TryDesugar) = &arg.kind;
125+
if let ExprKind::Match(inner_expr_with_q, _, MatchSource::TryDesugar(_)) = &arg.kind;
126126
if let ExprKind::Call(called, [inner_expr]) = &inner_expr_with_q.kind;
127127
if let ExprKind::Path(QPath::LangItem(LangItem::TryTraitBranch, ..)) = &called.kind;
128128
if expr.span.ctxt() == inner_expr.span.ctxt();

clippy_lints/src/ptr.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
278278

279279
fn check_invalid_ptr_usage<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
280280
// (fn_path, arg_indices) - `arg_indices` are the `arg` positions where null would cause U.B.
281-
const INVALID_NULL_PTR_USAGE_TABLE: [(&[&str], &[usize]); 16] = [
281+
const INVALID_NULL_PTR_USAGE_TABLE: [(&[&str], &[usize]); 13] = [
282282
(&paths::SLICE_FROM_RAW_PARTS, &[0]),
283283
(&paths::SLICE_FROM_RAW_PARTS_MUT, &[0]),
284284
(&paths::PTR_COPY, &[0, 1]),
@@ -291,20 +291,33 @@ fn check_invalid_ptr_usage<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
291291
(&paths::PTR_SLICE_FROM_RAW_PARTS_MUT, &[0]),
292292
(&paths::PTR_SWAP, &[0, 1]),
293293
(&paths::PTR_SWAP_NONOVERLAPPING, &[0, 1]),
294-
(&paths::PTR_WRITE, &[0]),
295-
(&paths::PTR_WRITE_UNALIGNED, &[0]),
296-
(&paths::PTR_WRITE_VOLATILE, &[0]),
297294
(&paths::PTR_WRITE_BYTES, &[0]),
298295
];
296+
let invalid_null_ptr_usage_table_diag_items: [(Option<DefId>, &[usize]); 3] = [
297+
(cx.tcx.get_diagnostic_item(sym::ptr_write), &[0]),
298+
(cx.tcx.get_diagnostic_item(sym::ptr_write_unaligned), &[0]),
299+
(cx.tcx.get_diagnostic_item(sym::ptr_write_volatile), &[0]),
300+
];
299301

300302
if_chain! {
301303
if let ExprKind::Call(fun, args) = expr.kind;
302304
if let ExprKind::Path(ref qpath) = fun.kind;
303305
if let Some(fun_def_id) = cx.qpath_res(qpath, fun.hir_id).opt_def_id();
304306
let fun_def_path = cx.get_def_path(fun_def_id).into_iter().map(Symbol::to_ident_string).collect::<Vec<_>>();
305-
if let Some(&(_, arg_indices)) = INVALID_NULL_PTR_USAGE_TABLE
307+
if let Some(arg_indices) = INVALID_NULL_PTR_USAGE_TABLE
306308
.iter()
307-
.find(|&&(fn_path, _)| fn_path == fun_def_path);
309+
.find_map(|&(fn_path, indices)| if fn_path == fun_def_path { Some(indices) } else { None })
310+
.or_else(|| {
311+
invalid_null_ptr_usage_table_diag_items
312+
.iter()
313+
.find_map(|&(def_id, indices)| {
314+
if def_id == Some(fun_def_id) {
315+
Some(indices)
316+
} else {
317+
None
318+
}
319+
})
320+
});
308321
then {
309322
for &arg_idx in arg_indices {
310323
if let Some(arg) = args.get(arg_idx).filter(|arg| is_null_path(cx, arg)) {

clippy_lints/src/question_mark_used.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ declare_lint_pass!(QuestionMarkUsed => [QUESTION_MARK_USED]);
3434

3535
impl<'tcx> LateLintPass<'tcx> for QuestionMarkUsed {
3636
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
37-
if let ExprKind::Match(_, _, MatchSource::TryDesugar) = expr.kind {
37+
if let ExprKind::Match(_, _, MatchSource::TryDesugar(_)) = expr.kind {
3838
if !span_is_local(expr.span) {
3939
return;
4040
}

clippy_lints/src/redundant_closure_call.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl ReturnVisitor {
5252

5353
impl<'tcx> Visitor<'tcx> for ReturnVisitor {
5454
fn visit_expr(&mut self, ex: &'tcx hir::Expr<'tcx>) {
55-
if let hir::ExprKind::Ret(_) | hir::ExprKind::Match(.., hir::MatchSource::TryDesugar) = ex.kind {
55+
if let hir::ExprKind::Ret(_) | hir::ExprKind::Match(.., hir::MatchSource::TryDesugar(_)) = ex.kind {
5656
self.found_return = true;
5757
} else {
5858
hir_visit::walk_expr(self, ex);

clippy_lints/src/returns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl<'tcx> LateLintPass<'tcx> for Return {
164164
if !in_external_macro(cx.sess(), stmt.span)
165165
&& let StmtKind::Semi(expr) = stmt.kind
166166
&& let ExprKind::Ret(Some(ret)) = expr.kind
167-
&& let ExprKind::Match(.., MatchSource::TryDesugar) = ret.kind
167+
&& let ExprKind::Match(.., MatchSource::TryDesugar(_)) = ret.kind
168168
// Ensure this is not the final stmt, otherwise removing it would cause a compile error
169169
&& let OwnerNode::Item(item) = cx.tcx.hir().owner(cx.tcx.hir().get_parent_item(expr.hir_id))
170170
&& let ItemKind::Fn(_, _, body) = item.kind

clippy_lints/src/unit_types/unit_arg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
4242
if cx.typeck_results().expr_ty(arg).is_unit() && !utils::is_unit_literal(arg) {
4343
!matches!(
4444
&arg.kind,
45-
ExprKind::Match(.., MatchSource::TryDesugar) | ExprKind::Path(..)
45+
ExprKind::Match(.., MatchSource::TryDesugar(_)) | ExprKind::Path(..)
4646
)
4747
} else {
4848
false

clippy_lints/src/useless_conversion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
116116
}
117117

118118
match e.kind {
119-
ExprKind::Match(_, arms, MatchSource::TryDesugar) => {
119+
ExprKind::Match(_, arms, MatchSource::TryDesugar(_)) => {
120120
let (ExprKind::Ret(Some(e)) | ExprKind::Break(_, Some(e))) = arms[0].body.kind else {
121121
return;
122122
};

clippy_utils/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_utils"
3-
version = "0.1.73"
3+
version = "0.1.74"
44
edition = "2021"
55
publish = false
66

clippy_utils/src/check_proc_macro.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ fn expr_search_pat(tcx: TyCtxt<'_>, e: &Expr<'_>) -> (Pat, Pat) {
149149
(Pat::Str("for"), Pat::Str("}"))
150150
},
151151
ExprKind::Match(_, _, MatchSource::Normal) => (Pat::Str("match"), Pat::Str("}")),
152-
ExprKind::Match(e, _, MatchSource::TryDesugar) => (expr_search_pat(tcx, e).0, Pat::Str("?")),
152+
ExprKind::Match(e, _, MatchSource::TryDesugar(_)) => (expr_search_pat(tcx, e).0, Pat::Str("?")),
153153
ExprKind::Match(e, _, MatchSource::AwaitDesugar) | ExprKind::Yield(e, YieldSource::Await { .. }) => {
154154
(expr_search_pat(tcx, e).0, Pat::Str("await"))
155155
},

clippy_utils/src/hir_utils.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::tokenize_with_text;
55
use rustc_ast::ast::InlineAsmTemplatePiece;
66
use rustc_data_structures::fx::FxHasher;
77
use rustc_hir::def::Res;
8+
use rustc_hir::MatchSource::TryDesugar;
89
use rustc_hir::{
910
ArrayLen, BinOpKind, BindingAnnotation, Block, BodyId, Closure, Expr, ExprField, ExprKind, FnRetTy, GenericArg,
1011
GenericArgs, Guard, HirId, HirIdMap, InlineAsmOperand, Let, Lifetime, LifetimeName, Pat, PatField, PatKind, Path,
@@ -311,7 +312,7 @@ impl HirEqInterExpr<'_, '_, '_> {
311312
lls == rls && self.eq_block(lb, rb) && both(ll, rl, |l, r| l.ident.name == r.ident.name)
312313
},
313314
(&ExprKind::Match(le, la, ref ls), &ExprKind::Match(re, ra, ref rs)) => {
314-
ls == rs
315+
(ls == rs || (matches!((ls, rs), (TryDesugar(_), TryDesugar(_)))))
315316
&& self.eq_expr(le, re)
316317
&& over(la, ra, |l, r| {
317318
self.eq_pat(l.pat, r.pat)

clippy_utils/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ use rustc_ast::Attribute;
8383
use rustc_data_structures::fx::FxHashMap;
8484
use rustc_data_structures::unhash::UnhashMap;
8585
use rustc_hir::def::{DefKind, Res};
86-
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
86+
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalModDefId, LOCAL_CRATE};
8787
use rustc_hir::hir_id::{HirIdMap, HirIdSet};
8888
use rustc_hir::intravisit::{walk_expr, FnKind, Visitor};
8989
use rustc_hir::LangItem::{OptionNone, OptionSome, ResultErr, ResultOk};
@@ -1765,7 +1765,7 @@ pub fn is_try<'tcx>(cx: &LateContext<'_>, expr: &'tcx Expr<'tcx>) -> Option<&'tc
17651765

17661766
if let ExprKind::Match(_, arms, ref source) = expr.kind {
17671767
// desugared from a `?` operator
1768-
if *source == MatchSource::TryDesugar {
1768+
if let MatchSource::TryDesugar(_) = *source {
17691769
return Some(expr);
17701770
}
17711771

@@ -2370,11 +2370,11 @@ pub fn is_hir_ty_cfg_dependant(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> bool {
23702370
false
23712371
}
23722372

2373-
static TEST_ITEM_NAMES_CACHE: OnceLock<Mutex<FxHashMap<LocalDefId, Vec<Symbol>>>> = OnceLock::new();
2373+
static TEST_ITEM_NAMES_CACHE: OnceLock<Mutex<FxHashMap<LocalModDefId, Vec<Symbol>>>> = OnceLock::new();
23742374

2375-
fn with_test_item_names(tcx: TyCtxt<'_>, module: LocalDefId, f: impl Fn(&[Symbol]) -> bool) -> bool {
2375+
fn with_test_item_names(tcx: TyCtxt<'_>, module: LocalModDefId, f: impl Fn(&[Symbol]) -> bool) -> bool {
23762376
let cache = TEST_ITEM_NAMES_CACHE.get_or_init(|| Mutex::new(FxHashMap::default()));
2377-
let mut map: MutexGuard<'_, FxHashMap<LocalDefId, Vec<Symbol>>> = cache.lock().unwrap();
2377+
let mut map: MutexGuard<'_, FxHashMap<LocalModDefId, Vec<Symbol>>> = cache.lock().unwrap();
23782378
let value = map.entry(module);
23792379
match value {
23802380
Entry::Occupied(entry) => f(entry.get()),

clippy_utils/src/paths.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,7 @@ pub const PTR_REPLACE: [&str; 3] = ["core", "ptr", "replace"];
8787
pub const PTR_SWAP: [&str; 3] = ["core", "ptr", "swap"];
8888
pub const PTR_UNALIGNED_VOLATILE_LOAD: [&str; 3] = ["core", "intrinsics", "unaligned_volatile_load"];
8989
pub const PTR_UNALIGNED_VOLATILE_STORE: [&str; 3] = ["core", "intrinsics", "unaligned_volatile_store"];
90-
pub const PTR_WRITE: [&str; 3] = ["core", "ptr", "write"];
9190
pub const PTR_WRITE_BYTES: [&str; 3] = ["core", "intrinsics", "write_bytes"];
92-
pub const PTR_WRITE_UNALIGNED: [&str; 3] = ["core", "ptr", "write_unaligned"];
93-
pub const PTR_WRITE_VOLATILE: [&str; 3] = ["core", "ptr", "write_volatile"];
9491
pub const PUSH_STR: [&str; 4] = ["alloc", "string", "String", "push_str"];
9592
pub const RANGE_ARGUMENT_TRAIT: [&str; 3] = ["core", "ops", "RangeBounds"];
9693
pub const REFCELL_REF: [&str; 3] = ["core", "cell", "Ref"];

clippy_utils/src/qualify_min_const_fn.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,8 @@ fn check_terminator<'tcx>(
291291
| TerminatorKind::FalseUnwind { .. }
292292
| TerminatorKind::Goto { .. }
293293
| TerminatorKind::Return
294-
| TerminatorKind::Resume
295-
| TerminatorKind::Terminate
294+
| TerminatorKind::UnwindResume
295+
| TerminatorKind::UnwindTerminate
296296
| TerminatorKind::Unreachable => Ok(()),
297297
TerminatorKind::Drop { place, .. } => {
298298
if !is_ty_const_destruct(tcx, place.ty(&body.local_decls, tcx).ty, body) {
@@ -415,7 +415,7 @@ fn is_ty_const_destruct<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, body: &Body<'tcx>
415415

416416
if !matches!(
417417
impl_src,
418-
ImplSource::Builtin(BuiltinImplSource::Misc, _) | ImplSource::Param(ty::BoundConstness::ConstIfConst, _)
418+
ImplSource::Builtin(BuiltinImplSource::Misc, _) | ImplSource::Param(_)
419419
) {
420420
return false;
421421
}

clippy_utils/src/visitors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ pub fn for_each_expr_with_closures<'tcx, B, C: Continue>(
161161
/// returns `true` if expr contains match expr desugared from try
162162
fn contains_try(expr: &hir::Expr<'_>) -> bool {
163163
for_each_expr(expr, |e| {
164-
if matches!(e.kind, hir::ExprKind::Match(_, _, hir::MatchSource::TryDesugar)) {
164+
if matches!(e.kind, hir::ExprKind::Match(_, _, hir::MatchSource::TryDesugar(_))) {
165165
ControlFlow::Break(())
166166
} else {
167167
ControlFlow::Continue(())

declare_clippy_lint/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "declare_clippy_lint"
3-
version = "0.1.73"
3+
version = "0.1.74"
44
edition = "2021"
55
publish = false
66

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2023-08-10"
2+
channel = "nightly-2023-08-24"
33
components = ["cargo", "llvm-tools", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt"]

0 commit comments

Comments
 (0)