Skip to content

Commit 371120b

Browse files
committed
Auto merge of #10749 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
2 parents d7173e2 + 79656cc commit 371120b

28 files changed

+109
-227
lines changed

Diff for: CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Current stable, released 2023-04-20
6262

6363
* [`explicit_auto_deref`]: Now considers projections when determining if auto deref is applicable
6464
[#10386](https://github.com/rust-lang/rust-clippy/pull/10386)
65-
* [`manual_let_else`]: Now considers side effects of branches before linting
65+
* [`manual_let_else`]: Now considers side effects of branches before linting
6666
[#10336](https://github.com/rust-lang/rust-clippy/pull/10336)
6767
* [`uninlined_format_args`]: No longer lints for arguments with generic parameters
6868
[#10343](https://github.com/rust-lang/rust-clippy/pull/10343)

Diff for: clippy_lints/src/declared_lints.rs

-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
315315
crate::methods::CHARS_NEXT_CMP_INFO,
316316
crate::methods::CLEAR_WITH_DRAIN_INFO,
317317
crate::methods::CLONED_INSTEAD_OF_COPIED_INFO,
318-
crate::methods::CLONE_DOUBLE_REF_INFO,
319318
crate::methods::CLONE_ON_COPY_INFO,
320319
crate::methods::CLONE_ON_REF_PTR_INFO,
321320
crate::methods::COLLAPSIBLE_STR_REPLACE_INFO,

Diff for: clippy_lints/src/default_union_representation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl<'tcx> LateLintPass<'tcx> for DefaultUnionRepresentation {
6161
None,
6262
&format!(
6363
"consider annotating `{}` with `#[repr(C)]` to explicitly specify memory layout",
64-
cx.tcx.def_path_str(item.owner_id.to_def_id())
64+
cx.tcx.def_path_str(item.owner_id)
6565
),
6666
);
6767
}

Diff for: clippy_lints/src/derive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) ->
517517
tcx.mk_predicates_from_iter(ty_predicates.iter().map(|&(p, _)| p).chain(
518518
params.iter().filter(|&&(_, needs_eq)| needs_eq).map(|&(param, _)| {
519519
tcx.mk_predicate(Binder::dummy(PredicateKind::Clause(Clause::Trait(TraitPredicate {
520-
trait_ref: tcx.mk_trait_ref(eq_trait_id, [tcx.mk_param_from_def(param)]),
520+
trait_ref: ty::TraitRef::new(tcx, eq_trait_id, [tcx.mk_param_from_def(param)]),
521521
constness: BoundConstness::NotConst,
522522
polarity: ImplPolarity::Positive,
523523
}))))

Diff for: clippy_lints/src/escape.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,8 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
9292
if trait_item.id.owner_id.def_id == fn_def_id {
9393
// be sure we have `self` parameter in this function
9494
if trait_item.kind == (AssocItemKind::Fn { has_self: true }) {
95-
trait_self_ty = Some(
96-
TraitRef::identity(cx.tcx, trait_item.id.owner_id.to_def_id())
97-
.self_ty()
98-
.skip_binder(),
99-
);
95+
trait_self_ty =
96+
Some(TraitRef::identity(cx.tcx, trait_item.id.owner_id.to_def_id()).self_ty());
10097
}
10198
}
10299
}

Diff for: clippy_lints/src/formatting.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_span::source_map::Span;
1010

1111
declare_clippy_lint! {
1212
/// ### What it does
13-
/// Checks for usage of the nonexistent `=*`, `=!` and `=-`
13+
/// Checks for usage of the non-existent `=*`, `=!` and `=-`
1414
/// operators.
1515
///
1616
/// ### Why is this bad?

Diff for: clippy_lints/src/future_not_send.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_hir::intravisit::FnKind;
44
use rustc_hir::{Body, FnDecl};
55
use rustc_infer::infer::TyCtxtInferExt;
66
use rustc_lint::{LateContext, LateLintPass};
7-
use rustc_middle::ty::{self, AliasTy, Clause, EarlyBinder, PredicateKind};
7+
use rustc_middle::ty::{self, AliasTy, Clause, PredicateKind};
88
use rustc_session::{declare_lint_pass, declare_tool_lint};
99
use rustc_span::def_id::LocalDefId;
1010
use rustc_span::{sym, Span};
@@ -66,8 +66,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
6666
if let ty::Alias(ty::Opaque, AliasTy { def_id, substs, .. }) = *ret_ty.kind() {
6767
let preds = cx.tcx.explicit_item_bounds(def_id);
6868
let mut is_future = false;
69-
for &(p, _span) in preds {
70-
let p = EarlyBinder(p).subst(cx.tcx, substs);
69+
for (p, _span) in preds.subst_iter_copied(cx.tcx, substs) {
7170
if let Some(trait_pred) = p.to_opt_poly_trait_pred() {
7271
if Some(trait_pred.skip_binder().trait_ref.def_id) == cx.tcx.lang_items().future_trait() {
7372
is_future = true;
@@ -97,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
9796
if let PredicateKind::Clause(Clause::Trait(trait_pred)) =
9897
obligation.predicate.kind().skip_binder()
9998
{
100-
db.note(&format!(
99+
db.note(format!(
101100
"`{}` doesn't implement `{}`",
102101
trait_pred.self_ty(),
103102
trait_pred.trait_ref.print_only_trait_path(),

Diff for: clippy_lints/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ pub fn register_pre_expansion_lints(store: &mut rustc_lint::LintStore, sess: &Se
354354
pub fn read_conf(sess: &Session, path: &io::Result<(Option<PathBuf>, Vec<String>)>) -> Conf {
355355
if let Ok((_, warnings)) = path {
356356
for warning in warnings {
357-
sess.warn(warning);
357+
sess.warn(warning.clone());
358358
}
359359
}
360360
let file_name = match path {

Diff for: clippy_lints/src/methods/clone_on_copy.rs

+2-38
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
1+
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::get_parent_node;
33
use clippy_utils::source::snippet_with_context;
4-
use clippy_utils::sugg;
54
use clippy_utils::ty::is_copy;
65
use rustc_errors::Applicability;
76
use rustc_hir::{BindingAnnotation, ByRef, Expr, ExprKind, MatchSource, Node, PatKind, QPath};
87
use rustc_lint::LateContext;
98
use rustc_middle::ty::{self, adjustment::Adjust, print::with_forced_trimmed_paths};
109
use rustc_span::symbol::{sym, Symbol};
1110

12-
use super::CLONE_DOUBLE_REF;
1311
use super::CLONE_ON_COPY;
1412

1513
/// Checks for the `CLONE_ON_COPY` lint.
@@ -42,41 +40,7 @@ pub(super) fn check(
4240

4341
let ty = cx.typeck_results().expr_ty(expr);
4442
if let ty::Ref(_, inner, _) = arg_ty.kind() {
45-
if let ty::Ref(_, innermost, _) = inner.kind() {
46-
span_lint_and_then(
47-
cx,
48-
CLONE_DOUBLE_REF,
49-
expr.span,
50-
&with_forced_trimmed_paths!(format!(
51-
"using `clone` on a double-reference; \
52-
this will copy the reference of type `{ty}` instead of cloning the inner type"
53-
)),
54-
|diag| {
55-
if let Some(snip) = sugg::Sugg::hir_opt(cx, arg) {
56-
let mut ty = innermost;
57-
let mut n = 0;
58-
while let ty::Ref(_, inner, _) = ty.kind() {
59-
ty = inner;
60-
n += 1;
61-
}
62-
let refs = "&".repeat(n + 1);
63-
let derefs = "*".repeat(n);
64-
let explicit = with_forced_trimmed_paths!(format!("<{refs}{ty}>::clone({snip})"));
65-
diag.span_suggestion(
66-
expr.span,
67-
"try dereferencing it",
68-
with_forced_trimmed_paths!(format!("{refs}({derefs}{}).clone()", snip.deref())),
69-
Applicability::MaybeIncorrect,
70-
);
71-
diag.span_suggestion(
72-
expr.span,
73-
"or try being explicit if you are sure, that you want to clone a reference",
74-
explicit,
75-
Applicability::MaybeIncorrect,
76-
);
77-
}
78-
},
79-
);
43+
if let ty::Ref(..) = inner.kind() {
8044
return; // don't report clone_on_copy
8145
}
8246
}

Diff for: clippy_lints/src/methods/mod.rs

+2-28
Original file line numberDiff line numberDiff line change
@@ -984,29 +984,6 @@ declare_clippy_lint! {
984984
"using 'clone' on a ref-counted pointer"
985985
}
986986

987-
declare_clippy_lint! {
988-
/// ### What it does
989-
/// Checks for usage of `.clone()` on an `&&T`.
990-
///
991-
/// ### Why is this bad?
992-
/// Cloning an `&&T` copies the inner `&T`, instead of
993-
/// cloning the underlying `T`.
994-
///
995-
/// ### Example
996-
/// ```rust
997-
/// fn main() {
998-
/// let x = vec![1];
999-
/// let y = &&x;
1000-
/// let z = y.clone();
1001-
/// println!("{:p} {:p}", *y, z); // prints out the same pointer
1002-
/// }
1003-
/// ```
1004-
#[clippy::version = "pre 1.29.0"]
1005-
pub CLONE_DOUBLE_REF,
1006-
correctness,
1007-
"using `clone` on `&&T`"
1008-
}
1009-
1010987
declare_clippy_lint! {
1011988
/// ### What it does
1012989
/// Checks for usage of `.to_string()` on an `&&T` where
@@ -3258,7 +3235,6 @@ impl_lint_pass!(Methods => [
32583235
CHARS_LAST_CMP,
32593236
CLONE_ON_COPY,
32603237
CLONE_ON_REF_PTR,
3261-
CLONE_DOUBLE_REF,
32623238
COLLAPSIBLE_STR_REPLACE,
32633239
ITER_OVEREAGER_CLONED,
32643240
CLONED_INSTEAD_OF_COPIED,
@@ -3500,8 +3476,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
35003476
let first_arg_span = first_arg_ty.span;
35013477
let first_arg_ty = hir_ty_to_ty(cx.tcx, first_arg_ty);
35023478
let self_ty = TraitRef::identity(cx.tcx, item.owner_id.to_def_id())
3503-
.self_ty()
3504-
.skip_binder();
3479+
.self_ty();
35053480
wrong_self_convention::check(
35063481
cx,
35073482
item.ident.name.as_str(),
@@ -3519,8 +3494,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
35193494
if let TraitItemKind::Fn(_, _) = item.kind;
35203495
let ret_ty = return_ty(cx, item.owner_id);
35213496
let self_ty = TraitRef::identity(cx.tcx, item.owner_id.to_def_id())
3522-
.self_ty()
3523-
.skip_binder();
3497+
.self_ty();
35243498
if !ret_ty.contains(self_ty);
35253499

35263500
then {

Diff for: clippy_lints/src/methods/str_splitn.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,13 @@ fn check_manual_split_once_indirect(
175175
let remove_msg = format!("remove the `{iter_ident}` usages");
176176
diag.span_suggestion(
177177
first.span,
178-
&remove_msg,
178+
remove_msg.clone(),
179179
"",
180180
app,
181181
);
182182
diag.span_suggestion(
183183
second.span,
184-
&remove_msg,
184+
remove_msg,
185185
"",
186186
app,
187187
);

Diff for: clippy_lints/src/non_send_fields_in_send_ty.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,13 @@ impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy {
131131
for field in non_send_fields {
132132
diag.span_note(
133133
field.def.span,
134-
&format!("it is not safe to send field `{}` to another thread", field.def.ident.name),
134+
format!("it is not safe to send field `{}` to another thread", field.def.ident.name),
135135
);
136136

137137
match field.generic_params.len() {
138138
0 => diag.help("use a thread-safe type that implements `Send`"),
139-
1 if is_ty_param(field.ty) => diag.help(&format!("add `{}: Send` bound in `Send` impl", field.ty)),
140-
_ => diag.help(&format!(
139+
1 if is_ty_param(field.ty) => diag.help(format!("add `{}: Send` bound in `Send` impl", field.ty)),
140+
_ => diag.help(format!(
141141
"add bounds on type parameter{} `{}` that satisfy `{}: Send`",
142142
if field.generic_params.len() > 1 { "s" } else { "" },
143143
field.generic_params_string(),

Diff for: clippy_lints/src/renamed_lints.rs

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[
3030
("clippy::stutter", "clippy::module_name_repetitions"),
3131
("clippy::to_string_in_display", "clippy::recursive_format_impl"),
3232
("clippy::zero_width_space", "clippy::invisible_characters"),
33+
("clippy::clone_double_ref", "suspicious_double_ref_op"),
3334
("clippy::drop_bounds", "drop_bounds"),
3435
("clippy::for_loop_over_option", "for_loops_over_fallibles"),
3536
("clippy::for_loop_over_result", "for_loops_over_fallibles"),

Diff for: clippy_lints/src/suspicious_operation_groupings.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ fn ident_difference_expr_with_base_location(
577577
| (AssignOp(_, _, _), AssignOp(_, _, _))
578578
| (Assign(_, _, _), Assign(_, _, _))
579579
| (TryBlock(_), TryBlock(_))
580-
| (Await(_), Await(_))
580+
| (Await(_, _), Await(_, _))
581581
| (Async(_, _), Async(_, _))
582582
| (Block(_, _), Block(_, _))
583583
| (Closure(_), Closure(_))

Diff for: clippy_lints/src/trailing_empty_array.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl<'tcx> LateLintPass<'tcx> for TrailingEmptyArray {
4646
None,
4747
&format!(
4848
"consider annotating `{}` with `#[repr(C)]` or another `repr` attribute",
49-
cx.tcx.def_path_str(item.owner_id.to_def_id())
49+
cx.tcx.def_path_str(item.owner_id)
5050
),
5151
);
5252
}

Diff for: clippy_utils/src/ast_utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool {
143143
(Paren(l), _) => eq_expr(l, r),
144144
(_, Paren(r)) => eq_expr(l, r),
145145
(Err, Err) => true,
146-
(Try(l), Try(r)) | (Await(l), Await(r)) => eq_expr(l, r),
146+
(Try(l), Try(r)) | (Await(l, _), Await(r, _)) => eq_expr(l, r),
147147
(Array(l), Array(r)) => over(l, r, |l, r| eq_expr(l, r)),
148148
(Tup(l), Tup(r)) => over(l, r, |l, r| eq_expr(l, r)),
149149
(Repeat(le, ls), Repeat(re, rs)) => eq_expr(le, re) && eq_expr(&ls.value, &rs.value),

Diff for: clippy_utils/src/attrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pub fn get_unique_attr<'a>(
133133
let mut unique_attr: Option<&ast::Attribute> = None;
134134
for attr in get_attr(sess, attrs, name) {
135135
if let Some(duplicate) = unique_attr {
136-
sess.struct_span_err(attr.span, &format!("`{name}` is defined multiple times"))
136+
sess.struct_span_err(attr.span, format!("`{name}` is defined multiple times"))
137137
.span_note(duplicate.span, "first definition found here")
138138
.emit();
139139
} else {

Diff for: clippy_utils/src/sugg.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,9 @@ impl<'a> Sugg<'a> {
162162
get_snippet(lhs.span),
163163
get_snippet(rhs.span),
164164
),
165-
hir::ExprKind::Cast(lhs, ty) => Sugg::BinOp(AssocOp::As, get_snippet(lhs.span), get_snippet(ty.span)),
166-
hir::ExprKind::Type(lhs, ty) => Sugg::BinOp(AssocOp::Colon, get_snippet(lhs.span), get_snippet(ty.span)),
165+
hir::ExprKind::Cast(lhs, ty) |
166+
//FIXME(chenyukang), remove this after type ascription is removed from AST
167+
hir::ExprKind::Type(lhs, ty) => Sugg::BinOp(AssocOp::As, get_snippet(lhs.span), get_snippet(ty.span)),
167168
}
168169
}
169170

@@ -253,13 +254,10 @@ impl<'a> Sugg<'a> {
253254
snippet_with_context(cx, lhs.span, ctxt, default, app).0,
254255
snippet_with_context(cx, rhs.span, ctxt, default, app).0,
255256
),
256-
ast::ExprKind::Cast(ref lhs, ref ty) => Sugg::BinOp(
257-
AssocOp::As,
258-
snippet_with_context(cx, lhs.span, ctxt, default, app).0,
259-
snippet_with_context(cx, ty.span, ctxt, default, app).0,
260-
),
257+
ast::ExprKind::Cast(ref lhs, ref ty) |
258+
//FIXME(chenyukang), remove this after type ascription is removed from AST
261259
ast::ExprKind::Type(ref lhs, ref ty) => Sugg::BinOp(
262-
AssocOp::Colon,
260+
AssocOp::As,
263261
snippet_with_context(cx, lhs.span, ctxt, default, app).0,
264262
snippet_with_context(cx, ty.span, ctxt, default, app).0,
265263
),
@@ -392,7 +390,6 @@ fn binop_to_string(op: AssocOp, lhs: &str, rhs: &str) -> String {
392390
AssocOp::As => format!("{lhs} as {rhs}"),
393391
AssocOp::DotDot => format!("{lhs}..{rhs}"),
394392
AssocOp::DotDotEq => format!("{lhs}..={rhs}"),
395-
AssocOp::Colon => format!("{lhs}: {rhs}"),
396393
}
397394
}
398395

@@ -602,13 +599,13 @@ enum Associativity {
602599
#[must_use]
603600
fn associativity(op: AssocOp) -> Associativity {
604601
use rustc_ast::util::parser::AssocOp::{
605-
Add, As, Assign, AssignOp, BitAnd, BitOr, BitXor, Colon, Divide, DotDot, DotDotEq, Equal, Greater,
606-
GreaterEqual, LAnd, LOr, Less, LessEqual, Modulus, Multiply, NotEqual, ShiftLeft, ShiftRight, Subtract,
602+
Add, As, Assign, AssignOp, BitAnd, BitOr, BitXor, Divide, DotDot, DotDotEq, Equal, Greater, GreaterEqual, LAnd,
603+
LOr, Less, LessEqual, Modulus, Multiply, NotEqual, ShiftLeft, ShiftRight, Subtract,
607604
};
608605

609606
match op {
610607
Assign | AssignOp(_) => Associativity::Right,
611-
Add | BitAnd | BitOr | BitXor | LAnd | LOr | Multiply | As | Colon => Associativity::Both,
608+
Add | BitAnd | BitOr | BitXor | LAnd | LOr | Multiply | As => Associativity::Both,
612609
Divide | Equal | Greater | GreaterEqual | Less | LessEqual | Modulus | NotEqual | ShiftLeft | ShiftRight
613610
| Subtract => Associativity::Left,
614611
DotDot | DotDotEq => Associativity::None,

Diff for: clippy_utils/src/ty.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'
9090
return false;
9191
}
9292

93-
for &(predicate, _span) in cx.tcx.explicit_item_bounds(def_id) {
93+
for (predicate, _span) in cx.tcx.explicit_item_bounds(def_id).subst_identity_iter_copied() {
9494
match predicate.kind().skip_binder() {
9595
// For `impl Trait<U>`, it will register a predicate of `T: Trait<U>`, so we go through
9696
// and check substitutions to find `U`.
@@ -226,7 +226,7 @@ pub fn implements_trait_with_env<'tcx>(
226226
ty_params: impl IntoIterator<Item = Option<GenericArg<'tcx>>>,
227227
) -> bool {
228228
// Clippy shouldn't have infer types
229-
assert!(!ty.needs_infer());
229+
assert!(!ty.has_infer());
230230

231231
let ty = tcx.erase_regions(ty);
232232
if ty.has_escaping_bound_vars() {
@@ -267,7 +267,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
267267
},
268268
ty::Tuple(substs) => substs.iter().any(|ty| is_must_use_ty(cx, ty)),
269269
ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => {
270-
for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) {
270+
for (predicate, _) in cx.tcx.explicit_item_bounds(def_id).skip_binder() {
271271
if let ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) = predicate.kind().skip_binder() {
272272
if cx.tcx.has_attr(trait_predicate.trait_ref.def_id, sym::must_use) {
273273
return true;
@@ -743,7 +743,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: AliasTy<'tcx>) -> Option
743743

744744
for (pred, _) in cx
745745
.tcx
746-
.bound_explicit_item_bounds(ty.def_id)
746+
.explicit_item_bounds(ty.def_id)
747747
.subst_iter_copied(cx.tcx, ty.substs)
748748
{
749749
match pred.kind().skip_binder() {
@@ -837,7 +837,7 @@ pub fn is_c_void(cx: &LateContext<'_>, ty: Ty<'_>) -> bool {
837837
if let ty::Adt(adt, _) = ty.kind()
838838
&& let &[krate, .., name] = &*cx.get_def_path(adt.did())
839839
&& let sym::libc | sym::core | sym::std = krate
840-
&& name.as_str() == "c_void"
840+
&& name == rustc_span::sym::c_void
841841
{
842842
true
843843
} else {

Diff for: rust-toolchain

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2023-04-23"
2+
channel = "nightly-2023-05-05"
33
components = ["cargo", "llvm-tools", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt"]

0 commit comments

Comments
 (0)