Skip to content

Commit 680256f

Browse files
committed
Auto merge of #12813 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: None
2 parents 5459429 + 9f6280b commit 680256f

Some content is hidden

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

56 files changed

+306
-387
lines changed

clippy_lints/src/default_union_representation.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_help;
22
use rustc_hir::{HirId, Item, ItemKind};
33
use rustc_lint::{LateContext, LateLintPass};
44
use rustc_middle::ty::layout::LayoutOf;
5-
use rustc_middle::ty::{self, FieldDef, GenericArg, List};
5+
use rustc_middle::ty::{self, FieldDef};
66
use rustc_session::declare_lint_pass;
77
use rustc_span::sym;
88

@@ -85,7 +85,7 @@ fn is_union_with_two_non_zst_fields<'tcx>(cx: &LateContext<'tcx>, item: &Item<'t
8585
}
8686
}
8787

88-
fn is_zst<'tcx>(cx: &LateContext<'tcx>, field: &FieldDef, args: &'tcx List<GenericArg<'tcx>>) -> bool {
88+
fn is_zst<'tcx>(cx: &LateContext<'tcx>, field: &FieldDef, args: ty::GenericArgsRef<'tcx>) -> bool {
8989
let ty = field.ty(cx.tcx, args);
9090
if let Ok(layout) = cx.layout_of(ty) {
9191
layout.is_zst()

clippy_lints/src/dereference.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
382382
cx,
383383
impl_ty,
384384
trait_id,
385-
&args[..cx.tcx.generics_of(trait_id).params.len() - 1],
385+
&args[..cx.tcx.generics_of(trait_id).own_params.len() - 1],
386386
)
387387
{
388388
false

clippy_lints/src/derive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) ->
480480
// Vec<(param_def, needs_eq)>
481481
let mut params = tcx
482482
.generics_of(did)
483-
.params
483+
.own_params
484484
.iter()
485485
.map(|p| (p, matches!(p.kind, GenericParamDefKind::Type { .. })))
486486
.collect::<Vec<_>>();

clippy_lints/src/escape.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_hir;
22
use rustc_hir::{intravisit, AssocItemKind, Body, FnDecl, HirId, HirIdSet, Impl, ItemKind, Node, Pat, PatKind};
33
use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
4-
use rustc_infer::infer::TyCtxtInferExt;
54
use rustc_lint::{LateContext, LateLintPass};
65
use rustc_middle::mir::FakeReadCause;
76
use rustc_middle::ty::layout::LayoutOf;
@@ -105,8 +104,9 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
105104
too_large_for_stack: self.too_large_for_stack,
106105
};
107106

108-
let infcx = cx.tcx.infer_ctxt().build();
109-
ExprUseVisitor::new(&mut v, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body);
107+
ExprUseVisitor::for_clippy(cx, fn_def_id, &mut v)
108+
.consume_body(body)
109+
.into_ok();
110110

