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

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

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

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

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

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

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

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

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

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

Lines changed: 3 additions & 1 deletion
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 {

0 commit comments

Comments
 (0)