Skip to content

Commit cb80611

Browse files
committed
Auto merge of #13236 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: ICE fix [`uninit_vec`] through rust-lang/rust#128720
2 parents b1e8792 + e608b2f commit cb80611

27 files changed

+84
-219
lines changed

clippy_lints/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#![feature(f128)]
66
#![feature(f16)]
77
#![feature(if_let_guard)]
8-
#![feature(is_sorted)]
98
#![feature(iter_intersperse)]
109
#![feature(iter_partition_in_place)]
1110
#![feature(let_chains)]

clippy_lints/src/lifetimes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> {
543543
if !lt.is_elided() {
544544
self.unelided_trait_object_lifetime = true;
545545
}
546-
for bound in bounds {
546+
for (bound, _) in bounds {
547547
self.visit_poly_trait_ref(bound);
548548
}
549549
},

clippy_lints/src/methods/map_clone.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ use clippy_config::msrvs::{self, Msrv};
22
use clippy_utils::diagnostics::span_lint_and_sugg;
33
use clippy_utils::source::snippet_with_applicability;
44
use clippy_utils::ty::{is_copy, is_type_diagnostic_item, should_call_clone_as_function};
5-
use clippy_utils::{is_diag_trait_item, match_def_path, paths, peel_blocks};
5+
use clippy_utils::{is_diag_trait_item, peel_blocks};
66
use rustc_errors::Applicability;
7-
use rustc_hir as hir;
87
use rustc_hir::def_id::DefId;
8+
use rustc_hir::{self as hir, LangItem};
99
use rustc_lint::LateContext;
1010
use rustc_middle::mir::Mutability;
1111
use rustc_middle::ty;
@@ -114,7 +114,7 @@ fn handle_path(
114114
recv: &hir::Expr<'_>,
115115
) {
116116
if let Some(path_def_id) = cx.qpath_res(qpath, arg.hir_id).opt_def_id()
117-
&& match_def_path(cx, path_def_id, &paths::CLONE_TRAIT_METHOD)
117+
&& cx.tcx.lang_items().get(LangItem::CloneFn) == Some(path_def_id)
118118
{
119119
// The `copied` and `cloned` methods are only available on `&T` and `&mut T` in `Option`
120120
// and `Result`.

clippy_lints/src/methods/useless_asref.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::source::snippet_with_applicability;
33
use clippy_utils::ty::{should_call_clone_as_function, walk_ptrs_ty_depth};
44
use clippy_utils::{
5-
get_parent_expr, is_diag_trait_item, match_def_path, path_to_local_id, paths, peel_blocks, strip_pat_refs,
5+
get_parent_expr, is_diag_trait_item, match_def_path, path_to_local_id, peel_blocks, strip_pat_refs,
66
};
77
use rustc_errors::Applicability;
8-
use rustc_hir as hir;
8+
use rustc_hir::{self as hir, LangItem};
99
use rustc_lint::LateContext;
1010
use rustc_middle::ty::adjustment::Adjust;
1111
use rustc_middle::ty::{Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor};
@@ -104,7 +104,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, call_name: &str,
104104
fn check_qpath(cx: &LateContext<'_>, qpath: hir::QPath<'_>, hir_id: hir::HirId) -> bool {
105105
// We check it's calling the `clone` method of the `Clone` trait.
106106
if let Some(path_def_id) = cx.qpath_res(&qpath, hir_id).opt_def_id() {
107-
match_def_path(cx, path_def_id, &paths::CLONE_TRAIT_METHOD)
107+
cx.tcx.lang_items().get(LangItem::CloneFn) == Some(path_def_id)
108108
} else {
109109
false
110110
}

clippy_lints/src/precedence.rs

+1-55
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,17 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::source::snippet_with_applicability;
3-
use rustc_ast::ast::{BinOpKind, Expr, ExprKind, MethodCall, UnOp};
4-
use rustc_ast::token;
3+
use rustc_ast::ast::{BinOpKind, Expr, ExprKind};
54
use rustc_errors::Applicability;
65
use rustc_lint::{EarlyContext, EarlyLintPass};
76
use rustc_session::declare_lint_pass;
87
use rustc_span::source_map::Spanned;
98

10-
const ALLOWED_ODD_FUNCTIONS: [&str; 14] = [
11-
"asin",
12-
"asinh",
13-
"atan",
14-
"atanh",
15-
"cbrt",
16-
"fract",
17-
"round",
18-
"signum",
19-
"sin",
20-
"sinh",
21-
"tan",
22-
"tanh",
23-
"to_degrees",
24-
"to_radians",
25-
];
26-
279
declare_clippy_lint! {
2810
/// ### What it does
2911
/// Checks for operations where precedence may be unclear
3012
/// and suggests to add parentheses. Currently it catches the following:
3113
/// * mixed usage of arithmetic and bit shifting/combining operators without
3214
/// parentheses
33-
/// * a "negative" numeric literal (which is really a unary `-` followed by a
34-
/// numeric literal)
35-
/// followed by a method call
3615
///
3716
/// ### Why is this bad?
3817
/// Not everyone knows the precedence of those operators by
@@ -41,7 +20,6 @@ declare_clippy_lint! {
4120
///
4221
/// ### Example
4322
/// * `1 << 2 + 3` equals 32, while `(1 << 2) + 3` equals 7
44-
/// * `-1i32.abs()` equals -1, while `(-1i32).abs()` equals 1
4523
#[clippy::version = "pre 1.29.0"]
4624
pub PRECEDENCE,
4725
complexity,
@@ -104,38 +82,6 @@ impl EarlyLintPass for Precedence {
10482
(false, false) => (),
10583
}
10684
}
107-
108-
if let ExprKind::Unary(UnOp::Neg, operand) = &expr.kind {
109-
let mut arg = operand;
110-
111-
let mut all_odd = true;
112-
while let ExprKind::MethodCall(box MethodCall { seg, receiver, .. }) = &arg.kind {
113-
let seg_str = seg.ident.name.as_str();
114-
all_odd &= ALLOWED_ODD_FUNCTIONS
115-
.iter()
116-
.any(|odd_function| **odd_function == *seg_str);
117-
arg = receiver;
118-
}
119-
120-
if !all_odd
121-
&& let ExprKind::Lit(lit) = &arg.kind
122-
&& let token::LitKind::Integer | token::LitKind::Float = &lit.kind
123-
{
124-
let mut applicability = Applicability::MachineApplicable;
125-
span_lint_and_sugg(
126-
cx,
127-
PRECEDENCE,
128-
expr.span,
129-
"unary minus has lower precedence than method call",
130-
"consider adding parentheses to clarify your intent",
131-
format!(
132-
"-({})",
133-
snippet_with_applicability(cx, operand.span, "..", &mut applicability)
134-
),
135-
applicability,
136-
);
137-
}
138-
}
13985
}
14086
}
14187

clippy_lints/src/redundant_clone.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClone {
9696
let (fn_def_id, arg, arg_ty, clone_ret) =
9797
unwrap_or_continue!(is_call_with_ref_arg(cx, mir, &terminator.kind));
9898

99-
let from_borrow = match_def_path(cx, fn_def_id, &paths::CLONE_TRAIT_METHOD)
99+
let from_borrow = cx.tcx.lang_items().get(LangItem::CloneFn) == Some(fn_def_id)
100100
|| cx.tcx.is_diagnostic_item(sym::to_owned_method, fn_def_id)
101101
|| (cx.tcx.is_diagnostic_item(sym::to_string_method, fn_def_id)
102102
&& is_type_lang_item(cx, arg_ty, LangItem::String));

clippy_lints/src/trait_bounds.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds {
183183

184184
// Iterate the bounds and add them to our seen hash
185185
// If we haven't yet seen it, add it to the fixed traits
186-
for bound in bounds {
186+
for (bound, _) in bounds {
187187
let Some(def_id) = bound.trait_ref.trait_def_id() else {
188188
continue;
189189
};
@@ -198,9 +198,9 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds {
198198
// If the number of unique traits isn't the same as the number of traits in the bounds,
199199
// there must be 1 or more duplicates
200200
if bounds.len() != unique_traits.len() {
201-
let mut bounds_span = bounds[0].span;
201+
let mut bounds_span = bounds[0].0.span;
202202

203-
for bound in bounds.iter().skip(1) {
203+
for (bound, _) in bounds.iter().skip(1) {
204204
bounds_span = bounds_span.to(bound.span);
205205
}
206206

clippy_lints/src/types/borrowed_box.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,15 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, lt: &Lifetime, m
8181

8282
// Returns true if given type is `Any` trait.
8383
fn is_any_trait(cx: &LateContext<'_>, t: &hir::Ty<'_>) -> bool {
84-
if let TyKind::TraitObject(traits, ..) = t.kind
85-
&& !traits.is_empty()
86-
&& let Some(trait_did) = traits[0].trait_ref.trait_def_id()
87-
// Only Send/Sync can be used as additional traits, so it is enough to
88-
// check only the first trait.
89-
&& cx.tcx.is_diagnostic_item(sym::Any, trait_did)
90-
{
91-
return true;
84+
if let TyKind::TraitObject(traits, ..) = t.kind {
85+
return traits.iter().any(|(bound, _)| {
86+
if let Some(trait_did) = bound.trait_ref.trait_def_id()
87+
&& cx.tcx.is_diagnostic_item(sym::Any, trait_did)
88+
{
89+
return true;
90+
}
91+
false
92+
});
9293
}
9394

9495
false

clippy_lints/src/types/type_complexity.rs

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ impl<'tcx> Visitor<'tcx> for TypeComplexityVisitor {
5555
TyKind::TraitObject(param_bounds, _, _) => {
5656
let has_lifetime_parameters = param_bounds.iter().any(|bound| {
5757
bound
58+
.0
5859
.bound_generic_params
5960
.iter()
6061
.any(|param| matches!(param.kind, GenericParamKind::Lifetime { .. }))

clippy_lints/src/unnecessary_wraps.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps {
145145
(
146146
"this function's return value is unnecessary".to_string(),
147147
"remove the return type...".to_string(),
148-
snippet(cx, fn_decl.output.span(), "..").to_string(),
148+
// FIXME: we should instead get the span including the `->` and suggest an
149+
// empty string for this case.
150+
"()".to_string(),
149151
"...and then remove returned values",
150152
)
151153
} else {

clippy_utils/src/paths.rs

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ pub const BINARYHEAP_ITER: [&str; 5] = ["alloc", "collections", "binary_heap", "
1616
pub const BTREEMAP_CONTAINS_KEY: [&str; 6] = ["alloc", "collections", "btree", "map", "BTreeMap", "contains_key"];
1717
pub const BTREEMAP_INSERT: [&str; 6] = ["alloc", "collections", "btree", "map", "BTreeMap", "insert"];
1818
pub const BTREESET_ITER: [&str; 6] = ["alloc", "collections", "btree", "set", "BTreeSet", "iter"];
19-
pub const CLONE_TRAIT_METHOD: [&str; 4] = ["core", "clone", "Clone", "clone"];
2019
pub const CORE_ITER_CLONED: [&str; 6] = ["core", "iter", "traits", "iterator", "Iterator", "cloned"];
2120
pub const CORE_ITER_COPIED: [&str; 6] = ["core", "iter", "traits", "iterator", "Iterator", "copied"];
2221
pub const CORE_ITER_FILTER: [&str; 6] = ["core", "iter", "traits", "iterator", "Iterator", "filter"];

rust-toolchain

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

tests/compile-test.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(is_sorted)]
21
#![warn(rust_2018_idioms, unused_lifetimes)]
32
#![allow(unused_extern_crates)]
43

tests/ui/from_str_radix_10.fixed

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(const_int_from_str)]
21
#![warn(clippy::from_str_radix_10)]
32

43
mod some_mod {
@@ -61,7 +60,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
6160
Ok(())
6261
}
6362

64-
fn issue_12732() {
63+
// https://github.com/rust-lang/rust-clippy/issues/12731
64+
fn issue_12731() {
6565
const A: Result<u32, std::num::ParseIntError> = u32::from_str_radix("123", 10);
6666
const B: () = {
6767
let _ = u32::from_str_radix("123", 10);

tests/ui/from_str_radix_10.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(const_int_from_str)]
21
#![warn(clippy::from_str_radix_10)]
32

43
mod some_mod {
@@ -61,7 +60,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
6160
Ok(())
6261
}
6362

64-
fn issue_12732() {
63+
// https://github.com/rust-lang/rust-clippy/issues/12731
64+
fn issue_12731() {
6565
const A: Result<u32, std::num::ParseIntError> = u32::from_str_radix("123", 10);
6666
const B: () = {
6767
let _ = u32::from_str_radix("123", 10);

tests/ui/from_str_radix_10.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: this call to `from_str_radix` can be replaced with a call to `str::parse`
2-
--> tests/ui/from_str_radix_10.rs:29:5
2+
--> tests/ui/from_str_radix_10.rs:28:5
33
|
44
LL | u32::from_str_radix("30", 10)?;
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"30".parse::<u32>()`
@@ -8,43 +8,43 @@ LL | u32::from_str_radix("30", 10)?;
88
= help: to override `-D warnings` add `#[allow(clippy::from_str_radix_10)]`
99

1010
error: this call to `from_str_radix` can be replaced with a call to `str::parse`
11-
--> tests/ui/from_str_radix_10.rs:32:5
11+
--> tests/ui/from_str_radix_10.rs:31:5
1212
|
1313
LL | i64::from_str_radix("24", 10)?;
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"24".parse::<i64>()`
1515

1616
error: this call to `from_str_radix` can be replaced with a call to `str::parse`
17-
--> tests/ui/from_str_radix_10.rs:34:5
17+
--> tests/ui/from_str_radix_10.rs:33:5
1818
|
1919
LL | isize::from_str_radix("100", 10)?;
2020
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"100".parse::<isize>()`
2121

2222
error: this call to `from_str_radix` can be replaced with a call to `str::parse`
23-
--> tests/ui/from_str_radix_10.rs:36:5
23+
--> tests/ui/from_str_radix_10.rs:35:5
2424
|
2525
LL | u8::from_str_radix("7", 10)?;
2626
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"7".parse::<u8>()`
2727

2828
error: this call to `from_str_radix` can be replaced with a call to `str::parse`
29-
--> tests/ui/from_str_radix_10.rs:38:5
29+
--> tests/ui/from_str_radix_10.rs:37:5
3030
|
3131
LL | u16::from_str_radix(&("10".to_owned() + "5"), 10)?;
3232
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `("10".to_owned() + "5").parse::<u16>()`
3333

3434
error: this call to `from_str_radix` can be replaced with a call to `str::parse`
35-
--> tests/ui/from_str_radix_10.rs:40:5
35+
--> tests/ui/from_str_radix_10.rs:39:5
3636
|
3737
LL | i128::from_str_radix(Test + Test, 10)?;
3838
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(Test + Test).parse::<i128>()`
3939

4040
error: this call to `from_str_radix` can be replaced with a call to `str::parse`
41-
--> tests/ui/from_str_radix_10.rs:44:5
41+
--> tests/ui/from_str_radix_10.rs:43:5
4242
|
4343
LL | i32::from_str_radix(string, 10)?;
4444
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `string.parse::<i32>()`
4545

4646
error: this call to `from_str_radix` can be replaced with a call to `str::parse`
47-
--> tests/ui/from_str_radix_10.rs:48:5
47+
--> tests/ui/from_str_radix_10.rs:47:5
4848
|
4949
LL | i32::from_str_radix(&stringier, 10)?;
5050
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `stringier.parse::<i32>()`

tests/ui/precedence.fixed

-34
Original file line numberDiff line numberDiff line change
@@ -20,40 +20,6 @@ fn main() {
2020
1 ^ (1 - 1);
2121
3 | (2 - 1);
2222
3 & (5 - 2);
23-
-(1i32.abs());
24-
-(1f32.abs());
25-
26-
// These should not trigger an error
27-
let _ = (-1i32).abs();
28-
let _ = (-1f32).abs();
29-
let _ = -(1i32).abs();
30-
let _ = -(1f32).abs();
31-
let _ = -(1i32.abs());
32-
let _ = -(1f32.abs());
33-
34-
// Odd functions should not trigger an error
35-
let _ = -1f64.asin();
36-
let _ = -1f64.asinh();
37-
let _ = -1f64.atan();
38-
let _ = -1f64.atanh();
39-
let _ = -1f64.cbrt();
40-
let _ = -1f64.fract();
41-
let _ = -1f64.round();
42-
let _ = -1f64.signum();
43-
let _ = -1f64.sin();
44-
let _ = -1f64.sinh();
45-
let _ = -1f64.tan();
46-
let _ = -1f64.tanh();
47-
let _ = -1f64.to_degrees();
48-
let _ = -1f64.to_radians();
49-
50-
// Chains containing any non-odd function should trigger (issue #5924)
51-
let _ = -(1.0_f64.cos().cos());
52-
let _ = -(1.0_f64.cos().sin());
53-
let _ = -(1.0_f64.sin().cos());
54-
55-
// Chains of odd functions shouldn't trigger
56-
let _ = -1f64.sin().sin();
5723

5824
let b = 3;
5925
trip!(b * 8);

0 commit comments

Comments
 (0)