111111
for node in v.set {
112112
span_lint_hir(

clippy_lints/src/future_not_send.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +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::print::PrintTraitRefExt;
78
use rustc_middle::ty::{self, AliasTy, ClauseKind, PredicateKind};
89
use rustc_session::declare_lint_pass;
910
use rustc_span::def_id::LocalDefId;

clippy_lints/src/implied_bounds_in_impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ fn try_resolve_type<'tcx>(
148148
match args.get(index - 1) {
149149
Some(GenericArg::Type(ty)) => Some(lower_ty(tcx, ty)),
150150
Some(_) => None,
151-
None => Some(tcx.type_of(generics.params[index].def_id).skip_binder()),
151+
None => Some(tcx.type_of(generics.own_params[index].def_id).skip_binder()),
152152
}
153153
}
154154

clippy_lints/src/iter_without_into_iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ impl {self_ty_without_ref} {{
225225
&& let ImplItemKind::Fn(sig, _) = item.kind
226226
&& let FnRetTy::Return(ret) = sig.decl.output
227227
&& is_nameable_in_impl_trait(ret)
228-
&& cx.tcx.generics_of(item_did).params.is_empty()
228+
&& cx.tcx.generics_of(item_did).own_params.is_empty()
229229
&& sig.decl.implicit_self == expected_implicit_self
230230
&& sig.decl.inputs.len() == 1
231231
&& let Some(imp) = get_parent_as_impl(cx.tcx, item.hir_id())

clippy_lints/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#![feature(never_type)]
99
#![feature(rustc_private)]
1010
#![feature(stmt_expr_attributes)]
11+
#![feature(unwrap_infallible)]
1112
#![recursion_limit = "512"]
1213
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
1314
#![allow(

clippy_lints/src/loops/mut_range_bound.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use clippy_utils::{get_enclosing_block, higher, path_to_local};
44
use rustc_hir::intravisit::{self, Visitor};
55
use rustc_hir::{BindingMode, Expr, ExprKind, HirId, Node, PatKind};
66
use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
7-
use rustc_infer::infer::TyCtxtInferExt;
87
use rustc_lint::LateContext;
98
use rustc_middle::mir::FakeReadCause;
109
use rustc_middle::ty;
@@ -61,15 +60,9 @@ fn check_for_mutation(
6160
span_low: None,
6261
span_high: None,
6362
};
64-
let infcx = cx.tcx.infer_ctxt().build();
65-
ExprUseVisitor::new(
66-
&mut delegate,
67-
&infcx,
68-
body.hir_id.owner.def_id,
69-
cx.param_env,
70-
cx.typeck_results(),
71-
)
72-
.walk_expr(body);
63+
ExprUseVisitor::for_clippy(cx, body.hir_id.owner.def_id, &mut delegate)
64+
.walk_expr(body)
65+
.into_ok();
7366

7467
delegate.mutation_span()
7568
}

clippy_lints/src/manual_assert.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
use crate::rustc_lint::LintContext;
21
use clippy_utils::diagnostics::span_lint_and_then;
32
use clippy_utils::macros::{is_panic, root_macro_call};
43
use clippy_utils::{is_else_clause, is_parent_stmt, peel_blocks_with_stmt, span_extract_comment, sugg};
54
use rustc_errors::Applicability;
65
use rustc_hir::{Expr, ExprKind, UnOp};
7-
use rustc_lint::{LateContext, LateLintPass};
6+
use rustc_lint::{LateContext, LateLintPass, LintContext};
87
use rustc_session::declare_lint_pass;
98

109
declare_clippy_lint! {

clippy_lints/src/matches/significant_drop_in_scrutinee.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_errors::{Applicability, Diag};
66
use rustc_hir::intravisit::{walk_expr, Visitor};
77
use rustc_hir::{Arm, Expr, ExprKind, MatchSource};
88
use rustc_lint::{LateContext, LintContext};
9-
use rustc_middle::ty::{GenericArgKind, Ty, TypeAndMut};
9+
use rustc_middle::ty::{GenericArgKind, Ty};
1010
use rustc_span::Span;
1111

1212
use super::SIGNIFICANT_DROP_IN_SCRUTINEE;
@@ -249,9 +249,9 @@ impl<'a, 'tcx> SigDropHelper<'a, 'tcx> {
249249
}
250250
let ty = self.cx.typeck_results().expr_ty(expr);
251251
if ty.is_ref() {
252-
// We checked that the type was ref, so builtin_deref will return Some TypeAndMut,
253-
// but let's avoid any chance of an ICE
254-
if let Some(TypeAndMut { ty, .. }) = ty.builtin_deref(true) {
252+
// We checked that the type was ref, so builtin_deref will return Some,
253+
// but let's avoid any chance of an ICE.
254+
if let Some(ty) = ty.builtin_deref(true) {
255255
if ty.is_trivially_pure_clone_copy() {
256256
self.replace_current_sig_drop(expr.span, false, LintSuggestion::MoveAndDerefToCopy);
257257
} else if allow_move_and_clone {

clippy_lints/src/methods/iter_overeager_cloned.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use rustc_span::sym;
1212

1313
use super::ITER_OVEREAGER_CLONED;
1414
use crate::redundant_clone::REDUNDANT_CLONE;
15-
use crate::rustc_trait_selection::infer::TyCtxtInferExt;
1615

1716
#[derive(Clone, Copy)]
1817
pub(super) enum Op<'a> {
@@ -69,16 +68,10 @@ pub(super) fn check<'tcx>(
6968
let mut delegate = MoveDelegate {
7069
used_move: HirIdSet::default(),
7170
};
72-
let infcx = cx.tcx.infer_ctxt().build();
73-
74-
ExprUseVisitor::new(
75-
&mut delegate,
76-
&infcx,
77-
closure.body.hir_id.owner.def_id,
78-
cx.param_env,
79-
cx.typeck_results(),
80-
)
81-
.consume_body(body);
71+
72+
ExprUseVisitor::for_clippy(cx, closure.def_id, &mut delegate)
73+
.consume_body(body)
74+
.into_ok();
8275

8376
let mut to_be_discarded = false;
8477

clippy_lints/src/methods/unnecessary_to_owned.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ fn get_input_traits_and_projections<'tcx>(
417417
}
418418
},
419419
ClauseKind::Projection(projection_predicate) => {
420-
if projection_predicate.projection_ty.self_ty() == input {
420+
if projection_predicate.projection_term.self_ty() == input {
421421
projection_predicates.push(projection_predicate);
422422
}
423423
},

clippy_lints/src/mismatching_type_param_order.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl<'tcx> LateLintPass<'tcx> for TypeParamMismatch {
7676
};
7777

7878
// get the names of the generic parameters in the type
79-
let type_params = &cx.tcx.generics_of(defid).params;
79+
let type_params = &cx.tcx.generics_of(defid).own_params;
8080
let type_param_names: Vec<_> = type_params
8181
.iter()
8282
.filter_map(|p| match p.kind {

clippy_lints/src/needless_borrows_for_generic_args.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_index::bit_set::BitSet;
1212
use rustc_infer::infer::TyCtxtInferExt;
1313
use rustc_lint::{LateContext, LateLintPass};
1414
use rustc_middle::ty::{
15-
self, ClauseKind, EarlyBinder, FnSig, GenericArg, GenericArgKind, List, ParamTy, ProjectionPredicate, Ty,
15+
self, ClauseKind, EarlyBinder, FnSig, GenericArg, GenericArgKind, ParamTy, ProjectionPredicate, Ty,
1616
};
1717
use rustc_session::impl_lint_pass;
1818
use rustc_span::symbol::sym;
@@ -157,7 +157,7 @@ fn path_has_args(p: &QPath<'_>) -> bool {
157157
fn needless_borrow_count<'tcx>(
158158
cx: &LateContext<'tcx>,
159159
fn_id: DefId,
160-
callee_args: &'tcx List<GenericArg<'tcx>>,
160+
callee_args: ty::GenericArgsRef<'tcx>,
161161
arg_index: usize,
162162
param_ty: ParamTy,
163163
mut expr: &Expr<'tcx>,
@@ -316,11 +316,11 @@ fn is_mixed_projection_predicate<'tcx>(
316316
&& (term_param_ty.index as usize) < generics.parent_count
317317
{
318318
// The inner-most self type is a type parameter from the current function.
319-
let mut projection_ty = projection_predicate.projection_ty;
319+
let mut projection_term = projection_predicate.projection_term;
320320
loop {
321-
match projection_ty.self_ty().kind() {
321+
match *projection_term.self_ty().kind() {
322322
ty::Alias(ty::Projection, inner_projection_ty) => {
323-
projection_ty = *inner_projection_ty;
323+
projection_term = inner_projection_ty.into();
324324
},
325325
ty::Param(param_ty) => {
326326
return (param_ty.index as usize) >= generics.parent_count;
@@ -369,14 +369,15 @@ fn replace_types<'tcx>(
369369
// The `replaced.insert(...)` check provides some protection against infinite loops.
370370
if replaced.insert(param_ty.index) {
371371
for projection_predicate in projection_predicates {
372-
if projection_predicate.projection_ty.self_ty() == param_ty.to_ty(cx.tcx)
372+
if projection_predicate.projection_term.self_ty() == param_ty.to_ty(cx.tcx)
373373
&& let Some(term_ty) = projection_predicate.term.ty()
374374
&& let ty::Param(term_param_ty) = term_ty.kind()
375375
{
376-
let projection = cx.tcx.mk_ty_from_kind(ty::Alias(
377-
ty::Projection,
378-
projection_predicate.projection_ty.with_self_ty(cx.tcx, new_ty),
379-
));
376+
let projection = projection_predicate
377+
.projection_term
378+
.with_self_ty(cx.tcx, new_ty)
379+
.expect_ty(cx.tcx)
380+
.to_ty(cx.tcx);
380381

381382
if let Ok(projected_ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, projection)
382383
&& args[term_param_ty.index as usize] != GenericArg::from(projected_ty)

clippy_lints/src/needless_pass_by_ref_mut.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use rustc_hir::{
1111
PatKind,
1212
};
1313
use rustc_hir_typeck::expr_use_visitor as euv;
14-
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
1514
use rustc_lint::{LateContext, LateLintPass};
1615
use rustc_middle::mir::FakeReadCause;
1716
use rustc_middle::ty::{self, Ty, TyCtxt, UpvarId, UpvarPath};
@@ -102,7 +101,6 @@ fn should_skip<'tcx>(
102101
fn check_closures<'tcx>(
103102
ctx: &mut MutablyUsedVariablesCtxt<'tcx>,
104103
cx: &LateContext<'tcx>,
105-
infcx: &InferCtxt<'tcx>,
106104
checked_closures: &mut FxHashSet<LocalDefId>,
107105
closures: FxHashSet<LocalDefId>,
108106
) {
@@ -119,7 +117,9 @@ fn check_closures<'tcx>(
119117
.associated_body()
120118
.map(|(_, body_id)| hir.body(body_id))
121119
{
122-
euv::ExprUseVisitor::new(ctx, infcx, closure, cx.param_env, cx.typeck_results()).consume_body(body);
120+
euv::ExprUseVisitor::for_clippy(cx, closure, &mut *ctx)
121+
.consume_body(body)
122+
.into_ok();
123123
}
124124
}
125125
}
@@ -196,8 +196,9 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> {
196196
async_closures: FxHashSet::default(),
197197
tcx: cx.tcx,
198198
};
199-
let infcx = cx.tcx.infer_ctxt().build();
200-
euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body);
199+
euv::ExprUseVisitor::for_clippy(cx, fn_def_id, &mut ctx)
200+
.consume_body(body)
201+
.into_ok();
201202

202203
let mut checked_closures = FxHashSet::default();
203204

@@ -210,13 +211,13 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> {
210211
}
211212
ControlFlow::<()>::Continue(())
212213
});
213-
check_closures(&mut ctx, cx, &infcx, &mut checked_closures, closures);
214+
check_closures(&mut ctx, cx, &mut checked_closures, closures);
214215

215216
if is_async {
216217
while !ctx.async_closures.is_empty() {
217218
let async_closures = ctx.async_closures.clone();
218219
ctx.async_closures.clear();
219-
check_closures(&mut ctx, cx, &infcx, &mut checked_closures, async_closures);
220+
check_closures(&mut ctx, cx, &mut checked_closures, async_closures);
220221
}
221222
}
222223
ctx.generate_mutably_used_ids_from_aliases()

clippy_lints/src/needless_pass_by_value.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use rustc_hir::{
1313
TyKind,
1414
};
1515
use rustc_hir_typeck::expr_use_visitor as euv;
16-
use rustc_infer::infer::TyCtxtInferExt;
1716
use rustc_lint::{LateContext, LateLintPass};
1817
use rustc_middle::mir::FakeReadCause;
1918
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
@@ -134,8 +133,9 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
134133
// function body.
135134
let MovedVariablesCtxt { moved_vars } = {
136135
let mut ctx = MovedVariablesCtxt::default();
137-
let infcx = cx.tcx.infer_ctxt().build();
138-
euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body);
136+
euv::ExprUseVisitor::for_clippy(cx, fn_def_id, &mut ctx)
137+
.consume_body(body)
138+
.into_ok();
139139
ctx
140140
};
141141

clippy_lints/src/operators/assign_op_pattern.rs

+4-19
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, Pl
1111
use rustc_lint::LateContext;
1212
use rustc_middle::mir::FakeReadCause;
1313
use rustc_middle::ty::BorrowKind;
14-
use rustc_trait_selection::infer::TyCtxtInferExt;
1514

1615
use super::ASSIGN_OP_PATTERN;
1716

@@ -119,15 +118,8 @@ fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> HirIdSet {
119118
}
120119

121120
let mut s = S(HirIdSet::default());
122-
let infcx = cx.tcx.infer_ctxt().build();
123-
let mut v = ExprUseVisitor::new(
124-
&mut s,
125-
&infcx,
126-
cx.tcx.hir().body_owner_def_id(cx.enclosing_body.unwrap()),
127-
cx.param_env,
128-
cx.typeck_results(),
129-
);
130-
v.consume_expr(e);
121+
let v = ExprUseVisitor::for_clippy(cx, e.hir_id.owner.def_id, &mut s);
122+
v.consume_expr(e).into_ok();
131123
s.0
132124
}
133125

@@ -151,14 +143,7 @@ fn mut_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> HirIdSet {
151143
}
152144

153145
let mut s = S(HirIdSet::default());
154-
let infcx = cx.tcx.infer_ctxt().build();
155-
let mut v = ExprUseVisitor::new(
156-
&mut s,
157-
&infcx,
158-
cx.tcx.hir().body_owner_def_id(cx.enclosing_body.unwrap()),
159-
cx.param_env,
160-
cx.typeck_results(),
161-
);
162-
v.consume_expr(e);
146+
let v = ExprUseVisitor::for_clippy(cx, e.hir_id.owner.def_id, &mut s);
147+
v.consume_expr(e).into_ok();
163148
s.0
164149
}

clippy_lints/src/operators/cmp_owned.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ fn check_op(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left: bool)
7070
let without_deref = symmetric_partial_eq(cx, arg_ty, other_ty).unwrap_or_default();
7171
let with_deref = arg_ty
7272
.builtin_deref(true)
73-
.and_then(|tam| symmetric_partial_eq(cx, tam.ty, other_ty))
73+
.and_then(|ty| symmetric_partial_eq(cx, ty, other_ty))
7474
.unwrap_or_default();
7575

7676
if !with_deref.is_implemented() && !without_deref.is_implemented() {

clippy_lints/src/redundant_closure_call.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::rustc_lint::LintContext;
21
use clippy_utils::diagnostics::{span_lint_and_then, span_lint_hir};
32
use clippy_utils::get_parent_expr;
43
use clippy_utils::sugg::Sugg;
@@ -9,7 +8,7 @@ use rustc_hir::intravisit::{Visitor as HirVisitor, Visitor};
98
use rustc_hir::{
109
intravisit as hir_visit, ClosureKind, CoroutineDesugaring, CoroutineKind, CoroutineSource, ExprKind, Node,
1110
};
12-
use rustc_lint::{LateContext, LateLintPass};
11+
use rustc_lint::{LateContext, LateLintPass, LintContext};
1312
use rustc_middle::hir::nested_filter;
1413
use rustc_middle::lint::in_external_macro;
1514
use rustc_middle::ty;

0 commit comments

Comments
 (0)