Skip to content

Commit 2c40b99

Browse files
committed
Auto merge of #11048 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
2 parents 73f1417 + 30d08d3 commit 2c40b99

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+242
-593
lines changed

clippy_lints/src/casts/cast_possible_wrap.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_from: Ty<'_>, ca
2424
// 1. unsigned to signed
2525
// and
2626
// 2. either:
27+
//
2728
// 2a. between two types of constant size that are always the same size
2829
// 2b. between one target-dependent size and one constant size integer,
2930
// and the constant integer is in the allowed set of target dependent sizes

clippy_lints/src/declared_lints.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
141141
crate::drop_forget_ref::DROP_NON_DROP_INFO,
142142
crate::drop_forget_ref::FORGET_NON_DROP_INFO,
143143
crate::drop_forget_ref::MEM_FORGET_INFO,
144-
crate::drop_forget_ref::UNDROPPED_MANUALLY_DROPS_INFO,
145144
crate::duplicate_mod::DUPLICATE_MOD_INFO,
146145
crate::else_if_without_else::ELSE_IF_WITHOUT_ELSE_INFO,
147146
crate::empty_drop::EMPTY_DROP_INFO,
@@ -493,7 +492,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
493492
crate::operators::ARITHMETIC_SIDE_EFFECTS_INFO,
494493
crate::operators::ASSIGN_OP_PATTERN_INFO,
495494
crate::operators::BAD_BIT_MASK_INFO,
496-
crate::operators::CMP_NAN_INFO,
497495
crate::operators::CMP_OWNED_INFO,
498496
crate::operators::DOUBLE_COMPARISONS_INFO,
499497
crate::operators::DURATION_SUBSEC_INFO,

