Skip to content

Commit 60cb29c

Browse files
committed
Auto merge of #12246 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
2 parents 62dcbd6 + 2ca6c84 commit 60cb29c

24 files changed

+110
-121
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.77"
3+
version = "0.1.78"
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.77"
3+
version = "0.1.78"
44
edition = "2021"
55

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

clippy_dev/src/update_lints.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ fn remove_line_splices(s: &str) -> String {
927927
.and_then(|s| s.strip_suffix('"'))
928928
.unwrap_or_else(|| panic!("expected quoted string, found `{s}`"));
929929
let mut res = String::with_capacity(s.len());
930-
unescape::unescape_literal(s, unescape::Mode::Str, &mut |range, ch| {
930+
unescape::unescape_unicode(s, unescape::Mode::Str, &mut |range, ch| {
931931
if ch.is_ok() {
932932
res.push_str(&s[range]);
933933
}

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.77"
3+
version = "0.1.78"
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/dereference.rs

+1
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,7 @@ impl TyCoercionStability {
881881
| ty::Coroutine(..)
882882
| ty::CoroutineWitness(..)
883883
| ty::Closure(..)
884+
| ty::CoroutineClosure(..)
884885
| ty::Never
885886
| ty::Tuple(_)
886887
| ty::Alias(ty::Projection, _) => Self::Deref,

clippy_lints/src/methods/iter_nth_zero.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_span::sym;
1111
use super::ITER_NTH_ZERO;
1212

1313
pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>, arg: &hir::Expr<'_>) {
14-
if let OwnerNode::Item(item) = cx.tcx.hir().owner(cx.tcx.hir().get_parent_item(expr.hir_id))
14+
if let OwnerNode::Item(item) = cx.tcx.hir_owner_node(cx.tcx.hir().get_parent_item(expr.hir_id))
1515
&& let def_id = item.owner_id.to_def_id()
1616
&& is_trait_method(cx, expr, sym::Iterator)
1717
&& let Some(Constant::Int(0)) = constant(cx, cx.typeck_results(), arg)

clippy_lints/src/min_ident_chars.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,7 @@ impl Visitor<'_> for IdentVisitor<'_, '_> {
9393
// reimplement it even if we wanted to
9494
cx.tcx.opt_hir_node(hir_id)
9595
} else {
96-
let Some(owner) = cx.tcx.hir_owner_nodes(hir_id.owner).as_owner() else {
97-
return;
98-
};
96+
let owner = cx.tcx.hir_owner_nodes(hir_id.owner);
9997
owner.nodes.get(hir_id.local_id).copied().flatten().map(|p| p.node)
10098
};
10199
let Some(node) = node else {

clippy_lints/src/operators/arithmetic_side_effects.rs

+31-24
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use super::ARITHMETIC_SIDE_EFFECTS;
22
use clippy_utils::consts::{constant, constant_simple, Constant};
33
use clippy_utils::diagnostics::span_lint;
4-
use clippy_utils::ty::type_diagnostic_name;
4+
use clippy_utils::ty::is_type_diagnostic_item;
55
use clippy_utils::{expr_or_init, is_from_proc_macro, is_lint_allowed, peel_hir_expr_refs, peel_hir_expr_unary};
66
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
77
use rustc_lint::{LateContext, LateLintPass};
8-
use rustc_middle::ty::Ty;
8+
use rustc_middle::ty::{self, Ty};
99
use rustc_session::impl_lint_pass;
1010
use rustc_span::source_map::Spanned;
1111
use rustc_span::symbol::sym;
@@ -88,37 +88,44 @@ impl ArithmeticSideEffects {
8888
}
8989

9090
/// Verifies built-in types that have specific allowed operations
91-
fn has_specific_allowed_type_and_operation(
92-
cx: &LateContext<'_>,
93-
lhs_ty: Ty<'_>,
91+
fn has_specific_allowed_type_and_operation<'tcx>(
92+
cx: &LateContext<'tcx>,
93+
lhs_ty: Ty<'tcx>,
9494
op: &Spanned<hir::BinOpKind>,
95-
rhs_ty: Ty<'_>,
95+
rhs_ty: Ty<'tcx>,
9696
) -> bool {
9797
let is_div_or_rem = matches!(op.node, hir::BinOpKind::Div | hir::BinOpKind::Rem);
98-
let is_non_zero_u = |symbol: Option<Symbol>| {
99-
matches!(
100-
symbol,
101-
Some(
102-
sym::NonZeroU128
103-
| sym::NonZeroU16
104-
| sym::NonZeroU32
105-
| sym::NonZeroU64
106-
| sym::NonZeroU8
107-
| sym::NonZeroUsize
108-
)
109-
)
98+
let is_non_zero_u = |cx: &LateContext<'tcx>, ty: Ty<'tcx>| {
99+
let tcx = cx.tcx;
100+
101+
let ty::Adt(adt, substs) = ty.kind() else { return false };
102+
103+
if !tcx.is_diagnostic_item(sym::NonZero, adt.did()) {
104+
return false;
105+
};
106+
107+
let int_type = substs.type_at(0);
108+
let unsigned_int_types = [
109+
tcx.types.u8,
110+
tcx.types.u16,
111+
tcx.types.u32,
112+
tcx.types.u64,
113+
tcx.types.u128,
114+
tcx.types.usize,
115+
];
116+
117+
unsigned_int_types.contains(&int_type)
110118
};
111119
let is_sat_or_wrap = |ty: Ty<'_>| {
112-
let is_sat = type_diagnostic_name(cx, ty) == Some(sym::Saturating);
113-
let is_wrap = type_diagnostic_name(cx, ty) == Some(sym::Wrapping);
114-
is_sat || is_wrap
120+
is_type_diagnostic_item(cx, ty, sym::Saturating) || is_type_diagnostic_item(cx, ty, sym::Wrapping)
115121
};
116122

117-
// If the RHS is NonZeroU*, then division or module by zero will never occur
118-
if is_non_zero_u(type_diagnostic_name(cx, rhs_ty)) && is_div_or_rem {
123+
// If the RHS is `NonZero<u*>`, then division or module by zero will never occur.
124+
if is_non_zero_u(cx, rhs_ty) && is_div_or_rem {
119125
return true;
120126
}
121-
// `Saturation` and `Wrapping` can overflow if the RHS is zero in a division or module
127+
128+
// `Saturation` and `Wrapping` can overflow if the RHS is zero in a division or module.
122129
if is_sat_or_wrap(lhs_ty) {
123130
return !is_div_or_rem;
124131
}

clippy_lints/src/returns.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl<'tcx> LateLintPass<'tcx> for Return {
196196
&& is_res_lang_ctor(cx, path_res(cx, maybe_constr), ResultErr)
197197

198198
// Ensure this is not the final stmt, otherwise removing it would cause a compile error
199-
&& let OwnerNode::Item(item) = cx.tcx.hir().owner(cx.tcx.hir().get_parent_item(expr.hir_id))
199+
&& let OwnerNode::Item(item) = cx.tcx.hir_owner_node(cx.tcx.hir().get_parent_item(expr.hir_id))
200200
&& let ItemKind::Fn(_, _, body) = item.kind
201201
&& let block = cx.tcx.hir().body(body).value
202202
&& let ExprKind::Block(block, _) = block.kind

clippy_lints/src/transmute/transmute_int_to_non_zero.rs

+33-18
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,55 @@ pub(super) fn check<'tcx>(
1616
to_ty: Ty<'tcx>,
1717
arg: &'tcx Expr<'_>,
1818
) -> bool {
19-
let (ty::Int(_) | ty::Uint(_), Some(to_ty_adt)) = (&from_ty.kind(), to_ty.ty_adt_def()) else {
19+
let tcx = cx.tcx;
20+
21+
let (ty::Int(_) | ty::Uint(_), ty::Adt(adt, substs)) = (&from_ty.kind(), to_ty.kind()) else {
2022
return false;
2123
};
22-
let Some(to_type_sym) = cx.tcx.get_diagnostic_name(to_ty_adt.did()) else {
24+
25+
if !tcx.is_diagnostic_item(sym::NonZero, adt.did()) {
2326
return false;
2427
};
2528

26-
if !matches!(
27-
to_type_sym,
28-
sym::NonZeroU8
29-
| sym::NonZeroU16
30-
| sym::NonZeroU32
31-
| sym::NonZeroU64
32-
| sym::NonZeroU128
33-
| sym::NonZeroI8
34-
| sym::NonZeroI16
35-
| sym::NonZeroI32
36-
| sym::NonZeroI64
37-
| sym::NonZeroI128
38-
) {
29+
// FIXME: This can be simplified once `NonZero<T>` is stable.
30+
let coercable_types = [
31+
("NonZeroU8", tcx.types.u8),
32+
("NonZeroU16", tcx.types.u16),
33+
("NonZeroU32", tcx.types.u32),
34+
("NonZeroU64", tcx.types.u64),
35+
("NonZeroU128", tcx.types.u128),
36+
("NonZeroUsize", tcx.types.usize),
37+
("NonZeroI8", tcx.types.i8),
38+
("NonZeroI16", tcx.types.i16),
39+
("NonZeroI32", tcx.types.i32),
40+
("NonZeroI64", tcx.types.i64),
41+
("NonZeroI128", tcx.types.i128),
42+
("NonZeroIsize", tcx.types.isize),
43+
];
44+
45+
let int_type = substs.type_at(0);
46+
47+
let Some(nonzero_alias) = coercable_types.iter().find_map(|(nonzero_alias, t)| {
48+
if *t == int_type && *t == from_ty {
49+
Some(nonzero_alias)
50+
} else {
51+
None
52+
}
53+
}) else {
3954
return false;
40-
}
55+
};
4156

4257
span_lint_and_then(
4358
cx,
4459
TRANSMUTE_INT_TO_NON_ZERO,
4560
e.span,
46-
&format!("transmute from a `{from_ty}` to a `{to_type_sym}`"),
61+
&format!("transmute from a `{from_ty}` to a `{nonzero_alias}`"),
4762
|diag| {
4863
let arg = sugg::Sugg::hir(cx, arg, "..");
4964
diag.span_suggestion(
5065
e.span,
5166
"consider using",
52-
format!("{to_type_sym}::{}({arg})", sym::new_unchecked),
67+
format!("{nonzero_alias}::{}({arg})", sym::new_unchecked),
5368
Applicability::Unspecified,
5469
);
5570
},

clippy_lints/src/transmute/utils.rs

+1-17
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ pub(super) fn check_cast<'tcx>(
3737
let inherited = Inherited::new(cx.tcx, local_def_id);
3838
let fn_ctxt = FnCtxt::new(&inherited, cx.param_env, local_def_id);
3939

40-
// If we already have errors, we can't be sure we can pointer cast.
41-
assert!(
42-
!fn_ctxt.errors_reported_since_creation(),
43-
"Newly created FnCtxt contained errors"
44-
);
45-
4640
if let Ok(check) = cast::CastCheck::new(
4741
&fn_ctxt,
4842
e,
@@ -53,17 +47,7 @@ pub(super) fn check_cast<'tcx>(
5347
DUMMY_SP,
5448
hir::Constness::NotConst,
5549
) {
56-
let res = check.do_check(&fn_ctxt);
57-
58-
// do_check's documentation says that it might return Ok and create
59-
// errors in the fcx instead of returning Err in some cases. Those cases
60-
// should be filtered out before getting here.
61-
assert!(
62-
!fn_ctxt.errors_reported_since_creation(),
63-
"`fn_ctxt` contained errors after cast check!"
64-
);
65-
66-
res.ok()
50+
check.do_check(&fn_ctxt).ok()
6751
} else {
6852
None
6953
}

clippy_lints/src/utils/author.rs

+3
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,9 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
490490
format!("ClosureKind::Coroutine(CoroutineKind::Coroutine(Movability::{movability:?})")
491491
},
492492
},
493+
ClosureKind::CoroutineClosure(desugaring) => {
494+
format!("ClosureKind::CoroutineClosure(CoroutineDesugaring::{desugaring:?})")
495+
},
493496
};
494497

495498
let ret_ty = match fn_decl.output {

clippy_utils/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy_utils"
3-
version = "0.1.77"
3+
version = "0.1.78"
44
edition = "2021"
55
publish = false
66

declare_clippy_lint/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "declare_clippy_lint"
3-
version = "0.1.77"
3+
version = "0.1.78"
44
edition = "2021"
55
publish = false
66

rust-toolchain

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2024-01-25"
2+
channel = "nightly-2024-02-08"
33
components = ["cargo", "llvm-tools", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt"]

tests/ui/author/blocks.stdout

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ if let ExprKind::Block(block, None) = expr.kind
4040
{
4141
// report your lint here
4242
}
43-
if let ExprKind::Closure { capture_clause: CaptureBy::Value { .. }, fn_decl: fn_decl, body: body_id, closure_kind: ClosureKind::Closure, .. } = expr.kind
43+
if let ExprKind::Closure { capture_clause: CaptureBy::Value { .. }, fn_decl: fn_decl, body: body_id, closure_kind: ClosureKind::CoroutineClosure(CoroutineDesugaring::Async), .. } = expr.kind
4444
&& let FnRetTy::DefaultReturn(_) = fn_decl.output
4545
&& expr1 = &cx.tcx.hir().body(body_id).value
46-
&& let ExprKind::Closure { capture_clause: CaptureBy::Value { .. }, fn_decl: fn_decl1, body: body_id1, closure_kind: ClosureKind::Coroutine(CoroutineKind::Desugared(CoroutineDesugaring::Async, CoroutineSource::Closure)), .. } = expr1.kind
46+
&& let ExprKind::Closure { capture_clause: CaptureBy::Ref, fn_decl: fn_decl1, body: body_id1, closure_kind: ClosureKind::Coroutine(CoroutineKind::Desugared(CoroutineDesugaring::Async, CoroutineSource::Closure)), .. } = expr1.kind
4747
&& let FnRetTy::DefaultReturn(_) = fn_decl1.output
4848
&& expr2 = &cx.tcx.hir().body(body_id1).value
4949
&& let ExprKind::Block(block, None) = expr2.kind

tests/ui/crashes/ice-6254.rs

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ fn main() {
1111
// This used to cause an ICE (https://github.com/rust-lang/rust/issues/78071)
1212
match FOO_REF_REF {
1313
FOO_REF_REF => {},
14-
//~^ ERROR: to use a constant of type `Foo` in a pattern, `Foo` must be annotated
15-
//~| NOTE: for more information, see issue #62411 <https://github.com/rust-lang/ru
1614
Foo(_) => {},
1715
}
1816
}

tests/ui/crashes/ice-6254.stderr

-15
This file was deleted.

tests/ui/expect_tool_lint_rfc_2383.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,8 @@ mod rustc_ok {
2020
pub fn rustc_lints() {
2121
let x = 42.0;
2222

23-
#[expect(illegal_floating_point_literal_pattern)]
24-
match x {
25-
5.0 => {},
26-
6.0 => {},
27-
_ => {},
28-
}
23+
#[expect(invalid_nan_comparisons)]
24+
let _b = x == f32::NAN;
2925
}
3026
}
3127

@@ -38,13 +34,9 @@ mod rustc_warn {
3834
pub fn rustc_lints() {
3935
let x = 42;
4036

41-
#[expect(illegal_floating_point_literal_pattern)]
37+
#[expect(invalid_nan_comparisons)]
4238
//~^ ERROR: this lint expectation is unfulfilled
43-
match x {
44-
5 => {},
45-
6 => {},
46-
_ => {},
47-
}
39+
let _b = x == 5;
4840
}
4941
}
5042

0 commit comments

Comments
 (0)