Skip to content

Commit a4e8726

Browse files
committed
Auto merge of #9680 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` I ran out of time and will have to do the Clippy->Rust sync tomorrow. changelog: none
2 parents 1afc7e2 + 4ff2364 commit a4e8726

Some content is hidden

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

47 files changed

+187
-512
lines changed

clippy_lints/src/dereference.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -856,11 +856,10 @@ fn walk_parents<'tcx>(
856856
// Trait methods taking `self`
857857
arg_ty
858858
} && impl_ty.is_ref()
859-
&& cx.tcx.infer_ctxt().enter(|infcx|
860-
infcx
861-
.type_implements_trait(trait_id, impl_ty, subs, cx.param_env)
862-
.must_apply_modulo_regions()
863-
)
859+
&& let infcx = cx.tcx.infer_ctxt().build()
860+
&& infcx
861+
.type_implements_trait(trait_id, impl_ty, subs, cx.param_env)
862+
.must_apply_modulo_regions()
864863
{
865864
return Some(Position::MethodReceiverRefImpl)
866865
}
@@ -1158,9 +1157,8 @@ fn needless_borrow_impl_arg_position<'tcx>(
11581157

11591158
let predicate = EarlyBinder(predicate).subst(cx.tcx, &substs_with_referent_ty);
11601159
let obligation = Obligation::new(ObligationCause::dummy(), cx.param_env, predicate);
1161-
cx.tcx
1162-
.infer_ctxt()
1163-
.enter(|infcx| infcx.predicate_must_hold_modulo_regions(&obligation))
1160+
let infcx = cx.tcx.infer_ctxt().build();
1161+
infcx.predicate_must_hold_modulo_regions(&obligation)
11641162
})
11651163
};
11661164

clippy_lints/src/escape.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,8 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
106106
};
107107

108108
let fn_def_id = cx.tcx.hir().local_def_id(hir_id);
109-
cx.tcx.infer_ctxt().enter(|infcx| {
110-
ExprUseVisitor::new(&mut v, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body);
111-
});
109+
let infcx = cx.tcx.infer_ctxt().build();
110+
ExprUseVisitor::new(&mut v, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body);
112111