clippy_lints/src/dereference.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ use rustc_lint::{LateContext, LateLintPass};
2626
use rustc_middle::mir::{Rvalue, StatementKind};
2727
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability};
2828
use rustc_middle::ty::{
29-
self, Binder, BoundVariableKind, Clause, EarlyBinder, FnSig, GenericArgKind, List, ParamEnv, ParamTy,
30-
PredicateKind, ProjectionPredicate, Ty, TyCtxt, TypeVisitableExt, TypeckResults,
29+
self, Binder, BoundVariableKind, ClauseKind, EarlyBinder, FnSig, GenericArgKind, List, ParamEnv, ParamTy,
30+
ProjectionPredicate, Ty, TyCtxt, TypeVisitableExt, TypeckResults,
3131
};
3232
use rustc_session::{declare_tool_lint, impl_lint_pass};
3333
use rustc_span::{symbol::sym, Span, Symbol};
@@ -357,15 +357,17 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
357357
// start auto-deref.
358358
// 4. If the chain of non-user-defined derefs ends with a mutable re-borrow, and re-borrow
359359
// adjustments will not be inserted automatically, then leave one further reference to avoid
360-
// moving a mutable borrow.
361-
// e.g.
362-
// fn foo<T>(x: &mut Option<&mut T>, y: &mut T) {
363-
// let x = match x {
364-
// // Removing the borrow will cause `x` to be moved
365-
// Some(x) => &mut *x,
366-
// None => y
367-
// };
368-
// }
360+
// moving a mutable borrow. e.g.
361+
//
362+
// ```rust
363+
// fn foo<T>(x: &mut Option<&mut T>, y: &mut T) {
364+
// let x = match x {
365+
// // Removing the borrow will cause `x` to be moved
366+
// Some(x) => &mut *x,
367+
// None => y
368+
// };
369+
// }
370+
// ```
369371
let deref_msg =
370372
"this expression creates a reference which is immediately dereferenced by the compiler";
371373
let borrow_msg = "this expression borrows a value the compiler would automatically borrow";
@@ -1135,7 +1137,7 @@ fn needless_borrow_impl_arg_position<'tcx>(
11351137
let projection_predicates = predicates
11361138
.iter()
11371139
.filter_map(|predicate| {
1138-
if let PredicateKind::Clause(Clause::Projection(projection_predicate)) = predicate.kind().skip_binder() {
1140+
if let ClauseKind::Projection(projection_predicate) = predicate.kind().skip_binder() {
11391141
Some(projection_predicate)
11401142
} else {
11411143
None
@@ -1149,7 +1151,7 @@ fn needless_borrow_impl_arg_position<'tcx>(
11491151
if predicates
11501152
.iter()
11511153
.filter_map(|predicate| {
1152-
if let PredicateKind::Clause(Clause::Trait(trait_predicate)) = predicate.kind().skip_binder()
1154+
if let ClauseKind::Trait(trait_predicate) = predicate.kind().skip_binder()
11531155
&& trait_predicate.trait_ref.self_ty() == param_ty.to_ty(cx.tcx)
11541156
{
11551157
Some(trait_predicate.trait_ref.def_id)
@@ -1211,7 +1213,7 @@ fn needless_borrow_impl_arg_position<'tcx>(
12111213
}
12121214

12131215
predicates.iter().all(|predicate| {
1214-
if let PredicateKind::Clause(Clause::Trait(trait_predicate)) = predicate.kind().skip_binder()
1216+
if let ClauseKind::Trait(trait_predicate) = predicate.kind().skip_binder()
12151217
&& cx.tcx.is_diagnostic_item(sym::IntoIterator, trait_predicate.trait_ref.def_id)
12161218
&& let ty::Param(param_ty) = trait_predicate.self_ty().kind()
12171219
&& let GenericArgKind::Type(ty) = substs_with_referent_ty[param_ty.index as usize].unpack()
@@ -1426,6 +1428,7 @@ fn ty_auto_deref_stability<'tcx>(
14261428
continue;
14271429
},
14281430
ty::Param(_) => TyPosition::new_deref_stable_for_result(precedence, ty),
1431+
ty::Alias(ty::Weak, _) => unreachable!("should have been normalized away above"),
14291432
ty::Alias(ty::Inherent, _) => unreachable!("inherent projection should have been normalized away above"),
14301433
ty::Alias(ty::Projection, _) if ty.has_non_region_param() => {
14311434
TyPosition::new_deref_stable_for_result(precedence, ty)

clippy_lints/src/derive.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_lint::{LateContext, LateLintPass};
1414
use rustc_middle::hir::nested_filter;
1515
use rustc_middle::traits::Reveal;
1616
use rustc_middle::ty::{
17-
self, Binder, BoundConstness, Clause, GenericArgKind, GenericParamDefKind, ImplPolarity, ParamEnv, PredicateKind,
17+
self, BoundConstness, ClauseKind, GenericArgKind, GenericParamDefKind, ImplPolarity, ParamEnv, ToPredicate,
1818
TraitPredicate, Ty, TyCtxt,
1919
};
2020
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -503,7 +503,7 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) ->
503503

504504
let ty_predicates = tcx.predicates_of(did).predicates;
505505
for (p, _) in ty_predicates {
506-
if let PredicateKind::Clause(Clause::Trait(p)) = p.kind().skip_binder()
506+
if let ClauseKind::Trait(p) = p.kind().skip_binder()
507507
&& p.trait_ref.def_id == eq_trait_id
508508
&& let ty::Param(self_ty) = p.trait_ref.self_ty().kind()
509509
&& p.constness == BoundConstness::NotConst
@@ -514,13 +514,14 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) ->
514514
}
515515

516516
ParamEnv::new(
517-
tcx.mk_predicates_from_iter(ty_predicates.iter().map(|&(p, _)| p).chain(
517+
tcx.mk_clauses_from_iter(ty_predicates.iter().map(|&(p, _)| p).chain(
518518
params.iter().filter(|&&(_, needs_eq)| needs_eq).map(|&(param, _)| {
519-
tcx.mk_predicate(Binder::dummy(PredicateKind::Clause(Clause::Trait(TraitPredicate {
519+
ClauseKind::Trait(TraitPredicate {
520520
trait_ref: ty::TraitRef::new(tcx, eq_trait_id, [tcx.mk_param_from_def(param)]),
521521
constness: BoundConstness::NotConst,
522522
polarity: ImplPolarity::Positive,
523-
}))))
523+
})
524+
.to_predicate(tcx)
524525
}),
525526
)),
526527
Reveal::UserFacing,

clippy_lints/src/drop_forget_ref.rs

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_note};
1+
use clippy_utils::diagnostics::span_lint_and_note;
22
use clippy_utils::get_parent_node;
33
use clippy_utils::is_must_use_func_call;
44
use clippy_utils::ty::{is_copy, is_must_use_ty, is_type_lang_item};
@@ -48,35 +48,6 @@ declare_clippy_lint! {
4848
"call to `std::mem::forget` with a value which does not implement `Drop`"
4949
}
5050

51-
declare_clippy_lint! {
52-
/// ### What it does
53-
/// Prevents the safe `std::mem::drop` function from being called on `std::mem::ManuallyDrop`.
54-
///
55-
/// ### Why is this bad?
56-
/// The safe `drop` function does not drop the inner value of a `ManuallyDrop`.
57-
///
58-
/// ### Known problems
59-
/// Does not catch cases if the user binds `std::mem::drop`
60-
/// to a different name and calls it that way.
61-
///
62-
/// ### Example
63-
/// ```rust
64-
/// struct S;
65-
/// drop(std::mem::ManuallyDrop::new(S));
66-
/// ```
67-
/// Use instead:
68-
/// ```rust
69-
/// struct S;
70-
/// unsafe {
71-
/// std::mem::ManuallyDrop::drop(&mut std::mem::ManuallyDrop::new(S));
72-
/// }
73-
/// ```
74-
#[clippy::version = "1.49.0"]
75-
pub UNDROPPED_MANUALLY_DROPS,
76-
correctness,
77-
"use of safe `std::mem::drop` function to drop a std::mem::ManuallyDrop, which will not drop the inner value"
78-
}
79-
8051
declare_clippy_lint! {
8152
/// ### What it does
8253
/// Checks for usage of `std::mem::forget(t)` where `t` is
@@ -106,7 +77,6 @@ const FORGET_NON_DROP_SUMMARY: &str = "call to `std::mem::forget` with a value t
10677
declare_lint_pass!(DropForgetRef => [
10778
DROP_NON_DROP,
10879
FORGET_NON_DROP,
109-
UNDROPPED_MANUALLY_DROPS,
11080
MEM_FORGET,
11181
]);
11282

@@ -126,17 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef {
12696
sym::mem_forget if arg_ty.is_ref() => return,
12797
sym::mem_drop if is_copy && !drop_is_single_call_in_arm => return,
12898
sym::mem_forget if is_copy => return,
129-
sym::mem_drop if is_type_lang_item(cx, arg_ty, LangItem::ManuallyDrop) => {
130-
span_lint_and_help(
131-
cx,
132-
UNDROPPED_MANUALLY_DROPS,
133-
expr.span,
134-
"the inner value of this ManuallyDrop will not be dropped",
135-
None,
136-
"to drop a `ManuallyDrop<T>`, use std::mem::ManuallyDrop::drop",
137-
);
138-
return;
139-
}
99+
sym::mem_drop if is_type_lang_item(cx, arg_ty, LangItem::ManuallyDrop) => return,
140100
sym::mem_drop
141101
if !(arg_ty.needs_drop(cx.tcx, cx.param_env)
142102
|| is_must_use_func_call(cx, arg)

clippy_lints/src/future_not_send.rs

Lines changed: 3 additions & 3 deletions
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, PredicateKind};
7+
use rustc_middle::ty::{self, AliasTy, ClauseKind, PredicateKind};
88
use rustc_session::{declare_lint_pass, declare_tool_lint};
99
use rustc_span::def_id::LocalDefId;
1010
use rustc_span::{sym, Span};
@@ -67,7 +67,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
6767
let preds = cx.tcx.explicit_item_bounds(def_id);
6868
let mut is_future = false;
6969
for (p, _span) in preds.subst_iter_copied(cx.tcx, substs) {
70-
if let Some(trait_pred) = p.to_opt_poly_trait_pred() {
70+
if let Some(trait_pred) = p.as_trait_clause() {
7171
if Some(trait_pred.skip_binder().trait_ref.def_id) == cx.tcx.lang_items().future_trait() {
7272
is_future = true;
7373
break;
@@ -93,7 +93,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
9393
infcx
9494
.err_ctxt()
9595
.maybe_note_obligation_cause_for_async_await(db, &obligation);
96-
if let PredicateKind::Clause(Clause::Trait(trait_pred)) =
96+
if let PredicateKind::Clause(ClauseKind::Trait(trait_pred)) =
9797
obligation.predicate.kind().skip_binder()
9898
{
9999
db.note(format!(

clippy_lints/src/loops/never_loop.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ fn never_loop_expr<'tcx>(
223223
NeverLoopResult::AlwaysBreak,
224224
)
225225
}),
226+
ExprKind::Become(e) => combine_seq(
227+
never_loop_expr(cx, e, ignore_ids, main_loop_id),
228+
NeverLoopResult::AlwaysBreak,
229+
),
226230
ExprKind::InlineAsm(asm) => asm
227231
.operands
228232
.iter()

clippy_lints/src/matches/significant_drop_in_scrutinee.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ impl<'a, 'tcx> Visitor<'tcx> for SigDropHelper<'a, 'tcx> {
329329
ExprKind::Field(..) |
330330
ExprKind::Index(..) |
331331
ExprKind::Ret(..) |
332+
ExprKind::Become(..) |
332333
ExprKind::Repeat(..) |
333334
ExprKind::Yield(..) => walk_expr(self, ex),
334335
ExprKind::AddrOf(_, _, _) |

clippy_lints/src/methods/needless_collect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_hir::{
1616
};
1717
use rustc_lint::LateContext;
1818
use rustc_middle::hir::nested_filter;
19-
use rustc_middle::ty::{self, AssocKind, Clause, EarlyBinder, GenericArg, GenericArgKind, PredicateKind, Ty};
19+
use rustc_middle::ty::{self, AssocKind, ClauseKind, EarlyBinder, GenericArg, GenericArgKind, Ty};
2020
use rustc_span::symbol::Ident;
2121
use rustc_span::{sym, Span, Symbol};
2222

@@ -175,7 +175,7 @@ fn check_collect_into_intoiterator<'tcx>(
175175
.caller_bounds()
176176
.into_iter()
177177
.filter_map(|p| {
178-
if let PredicateKind::Clause(Clause::Trait(t)) = p.kind().skip_binder()
178+
if let ClauseKind::Trait(t) = p.kind().skip_binder()
179179
&& cx.tcx.is_diagnostic_item(sym::IntoIterator,t.trait_ref.def_id) {
180180
Some(t.self_ty())
181181
} else {

clippy_lints/src/methods/unnecessary_to_owned.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_lint::LateContext;
1414
use rustc_middle::mir::Mutability;
1515
use rustc_middle::ty::adjustment::{Adjust, Adjustment, OverloadedDeref};
1616
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, SubstsRef};
17-
use rustc_middle::ty::{self, Clause, EarlyBinder, ParamTy, PredicateKind, ProjectionPredicate, TraitPredicate, Ty};
17+
use rustc_middle::ty::{self, ClauseKind, EarlyBinder, ParamTy, ProjectionPredicate, TraitPredicate, Ty};
1818
use rustc_span::{sym, Symbol};
1919
use rustc_trait_selection::traits::{query::evaluate_obligation::InferCtxtExt as _, Obligation, ObligationCause};
2020

@@ -350,12 +350,12 @@ fn get_input_traits_and_projections<'tcx>(
350350
let mut projection_predicates = Vec::new();
351351
for predicate in cx.tcx.param_env(callee_def_id).caller_bounds() {
352352
match predicate.kind().skip_binder() {
353-
PredicateKind::Clause(Clause::Trait(trait_predicate)) => {
353+
ClauseKind::Trait(trait_predicate) => {
354354
if trait_predicate.trait_ref.self_ty() == input {
355355
trait_predicates.push(trait_predicate);
356356
}
357357
},
358-
PredicateKind::Clause(Clause::Projection(projection_predicate)) => {
358+
ClauseKind::Projection(projection_predicate) => {
359359
if projection_predicate.projection_ty.self_ty() == input {
360360
projection_predicates.push(projection_predicate);
361361
}
@@ -412,7 +412,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
412412

413413
let mut trait_predicates = cx.tcx.param_env(callee_def_id)
414414
.caller_bounds().iter().filter(|predicate| {
415-
if let PredicateKind::Clause(Clause::Trait(trait_predicate))
415+
if let ClauseKind::Trait(trait_predicate)
416416
= predicate.kind().skip_binder()
417417
&& trait_predicate.trait_ref.self_ty() == *param_ty
418418
{

clippy_lints/src/missing_inline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
105105
match tit_.kind {
106106
hir::TraitItemKind::Const(..) | hir::TraitItemKind::Type(..) => {},
107107
hir::TraitItemKind::Fn(..) => {
108-
if cx.tcx.impl_defaultness(tit.id.owner_id).has_value() {
108+
if cx.tcx.defaultness(tit.id.owner_id).has_value() {
109109
// trait method with default body needs inline in case
110110
// an impl is not provided
111111
let desc = "a default trait method";

clippy_lints/src/needless_pass_by_value.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
125125
.filter_map(|pred| {
126126
// Note that we do not want to deal with qualified predicates here.
127127
match pred.kind().no_bound_vars() {
128-
Some(ty::PredicateKind::Clause(ty::Clause::Trait(pred))) if pred.def_id() != sized_trait => {
129-
Some(pred)
130-
},
128+
Some(ty::ClauseKind::Trait(pred)) if pred.def_id() != sized_trait => Some(pred),
131129
_ => None,
132130
}
133131
})

clippy_lints/src/non_copy_const.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,15 @@ fn is_value_unfrozen_raw<'tcx>(
166166
// have a value that is a frozen variant with a generic param (an example is
167167
// `declare_interior_mutable_const::enums::BothOfCellAndGeneric::GENERIC_VARIANT`).
168168
// However, it prevents a number of false negatives that is, I think, important:
169-
// 1. assoc consts in trait defs referring to consts of themselves
170-
// (an example is `declare_interior_mutable_const::traits::ConcreteTypes::ANOTHER_ATOMIC`).
171-
// 2. a path expr referring to assoc consts whose type is doesn't have
172-
// any frozen variants in trait defs (i.e. without substitute for `Self`).
173-
// (e.g. borrowing `borrow_interior_mutable_const::trait::ConcreteTypes::ATOMIC`)
174-
// 3. similar to the false positive above;
175-
// but the value is an unfrozen variant, or the type has no enums. (An example is
176-
// `declare_interior_mutable_const::enums::BothOfCellAndGeneric::UNFROZEN_VARIANT`
177-
// and `declare_interior_mutable_const::enums::BothOfCellAndGeneric::NO_ENUM`).
169+
// 1. assoc consts in trait defs referring to consts of themselves (an example is
170+
// `declare_interior_mutable_const::traits::ConcreteTypes::ANOTHER_ATOMIC`).
171+
// 2. a path expr referring to assoc consts whose type is doesn't have any frozen variants in trait
172+
// defs (i.e. without substitute for `Self`). (e.g. borrowing
173+
// `borrow_interior_mutable_const::trait::ConcreteTypes::ATOMIC`)
174+
// 3. similar to the false positive above; but the value is an unfrozen variant, or the type has no
175+
// enums. (An example is
176+
// `declare_interior_mutable_const::enums::BothOfCellAndGeneric::UNFROZEN_VARIANT` and
177+
// `declare_interior_mutable_const::enums::BothOfCellAndGeneric::NO_ENUM`).
178178
// One might be able to prevent these FNs correctly, and replace this with `false`;
179179
// e.g. implementing `has_frozen_variant` described above, and not running this function
180180
// when the type doesn't have any frozen variants would be the 'correct' way for the 2nd

clippy_lints/src/operators/cmp_nan.rs

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)