Skip to content

Commit d7b5cbf

Browse files
committed
Auto merge of #9007 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
2 parents 9edd641 + 280797e commit d7b5cbf

Some content is hidden

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

66 files changed

+208
-192
lines changed

clippy_lints/src/almost_complete_letter_range.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ fn check_range(cx: &EarlyContext<'_>, span: Span, start: &Expr, end: &Expr, sugg
9090
diag.span_suggestion(
9191
span,
9292
"use an inclusive range",
93-
sugg.to_owned(),
93+
sugg,
9494
Applicability::MaybeIncorrect,
9595
);
9696
}

clippy_lints/src/as_underscore.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl<'tcx> LateLintPass<'tcx> for AsUnderscore {
6363
diag.span_suggestion(
6464
ty.span,
6565
"consider giving the type explicitly",
66-
format!("{}", ty_resolved),
66+
ty_resolved,
6767
Applicability::MachineApplicable,
6868
);
6969
}

clippy_lints/src/attrs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
340340
for lint in lint_list {
341341
match item.kind {
342342
ItemKind::Use(..) => {
343-
if is_word(lint, sym!(unused_imports))
343+
if is_word(lint, sym::unused_imports)
344344
|| is_word(lint, sym::deprecated)
345345
|| is_word(lint, sym!(unreachable_pub))
346346
|| is_word(lint, sym!(unused))
@@ -355,7 +355,7 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
355355
}
356356
},
357357
ItemKind::ExternCrate(..) => {
358-
if is_word(lint, sym!(unused_imports)) && skip_unused_imports {
358+
if is_word(lint, sym::unused_imports) && skip_unused_imports {
359359
return;
360360
}
361361
if is_word(lint, sym!(unused_extern_crates)) {

clippy_lints/src/blocks_in_if_conditions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ struct ExVisitor<'a, 'tcx> {
5151

5252
impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> {
5353
fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) {
54-
if let ExprKind::Closure(_, _, eid, _, _) = expr.kind {
54+
if let ExprKind::Closure { body, .. } = expr.kind {
5555
// do not lint if the closure is called using an iterator (see #1141)
5656
if_chain! {
5757
if let Some(parent) = get_parent_expr(self.cx, expr);
@@ -64,7 +64,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> {
6464
}
6565
}
6666

67-
let body = self.cx.tcx.hir().body(eid);
67+
let body = self.cx.tcx.hir().body(body);
6868
let ex = &body.value;
6969
if let ExprKind::Block(block, _) = ex.kind {
7070
if !body.value.span.from_expansion() && !block.stmts.is_empty() {

clippy_lints/src/bytecount.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ impl<'tcx> LateLintPass<'tcx> for ByteCount {
5151
if count.ident.name == sym::count;
5252
if let ExprKind::MethodCall(filter, [filter_recv, filter_arg], _) = count_recv.kind;
5353
if filter.ident.name == sym!(filter);
54-
if let ExprKind::Closure(_, _, body_id, _, _) = filter_arg.kind;
55-
let body = cx.tcx.hir().body(body_id);
54+
if let ExprKind::Closure { body, .. } = filter_arg.kind;
55+
let body = cx.tcx.hir().body(body);
5656
if let [param] = body.params;
5757
if let PatKind::Binding(_, arg_id, _, _) = strip_pat_refs(param.pat).kind;
5858
if let ExprKind::Binary(ref op, l, r) = body.value.kind;

clippy_lints/src/dereference.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ fn is_linted_explicit_deref_position(parent: Option<Node<'_>>, child_id: HirId,
514514
| ExprKind::Loop(..)
515515
| ExprKind::Match(..)
516516
| ExprKind::Let(..)
517-
| ExprKind::Closure(..)
517+
| ExprKind::Closure{..}
518518
| ExprKind::Block(..)
519519
| ExprKind::Assign(..)
520520
| ExprKind::AssignOp(..)

clippy_lints/src/empty_structs_with_brackets.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl EarlyLintPass for EmptyStructsWithBrackets {
4444
diagnostic.span_suggestion_hidden(
4545
span_after_ident,
4646
"remove the brackets",
47-
";".to_string(),
47+
";",
4848
Applicability::MachineApplicable);
4949
},
5050
);

clippy_lints/src/enum_clike.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ impl<'tcx> LateLintPass<'tcx> for UnportableVariant {
5050
.tcx
5151
.const_eval_poly(def_id.to_def_id())
5252
.ok()
53-
.map(|val| rustc_middle::ty::Const::from_value(cx.tcx, val, ty));
54-
if let Some(Constant::Int(val)) = constant.and_then(miri_to_const) {
53+
.map(|val| rustc_middle::mir::ConstantKind::from_value(val, ty));
54+
if let Some(Constant::Int(val)) = constant.and_then(|c| miri_to_const(cx.tcx, c)) {
5555
if let ty::Adt(adt, _) = ty.kind() {
5656
if adt.is_enum() {
5757
ty = adt.repr().discr_type().to_ty(cx.tcx);

clippy_lints/src/eta_reduction.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction {
7878
return;
7979
}
8080
let body = match expr.kind {
81-
ExprKind::Closure(_, _, id, _, _) => cx.tcx.hir().body(id),
81+
ExprKind::Closure { body, .. } => cx.tcx.hir().body(body),
8282
_ => return,
8383
};
8484
if body.value.span.from_expansion() {

clippy_lints/src/infinite_iter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ fn is_infinite(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness {
159159
}
160160
}
161161
if method.ident.name == sym!(flat_map) && args.len() == 2 {
162-
if let ExprKind::Closure(_, _, body_id, _, _) = args[1].kind {
163-
let body = cx.tcx.hir().body(body_id);
162+
if let ExprKind::Closure { body, .. } = args[1].kind {
163+
let body = cx.tcx.hir().body(body);
164164
return is_infinite(cx, &body.value);
165165
}
166166
}

clippy_lints/src/large_const_arrays.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use if_chain::if_chain;
33
use rustc_errors::Applicability;
44
use rustc_hir::{Item, ItemKind};
55
use rustc_lint::{LateContext, LateLintPass};
6-
use rustc_middle::mir::interpret::ConstValue;
76
use rustc_middle::ty::layout::LayoutOf;
87
use rustc_middle::ty::{self, ConstKind};
98
use rustc_session::{declare_tool_lint, impl_lint_pass};
@@ -54,8 +53,8 @@ impl<'tcx> LateLintPass<'tcx> for LargeConstArrays {
5453
if let ItemKind::Const(hir_ty, _) = &item.kind;
5554
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
5655
if let ty::Array(element_type, cst) = ty.kind();
57-
if let ConstKind::Value(ConstValue::Scalar(element_count)) = cst.val();
58-
if let Ok(element_count) = element_count.to_machine_usize(&cx.tcx);
56+
if let ConstKind::Value(ty::ValTree::Leaf(element_count)) = cst.kind();
57+
if let Ok(element_count) = element_count.try_to_machine_usize(cx.tcx);
5958
if let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes());
6059
if self.maximum_allowed_size < element_count * element_size;
6160

@@ -76,7 +75,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeConstArrays {
7675
diag.span_suggestion(
7776
sugg_span,
7877
"make this a static item",
79-
"static".to_string(),
78+
"static",
8079
Applicability::MachineApplicable,
8180
);
8281
}

clippy_lints/src/large_stack_arrays.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use clippy_utils::source::snippet;
33
use if_chain::if_chain;
44
use rustc_hir::{Expr, ExprKind};
55
use rustc_lint::{LateContext, LateLintPass};
6-
use rustc_middle::mir::interpret::ConstValue;
76
use rustc_middle::ty::layout::LayoutOf;
87
use rustc_middle::ty::{self, ConstKind};
98
use rustc_session::{declare_tool_lint, impl_lint_pass};
@@ -43,8 +42,8 @@ impl<'tcx> LateLintPass<'tcx> for LargeStackArrays {
4342
if_chain! {
4443
if let ExprKind::Repeat(_, _) = expr.kind;
4544
if let ty::Array(element_type, cst) = cx.typeck_results().expr_ty(expr).kind();
46-
if let ConstKind::Value(ConstValue::Scalar(element_count)) = cst.val();
47-
if let Ok(element_count) = element_count.to_machine_usize(&cx.tcx);
45+
if let ConstKind::Value(ty::ValTree::Leaf(element_count)) = cst.kind();
46+
if let Ok(element_count) = element_count.try_to_machine_usize(cx.tcx);
4847
if let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes());
4948
if self.maximum_allowed_size < element_count * element_size;
5049
then {

clippy_lints/src/loops/needless_range_loop.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,8 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
369369
self.visit_expr(expr);
370370
}
371371
},
372-
ExprKind::Closure(_, _, body_id, ..) => {
373-
let body = self.cx.tcx.hir().body(body_id);
372+
ExprKind::Closure { body, .. } => {
373+
let body = self.cx.tcx.hir().body(body);
374374
self.visit_expr(&body.value);
375375
},
376376
_ => walk_expr(self, expr),

clippy_lints/src/loops/never_loop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult {
188188
})
189189
.fold(NeverLoopResult::Otherwise, combine_both),
190190
ExprKind::Yield(_, _)
191-
| ExprKind::Closure(_, _, _, _, _)
191+
| ExprKind::Closure { .. }
192192
| ExprKind::Path(_)
193193
| ExprKind::ConstBlock(_)
194194
| ExprKind::Lit(_)

clippy_lints/src/loops/while_let_on_iterator.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ fn uses_iter<'tcx>(cx: &LateContext<'tcx>, iter_expr: &IterExpr, container: &'tc
220220
if let Some(e) = e {
221221
self.visit_expr(e);
222222
}
223-
} else if let ExprKind::Closure(_, _, id, _, _) = e.kind {
223+
} else if let ExprKind::Closure { body: id, .. } = e.kind {
224224
if is_res_used(self.cx, self.iter_expr.path, id) {
225225
self.uses_iter = true;
226226
}
@@ -260,7 +260,7 @@ fn needs_mutable_borrow(cx: &LateContext<'_>, iter_expr: &IterExpr, loop_expr: &
260260
if let Some(e) = e {
261261
self.visit_expr(e);
262262
}
263-
} else if let ExprKind::Closure(_, _, id, _, _) = e.kind {
263+
} else if let ExprKind::Closure { body: id, .. } = e.kind {
264264
self.used_iter = is_res_used(self.cx, self.iter_expr.path, id);
265265
} else {
266266
walk_expr(self, e);
@@ -307,7 +307,7 @@ fn needs_mutable_borrow(cx: &LateContext<'_>, iter_expr: &IterExpr, loop_expr: &
307307
if let Some(e) = e {
308308
self.visit_expr(e);
309309
}
310-
} else if let ExprKind::Closure(_, _, id, _, _) = e.kind {
310+
} else if let ExprKind::Closure { body: id, .. } = e.kind {
311311
self.used_after = is_res_used(self.cx, self.iter_expr.path, id);
312312
} else {
313313
walk_expr(self, e);

clippy_lints/src/manual_async_fn.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualAsyncFn {
8686
diag.span_suggestion(
8787
block.span,
8888
"move the body of the async block to the enclosing function",
89-
body_snip.to_string(),
89+
body_snip,
9090
Applicability::MachineApplicable
9191
);
9292
}
@@ -177,8 +177,8 @@ fn desugared_async_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>)
177177
if let Some(block_expr) = block.expr;
178178
if let Some(args) = match_function_call(cx, block_expr, &FUTURE_FROM_GENERATOR);
179179
if args.len() == 1;
180-
if let Expr{kind: ExprKind::Closure(_, _, body_id, ..), ..} = args[0];
181-
let closure_body = cx.tcx.hir().body(body_id);
180+
if let Expr{kind: ExprKind::Closure { body, .. }, ..} = args[0];
181+
let closure_body = cx.tcx.hir().body(body);
182182
if closure_body.generator_kind == Some(GeneratorKind::Async(AsyncGeneratorKind::Block));
183183
then {
184184
return Some(closure_body);

clippy_lints/src/manual_ok_or.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ fn is_ok_wrapping(cx: &LateContext<'_>, map_expr: &Expr<'_>) -> bool {
8888
}
8989
}
9090
if_chain! {
91-
if let ExprKind::Closure(_, _, body_id, ..) = map_expr.kind;
92-
let body = cx.tcx.hir().body(body_id);
91+
if let ExprKind::Closure { body, .. } = map_expr.kind;
92+
let body = cx.tcx.hir().body(body);
9393
if let PatKind::Binding(_, param_id, ..) = body.params[0].pat.kind;
9494
if let ExprKind::Call(Expr { kind: ExprKind::Path(ok_path), .. }, &[ref ok_arg]) = body.value.kind;
9595
if is_lang_ctor(cx, ok_path, ResultOk);

clippy_lints/src/map_clone.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ impl<'tcx> LateLintPass<'tcx> for MapClone {
6767
if method.ident.name == sym::map;
6868
let ty = cx.typeck_results().expr_ty(&args[0]);
6969
if is_type_diagnostic_item(cx, ty, sym::Option) || is_trait_method(cx, e, sym::Iterator);
70-
if let hir::ExprKind::Closure(_, _, body_id, _, _) = args[1].kind;
70+
if let hir::ExprKind::Closure { body, .. } = args[1].kind;
7171
then {
72-
let closure_body = cx.tcx.hir().body(body_id);
72+
let closure_body = cx.tcx.hir().body(body);
7373
let closure_expr = peel_blocks(&closure_body.value);
7474
match closure_body.params[0].pat.kind {
7575
hir::PatKind::Ref(inner, hir::Mutability::Not) => if let hir::PatKind::Binding(

clippy_lints/src/map_err_ignore.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,19 @@ impl<'tcx> LateLintPass<'tcx> for MapErrIgnore {
117117
// only work if the method name is `map_err` and there are only 2 arguments (e.g. x.map_err(|_|[1]
118118
// Enum::Variant[2]))
119119
if method.ident.as_str() == "map_err" && args.len() == 2 {
120-
// make sure the first argument is a closure, and grab the CaptureRef, body_id, and body_span fields
121-
if let ExprKind::Closure(capture, _, body_id, body_span, _) = args[1].kind {
120+
// make sure the first argument is a closure, and grab the CaptureRef, BodyId, and fn_decl_span
121+
// fields
122+
if let ExprKind::Closure {
123+
capture_clause,
124+
body,
125+
fn_decl_span,
126+
..
127+
} = args[1].kind
128+
{
122129
// check if this is by Reference (meaning there's no move statement)
123-
if capture == CaptureBy::Ref {
130+
if capture_clause == CaptureBy::Ref {
124131
// Get the closure body to check the parameters and values
125-
let closure_body = cx.tcx.hir().body(body_id);
132+
let closure_body = cx.tcx.hir().body(body);
126133
// make sure there's only one parameter (`|_|`)
127134
if closure_body.params.len() == 1 {
128135
// make sure that parameter is the wild token (`_`)
@@ -132,7 +139,7 @@ impl<'tcx> LateLintPass<'tcx> for MapErrIgnore {
132139
span_lint_and_help(
133140
cx,
134141
MAP_ERR_IGNORE,
135-
body_span,
142+
fn_decl_span,
136143
"`map_err(|_|...` wildcard pattern discards the original error",
137144
None,
138145
"consider storing the original error as a source in the new error, or silence this warning using an ignored identifier (`.map_err(|_foo| ...`)",

clippy_lints/src/map_unit_fn.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,12 @@ fn unit_closure<'tcx>(
169169
expr: &hir::Expr<'_>,
170170
) -> Option<(&'tcx hir::Param<'tcx>, &'tcx hir::Expr<'tcx>)> {
171171
if_chain! {
172-
if let hir::ExprKind::Closure(_, decl, inner_expr_id, _, _) = expr.kind;
173-
let body = cx.tcx.hir().body(inner_expr_id);
172+
if let hir::ExprKind::Closure { fn_decl, body, .. } = expr.kind;
173+
let body = cx.tcx.hir().body(body);
174174
let body_expr = &body.value;
175-
if decl.inputs.len() == 1;
175+
if fn_decl.inputs.len() == 1;
176176
if is_unit_expression(cx, body_expr);
177-
if let Some(binding) = iter_input_pats(decl, body).next();
177+
if let Some(binding) = iter_input_pats(fn_decl, body).next();
178178
then {
179179
return Some((binding, body_expr));
180180
}

clippy_lints/src/matches/match_same_arms.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,9 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>]) {
110110
arm1.span,
111111
"this match arm has an identical body to the `_` wildcard arm",
112112
|diag| {
113-
diag.span_suggestion(
114-
arm1.span,
115-
"try removing the arm",
116-
String::new(),
117-
Applicability::MaybeIncorrect,
118-
)
119-
.help("or try changing either arm body")
120-
.span_note(arm2.span, "`_` wildcard arm here");
113+
diag.span_suggestion(arm1.span, "try removing the arm", "", Applicability::MaybeIncorrect)
114+
.help("or try changing either arm body")
115+
.span_note(arm2.span, "`_` wildcard arm here");
121116
},
122117
);
123118
} else {

clippy_lints/src/matches/match_single_binding.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ fn sugg_with_curlies<'a>(
177177

178178
let (mut cbrace_start, mut cbrace_end) = (String::new(), String::new());
179179
if let Some(parent_expr) = get_parent_expr(cx, match_expr) {
180-
if let ExprKind::Closure(..) = parent_expr.kind {
180+
if let ExprKind::Closure { .. } = parent_expr.kind {
181181
cbrace_end = format!("\n{}}}", indent);
182182
// Fix body indent due to the closure
183183
indent = " ".repeat(indent_of(cx, bind_names).unwrap_or(0));

clippy_lints/src/matches/overlapping_arms.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use clippy_utils::diagnostics::span_lint_and_note;
33
use core::cmp::Ordering;
44
use rustc_hir::{Arm, Expr, PatKind, RangeEnd};
55
use rustc_lint::LateContext;
6+
use rustc_middle::mir;
67
use rustc_middle::ty::Ty;
78
use rustc_span::Span;
89

@@ -34,11 +35,25 @@ fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>)
3435
if let PatKind::Range(ref lhs, ref rhs, range_end) = pat.kind {
3536
let lhs_const = match lhs {
3637
Some(lhs) => constant(cx, cx.typeck_results(), lhs)?.0,
37-
None => miri_to_const(ty.numeric_min_val(cx.tcx)?)?,
38+
None => {
39+
let min_val_const = ty.numeric_min_val(cx.tcx)?;
40+
let min_constant = mir::ConstantKind::from_value(
41+
cx.tcx.valtree_to_const_val((ty, min_val_const.to_valtree())),
42+
ty,
43+
);
44+
miri_to_const(cx.tcx, min_constant)?
45+
},
3846
};
3947
let rhs_const = match rhs {
4048
Some(rhs) => constant(cx, cx.typeck_results(), rhs)?.0,
41-
None => miri_to_const(ty.numeric_max_val(cx.tcx)?)?,
49+
None => {
50+
let max_val_const = ty.numeric_max_val(cx.tcx)?;
51+
let max_constant = mir::ConstantKind::from_value(
52+
cx.tcx.valtree_to_const_val((ty, max_val_const.to_valtree())),
53+
ty,
54+
);
55+
miri_to_const(cx.tcx, max_constant)?
56+
},
4257
};
4358
let lhs_val = lhs_const.int_value(cx, ty)?;
4459
let rhs_val = rhs_const.int_value(cx, ty)?;

clippy_lints/src/matches/redundant_pattern_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ fn temporaries_need_ordered_drop<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<
7070
}
7171
}
7272
},
73-
// the base type is alway taken by reference.
73+
// the base type is always taken by reference.
7474
// e.g. In `(vec![0])[0]` the vector is a temporary value.
7575
ExprKind::Index(base, index) => {
7676
if !matches!(base.kind, ExprKind::Path(_)) {

0 commit comments

Comments
 (0)