113112
for node in v.set {
114113
span_lint_hir(

clippy_lints/src/future_not_send.rs

+15-16
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_lint::{LateContext, LateLintPass};
77
use rustc_middle::ty::{EarlyBinder, Opaque, PredicateKind::Trait};
88
use rustc_session::{declare_lint_pass, declare_tool_lint};
99
use rustc_span::{sym, Span};
10-
use rustc_trait_selection::traits::error_reporting::suggestions::InferCtxtExt;
10+
use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt;
1111
use rustc_trait_selection::traits::{self, FulfillmentError};
1212

1313
declare_clippy_lint! {
@@ -77,29 +77,28 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
7777
if is_future {
7878
let send_trait = cx.tcx.get_diagnostic_item(sym::Send).unwrap();
7979
let span = decl.output.span();
80-
let send_errors = cx.tcx.infer_ctxt().enter(|infcx| {
81-
let cause = traits::ObligationCause::misc(span, hir_id);
82-
traits::fully_solve_bound(&infcx, cause, cx.param_env, ret_ty, send_trait)
83-
});
80+
let infcx = cx.tcx.infer_ctxt().build();
81+
let cause = traits::ObligationCause::misc(span, hir_id);
82+
let send_errors = traits::fully_solve_bound(&infcx, cause, cx.param_env, ret_ty, send_trait);
8483
if !send_errors.is_empty() {
8584
span_lint_and_then(
8685
cx,
8786
FUTURE_NOT_SEND,
8887
span,
8988
"future cannot be sent between threads safely",
9089
|db| {
91-
cx.tcx.infer_ctxt().enter(|infcx| {
92-
for FulfillmentError { obligation, .. } in send_errors {
93-
infcx.maybe_note_obligation_cause_for_async_await(db, &obligation);
94-
if let Trait(trait_pred) = obligation.predicate.kind().skip_binder() {
95-
db.note(&format!(
96-
"`{}` doesn't implement `{}`",
97-
trait_pred.self_ty(),
98-
trait_pred.trait_ref.print_only_trait_path(),
99-
));
100-
}
90+
for FulfillmentError { obligation, .. } in send_errors {
91+
infcx
92+
.err_ctxt()
93+
.maybe_note_obligation_cause_for_async_await(db, &obligation);
94+
if let Trait(trait_pred) = obligation.predicate.kind().skip_binder() {
95+
db.note(&format!(
96+
"`{}` doesn't implement `{}`",
97+
trait_pred.self_ty(),
98+
trait_pred.trait_ref.print_only_trait_path(),
99+
));
101100
}
102-
});
101+
}
103102
},
104103
);
105104
}

clippy_lints/src/indexing_slicing.rs

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ declare_clippy_lint! {
1919
///
2020
/// ### Example
2121
/// ```rust,no_run
22-
/// # #![allow(const_err)]
2322
/// let x = [1, 2, 3, 4];
2423
///
2524
/// x[9];

clippy_lints/src/lib.register_all.rs

-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
113113
LintId::of(loops::EMPTY_LOOP),
114114
LintId::of(loops::EXPLICIT_COUNTER_LOOP),
115115
LintId::of(loops::FOR_KV_MAP),
116-
LintId::of(loops::FOR_LOOPS_OVER_FALLIBLES),
117116
LintId::of(loops::ITER_NEXT_LOOP),
118117
LintId::of(loops::MANUAL_FIND),
119118
LintId::of(loops::MANUAL_FLATTEN),

clippy_lints/src/lib.register_lints.rs

-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ store.register_lints(&[
230230
loops::EXPLICIT_INTO_ITER_LOOP,
231231
loops::EXPLICIT_ITER_LOOP,
232232
loops::FOR_KV_MAP,
233-
loops::FOR_LOOPS_OVER_FALLIBLES,
234233
loops::ITER_NEXT_LOOP,
235234
loops::MANUAL_FIND,
236235
loops::MANUAL_FLATTEN,

clippy_lints/src/lib.register_suspicious.rs

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ store.register_group(true, "clippy::suspicious", Some("clippy_suspicious"), vec!
2222
LintId::of(formatting::SUSPICIOUS_ELSE_FORMATTING),
2323
LintId::of(formatting::SUSPICIOUS_UNARY_OP_FORMATTING),
2424
LintId::of(loops::EMPTY_LOOP),
25-
LintId::of(loops::FOR_LOOPS_OVER_FALLIBLES),
2625
LintId::of(loops::MUT_RANGE_BOUND),
2726
LintId::of(methods::NO_EFFECT_REPLACE),
2827
LintId::of(methods::SUSPICIOUS_MAP),

clippy_lints/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ pub fn read_conf(sess: &Session) -> Conf {
482482
}
483483

484484
for warning in warnings {
485-
sess.struct_warn(&format!(
485+
sess.struct_warn(format!(
486486
"error reading Clippy's configuration file `{}`: {}",
487487
file_name.display(),
488488
format_error(warning)

clippy_lints/src/loops/for_loops_over_fallibles.rs

-65
This file was deleted.

clippy_lints/src/loops/iter_next_loop.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_hir::Expr;
55
use rustc_lint::LateContext;
66
use rustc_span::sym;
77

8-
pub(super) fn check(cx: &LateContext<'_>, arg: &Expr<'_>) -> bool {
8+
pub(super) fn check(cx: &LateContext<'_>, arg: &Expr<'_>) {
99
if is_trait_method(cx, arg, sym::Iterator) {
1010
span_lint(
1111
cx,
@@ -14,8 +14,5 @@ pub(super) fn check(cx: &LateContext<'_>, arg: &Expr<'_>) -> bool {
1414
"you are iterating over `Iterator::next()` which is an Option; this will compile but is \
1515
probably not what you want",
1616
);
17-
true
18-
} else {
19-
false
2017
}
2118
}

clippy_lints/src/loops/mod.rs

+2-55
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ mod explicit_counter_loop;
33
mod explicit_into_iter_loop;
44
mod explicit_iter_loop;
55
mod for_kv_map;
6-
mod for_loops_over_fallibles;
76
mod iter_next_loop;
87
mod manual_find;
98
mod manual_flatten;
@@ -173,49 +172,6 @@ declare_clippy_lint! {
173172
"for-looping over `_.next()` which is probably not intended"
174173
}
175174

176-
declare_clippy_lint! {
177-
/// ### What it does
178-
/// Checks for `for` loops over `Option` or `Result` values.
179-
///
180-
/// ### Why is this bad?
181-
/// Readability. This is more clearly expressed as an `if
182-
/// let`.
183-
///
184-
/// ### Example
185-
/// ```rust
186-
/// # let opt = Some(1);
187-
/// # let res: Result<i32, std::io::Error> = Ok(1);
188-
/// for x in opt {
189-
/// // ..
190-
/// }
191-
///
192-
/// for x in &res {
193-
/// // ..
194-
/// }
195-
///
196-
/// for x in res.iter() {
197-
/// // ..
198-
/// }
199-
/// ```
200-
///
201-
/// Use instead:
202-
/// ```rust
203-
/// # let opt = Some(1);
204-
/// # let res: Result<i32, std::io::Error> = Ok(1);
205-
/// if let Some(x) = opt {
206-
/// // ..
207-
/// }
208-
///
209-
/// if let Ok(x) = res {
210-
/// // ..
211-
/// }
212-
/// ```
213-
#[clippy::version = "1.45.0"]
214-
pub FOR_LOOPS_OVER_FALLIBLES,
215-
suspicious,
216-
"for-looping over an `Option` or a `Result`, which is more clearly expressed as an `if let`"
217-
}
218-
219175
declare_clippy_lint! {
220176
/// ### What it does
221177
/// Detects `loop + match` combinations that are easier
@@ -648,7 +604,6 @@ declare_lint_pass!(Loops => [
648604
EXPLICIT_ITER_LOOP,
649605
EXPLICIT_INTO_ITER_LOOP,
650606
ITER_NEXT_LOOP,
651-
FOR_LOOPS_OVER_FALLIBLES,
652607
WHILE_LET_LOOP,
653608
NEEDLESS_COLLECT,
654609
EXPLICIT_COUNTER_LOOP,
@@ -739,30 +694,22 @@ fn check_for_loop<'tcx>(
739694
manual_find::check(cx, pat, arg, body, span, expr);
740695
}
741696

742-
fn check_for_loop_arg(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>) {
743-
let mut next_loop_linted = false; // whether or not ITER_NEXT_LOOP lint was used
744-
697+
fn check_for_loop_arg(cx: &LateContext<'_>, _: &Pat<'_>, arg: &Expr<'_>) {
745698
if let ExprKind::MethodCall(method, self_arg, [], _) = arg.kind {
746699
let method_name = method.ident.as_str();
747700
// check for looping over x.iter() or x.iter_mut(), could use &x or &mut x
748701
match method_name {
749702
"iter" | "iter_mut" => {
750703
explicit_iter_loop::check(cx, self_arg, arg, method_name);
751-
for_loops_over_fallibles::check(cx, pat, self_arg, Some(method_name));
752704
},
753705
"into_iter" => {
754706
explicit_iter_loop::check(cx, self_arg, arg, method_name);
755707
explicit_into_iter_loop::check(cx, self_arg, arg);
756-
for_loops_over_fallibles::check(cx, pat, self_arg, Some(method_name));
757708
},
758709
"next" => {
759-
next_loop_linted = iter_next_loop::check(cx, arg);
710+
iter_next_loop::check(cx, arg);
760711
},
761712
_ => {},
762713
}
763714
}
764-
765-
if !next_loop_linted {
766-
for_loops_over_fallibles::check(cx, pat, arg, None);
767-
}
768715
}

clippy_lints/src/loops/mut_range_bound.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,15 @@ fn check_for_mutation<'tcx>(
6565
span_low: None,
6666
span_high: None,
6767
};
68-
cx.tcx.infer_ctxt().enter(|infcx| {
69-
ExprUseVisitor::new(
70-
&mut delegate,
71-
&infcx,
72-
body.hir_id.owner.def_id,
73-
cx.param_env,
74-
cx.typeck_results(),
75-
)
76-
.walk_expr(body);
77-
});
68+
let infcx = cx.tcx.infer_ctxt().build();
69+
ExprUseVisitor::new(
70+
&mut delegate,
71+
&infcx,
72+
body.hir_id.owner.def_id,
73+
cx.param_env,
74+
cx.typeck_results(),
75+
)
76+
.walk_expr(body);
7877

7978
delegate.mutation_span()
8079
}

clippy_lints/src/methods/unnecessary_to_owned.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
363363
&& let output_ty = return_ty(cx, item.hir_id())
364364
&& let local_def_id = cx.tcx.hir().local_def_id(item.hir_id())
365365
&& Inherited::build(cx.tcx, local_def_id).enter(|inherited| {
366-
let fn_ctxt = FnCtxt::new(&inherited, cx.param_env, item.hir_id());
366+
let fn_ctxt = FnCtxt::new(inherited, cx.param_env, item.hir_id());
367367
fn_ctxt.can_coerce(ty, output_ty)
368368
}) {
369369
if has_lifetime(output_ty) && has_lifetime(ty) {
@@ -420,9 +420,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
420420
if trait_predicates.any(|predicate| {
421421
let predicate = EarlyBinder(predicate).subst(cx.tcx, new_subst);
422422
let obligation = Obligation::new(ObligationCause::dummy(), cx.param_env, predicate);
423-
!cx.tcx
424-
.infer_ctxt()
425-
.enter(|infcx| infcx.predicate_must_hold_modulo_regions(&obligation))
423+
!cx.tcx.infer_ctxt().build().predicate_must_hold_modulo_regions(&obligation)
426424
}) {
427425
return false;
428426
}

clippy_lints/src/missing_inline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
148148

149149
let desc = match impl_item.kind {
150150
hir::ImplItemKind::Fn(..) => "a method",
151-
hir::ImplItemKind::Const(..) | hir::ImplItemKind::TyAlias(_) => return,
151+
hir::ImplItemKind::Const(..) | hir::ImplItemKind::Type(_) => return,
152152
};
153153

154154
let assoc_item = cx.tcx.associated_item(impl_item.def_id);

clippy_lints/src/needless_pass_by_value.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,8 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
138138
..
139139
} = {
140140
let mut ctx = MovedVariablesCtxt::default();
141-
cx.tcx.infer_ctxt().enter(|infcx| {
142-
euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.typeck_results())
143-
.consume_body(body);
144-
});
141+
let infcx = cx.tcx.infer_ctxt().build();
142+
euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body);
145143
ctx
146144
};
147145

0 commit comments

Comments
 (0)