Skip to content

Commit a01ad33

Browse files
committed
Auto merge of rust-lang#3602 - RalfJung:rustup, r=RalfJung
Rustup
2 parents 102ffff + 0987d92 commit a01ad33

15 files changed

+42
-80
lines changed

clippy_lints/src/escape.rs

Lines changed: 1 addition & 3 deletions
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,7 @@ 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).consume_body(body).into_ok();
110108

111109
for node in v.set {
112110
span_lint_hir(

clippy_lints/src/lib.rs

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

Lines changed: 4 additions & 8 deletions
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,12 @@ 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,
63+
ExprUseVisitor::for_clippy(
64+
cx,
6865
body.hir_id.owner.def_id,
69-
cx.param_env,
70-
cx.typeck_results(),
66+
&mut delegate,
7167
)
72-
.walk_expr(body);
68+
.walk_expr(body).into_ok();
7369

7470
delegate.mutation_span()
7571
}

clippy_lints/src/methods/iter_overeager_cloned.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use rustc_lint::LateContext;
99
use rustc_middle::mir::{FakeReadCause, Mutability};
1010
use rustc_middle::ty::{self, BorrowKind};
1111
use rustc_span::sym;
12-
use rustc_trait_selection::infer::TyCtxtInferExt;
1312

1413
use super::ITER_OVEREAGER_CLONED;
1514
use crate::redundant_clone::REDUNDANT_CLONE;
@@ -69,16 +68,13 @@ pub(super) fn check<'tcx>(
6968
let mut delegate = MoveDelegate {
7069
used_move: HirIdSet::default(),
7170
};
72-
let infcx = cx.tcx.infer_ctxt().build();
7371

74-
ExprUseVisitor::new(
72+
ExprUseVisitor::for_clippy(
73+
cx,
74+
closure.def_id,
7575
&mut delegate,
76-
&infcx,
77-
closure.body.hir_id.owner.def_id,
78-
cx.param_env,
79-
cx.typeck_results(),
8076
)
81-
.consume_body(body);
77+
.consume_body(body).into_ok();
8278

8379
let mut to_be_discarded = false;
8480

clippy_lints/src/methods/unnecessary_to_owned.rs

Lines changed: 1 addition & 1 deletion
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/needless_borrows_for_generic_args.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,11 @@ fn is_mixed_projection_predicate<'tcx>(
320320
&& (term_param_ty.index as usize) < generics.parent_count
321321
{
322322
// The inner-most self type is a type parameter from the current function.
323-
let mut projection_ty = projection_predicate.projection_ty;
323+
let mut projection_term = projection_predicate.projection_term;
324324
loop {
325-
match projection_ty.self_ty().kind() {
325+
match *projection_term.self_ty().kind() {
326326
ty::Alias(ty::Projection, inner_projection_ty) => {
327-
projection_ty = *inner_projection_ty;
327+
projection_term = inner_projection_ty.into();
328328
},
329329
ty::Param(param_ty) => {
330330
return (param_ty.index as usize) >= generics.parent_count;
@@ -404,14 +404,11 @@ fn replace_types<'tcx>(
404404
// The `replaced.insert(...)` check provides some protection against infinite loops.
405405
if replaced.insert(param_ty.index) {
406406
for projection_predicate in projection_predicates {
407-
if projection_predicate.projection_ty.self_ty() == param_ty.to_ty(cx.tcx)
407+
if projection_predicate.projection_term.self_ty() == param_ty.to_ty(cx.tcx)
408408
&& let Some(term_ty) = projection_predicate.term.ty()
409409
&& let ty::Param(term_param_ty) = term_ty.kind()
410410
{
411-
let projection = cx.tcx.mk_ty_from_kind(ty::Alias(
412-
ty::Projection,
413-
projection_predicate.projection_ty.with_self_ty(cx.tcx, new_ty),
414-
));
411+
let projection = projection_predicate.projection_term.with_self_ty(cx.tcx, new_ty).expect_ty(cx.tcx).to_ty(cx.tcx);
415412

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

clippy_lints/src/needless_pass_by_ref_mut.rs

Lines changed: 4 additions & 7 deletions
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,7 @@ 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).consume_body(body).into_ok();
123121
}
124122
}
125123
}
@@ -196,8 +194,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> {
196194
async_closures: FxHashSet::default(),
197195
tcx: cx.tcx,
198196
};
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);
197+
euv::ExprUseVisitor::for_clippy(cx, fn_def_id, &mut ctx).consume_body(body).into_ok();
201198

202199
let mut checked_closures = FxHashSet::default();
203200

@@ -210,13 +207,13 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> {
210207
}
211208
ControlFlow::<()>::Continue(())
212209
});
213-
check_closures(&mut ctx, cx, &infcx, &mut checked_closures, closures);
210+
check_closures(&mut ctx, cx, &mut checked_closures, closures);
214211

215212
if is_async {
216213
while !ctx.async_closures.is_empty() {
217214
let async_closures = ctx.async_closures.clone();
218215
ctx.async_closures.clear();
219-
check_closures(&mut ctx, cx, &infcx, &mut checked_closures, async_closures);
216+
check_closures(&mut ctx, cx, &mut checked_closures, async_closures);
220217
}
221218
}
222219
ctx.generate_mutably_used_ids_from_aliases()

clippy_lints/src/needless_pass_by_value.rs

Lines changed: 1 addition & 3 deletions
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,7 @@ 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).consume_body(body).into_ok();
139137
ctx
140138
};
141139

clippy_lints/src/operators/assign_op_pattern.rs

Lines changed: 4 additions & 19 deletions
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/unit_return_expecting_ord.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fn get_projection_pred<'tcx>(
6666
let projection_pred = cx
6767
.tcx
6868
.instantiate_bound_regions_with_erased(proj_pred.kind().rebind(pred));
69-
if projection_pred.projection_ty.args == trait_pred.trait_ref.args {
69+
if projection_pred.projection_term.args == trait_pred.trait_ref.args {
7070
return Some(projection_pred);
7171
}
7272
}

0 commit comments

Comments
 (0)