Skip to content

Commit b40ea20

Browse files
committed
Auto merge of #7051 - flip1995:rustup, r=flip1995
Rustup changelog: none r? `@ghost`
2 parents db6ea84 + 61eafbb commit b40ea20

24 files changed

+65
-61
lines changed

clippy_lints/src/default_numeric_fallback.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rustc_middle::{
1313
ty::{self, FloatTy, IntTy, PolyFnSig, Ty},
1414
};
1515
use rustc_session::{declare_lint_pass, declare_tool_lint};
16+
use std::iter;
1617

1718
declare_clippy_lint! {
1819
/// **What it does:** Checks for usage of unconstrained numeric literals which may cause default numeric fallback in type
@@ -107,7 +108,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
107108
match &expr.kind {
108109
ExprKind::Call(func, args) => {
109110
if let Some(fn_sig) = fn_sig_opt(self.cx, func.hir_id) {
110-
for (expr, bound) in args.iter().zip(fn_sig.skip_binder().inputs().iter()) {
111+
for (expr, bound) in iter::zip(*args, fn_sig.skip_binder().inputs()) {
111112
// Push found arg type, then visit arg.
112113
self.ty_bounds.push(TyBound::Ty(bound));
113114
self.visit_expr(expr);
@@ -120,7 +121,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
120121
ExprKind::MethodCall(_, _, args, _) => {
121122
if let Some(def_id) = self.cx.typeck_results().type_dependent_def_id(expr.hir_id) {
122123
let fn_sig = self.cx.tcx.fn_sig(def_id).skip_binder();
123-
for (expr, bound) in args.iter().zip(fn_sig.inputs().iter()) {
124+
for (expr, bound) in iter::zip(*args, fn_sig.inputs()) {
124125
self.ty_bounds.push(TyBound::Ty(bound));
125126
self.visit_expr(expr);
126127
self.ty_bounds.pop();

clippy_lints/src/functions/must_use.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ fn check_needless_must_use(
115115
);
116116
},
117117
);
118-
} else if !attr.is_value_str() && is_must_use_ty(cx, return_ty(cx, item_id)) {
118+
} else if attr.value_str().is_none() && is_must_use_ty(cx, return_ty(cx, item_id)) {
119119
span_lint_and_help(
120120
cx,
121121
DOUBLE_MUST_USE,

clippy_lints/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#![feature(box_syntax)]
55
#![feature(drain_filter)]
66
#![feature(in_band_lifetimes)]
7+
#![feature(iter_zip)]
78
#![feature(once_cell)]
89
#![feature(rustc_private)]
910
#![feature(stmt_expr_attributes)]

clippy_lints/src/literal_representation.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rustc_errors::Applicability;
1313
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
1414
use rustc_middle::lint::in_external_macro;
1515
use rustc_session::{declare_tool_lint, impl_lint_pass};
16+
use std::iter;
1617

1718
declare_clippy_lint! {
1819
/// **What it does:** Warns if a long integral or floating-point constant does
@@ -349,7 +350,7 @@ impl LiteralDigitGrouping {
349350

350351
let group_sizes: Vec<usize> = num_lit.integer.split('_').map(str::len).collect();
351352
if UUID_GROUP_LENS.len() == group_sizes.len() {
352-
UUID_GROUP_LENS.iter().zip(&group_sizes).all(|(&a, &b)| a == b)
353+
iter::zip(&UUID_GROUP_LENS, &group_sizes).all(|(&a, &b)| a == b)
353354
} else {
354355
false
355356
}

clippy_lints/src/loops/needless_range_loop.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_middle::hir::map::Map;
1717
use rustc_middle::middle::region;
1818
use rustc_middle::ty::{self, Ty};
1919
use rustc_span::symbol::{sym, Symbol};
20-
use std::iter::Iterator;
20+
use std::iter::{self, Iterator};
2121
use std::mem;
2222

2323
/// Checks for looping over a range and then indexing a sequence with it.
@@ -367,7 +367,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
367367
},
368368
ExprKind::MethodCall(_, _, args, _) => {
369369
let def_id = self.cx.typeck_results().type_dependent_def_id(expr.hir_id).unwrap();
370-
for (ty, expr) in self.cx.tcx.fn_sig(def_id).inputs().skip_binder().iter().zip(args) {
370+
for (ty, expr) in iter::zip(self.cx.tcx.fn_sig(def_id).inputs().skip_binder(), args) {
371371
self.prefer_mutable = false;
372372
if let ty::Ref(_, _, mutbl) = *ty.kind() {
373373
if mutbl == Mutability::Mut {

clippy_lints/src/loops/never_loop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,12 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult {
142142
.map(|(o, _)| match o {
143143
InlineAsmOperand::In { expr, .. }
144144
| InlineAsmOperand::InOut { expr, .. }
145-
| InlineAsmOperand::Const { expr }
146145
| InlineAsmOperand::Sym { expr } => never_loop_expr(expr, main_loop_id),
147146
InlineAsmOperand::Out { expr, .. } => never_loop_expr_all(&mut expr.iter(), main_loop_id),
148147
InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => {
149148
never_loop_expr_all(&mut once(in_expr).chain(out_expr.iter()), main_loop_id)
150149
},
150+
InlineAsmOperand::Const { .. } => NeverLoopResult::Otherwise,
151151
})
152152
.fold(NeverLoopResult::Otherwise, combine_both),
153153
ExprKind::Struct(_, _, None)

clippy_lints/src/matches.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use rustc_span::source_map::{Span, Spanned};
2929
use rustc_span::sym;
3030
use std::cmp::Ordering;
3131
use std::collections::hash_map::Entry;
32+
use std::iter;
3233
use std::ops::Bound;
3334

3435
declare_clippy_lint! {
@@ -1670,7 +1671,7 @@ where
16701671

16711672
values.sort();
16721673

1673-
for (a, b) in values.iter().zip(values.iter().skip(1)) {
1674+
for (a, b) in iter::zip(&values, values.iter().skip(1)) {
16741675
match (a, b) {
16751676
(&Kind::Start(_, ra), &Kind::End(_, rb)) => {
16761677
if ra.node != rb.node {

clippy_lints/src/missing_doc.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ impl MissingDoc {
9393
return;
9494
}
9595

96-
let has_doc = attrs
97-
.iter()
98-
.any(|a| a.is_doc_comment() || a.doc_str().is_some() || a.is_value_str() || Self::has_include(a.meta()));
96+
let has_doc = attrs.iter().any(|a| {
97+
a.is_doc_comment() || a.doc_str().is_some() || a.value_str().is_some() || Self::has_include(a.meta())
98+
});
9999
if !has_doc {
100100
span_lint(
101101
cx,
@@ -121,7 +121,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
121121

122122
fn check_crate(&mut self, cx: &LateContext<'tcx>, krate: &'tcx hir::Crate<'_>) {
123123
let attrs = cx.tcx.hir().attrs(hir::CRATE_HIR_ID);
124-
self.check_missing_docs_attrs(cx, attrs, krate.item.span, "the", "crate");
124+
self.check_missing_docs_attrs(cx, attrs, krate.item.inner, "the", "crate");
125125
}
126126

127127
fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) {

clippy_lints/src/mut_key.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc_middle::ty::TypeFoldable;
66
use rustc_middle::ty::{Adt, Array, RawPtr, Ref, Slice, Tuple, Ty, TypeAndMut};
77
use rustc_session::{declare_lint_pass, declare_tool_lint};
88
use rustc_span::source_map::Span;
9+
use std::iter;
910

1011
declare_clippy_lint! {
1112
/// **What it does:** Checks for sets/maps with mutable key types.
@@ -87,7 +88,7 @@ impl<'tcx> LateLintPass<'tcx> for MutableKeyType {
8788
fn check_sig<'tcx>(cx: &LateContext<'tcx>, item_hir_id: hir::HirId, decl: &hir::FnDecl<'_>) {
8889
let fn_def_id = cx.tcx.hir().local_def_id(item_hir_id);
8990
let fn_sig = cx.tcx.fn_sig(fn_def_id);
90-
for (hir_ty, ty) in decl.inputs.iter().zip(fn_sig.inputs().skip_binder().iter()) {
91+
for (hir_ty, ty) in iter::zip(decl.inputs, fn_sig.inputs().skip_binder()) {
9192
check_ty(cx, hir_ty.span, ty);
9293
}
9394
check_ty(cx, decl.output.span(), cx.tcx.erase_late_bound_regions(fn_sig.output()));

clippy_lints/src/mut_reference.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use rustc_lint::{LateContext, LateLintPass};
44
use rustc_middle::ty::subst::Subst;
55
use rustc_middle::ty::{self, Ty};
66
use rustc_session::{declare_lint_pass, declare_tool_lint};
7+
use std::iter;
78

89
declare_clippy_lint! {
910
/// **What it does:** Detects passing a mutable reference to a function that only
@@ -64,7 +65,7 @@ fn check_arguments<'tcx>(
6465
match type_definition.kind() {
6566
ty::FnDef(..) | ty::FnPtr(_) => {
6667
let parameters = type_definition.fn_sig(cx.tcx).skip_binder().inputs();
67-
for (argument, parameter) in arguments.iter().zip(parameters.iter()) {
68+
for (argument, parameter) in iter::zip(arguments, parameters) {
6869
match parameter.kind() {
6970
ty::Ref(_, _, Mutability::Not)
7071
| ty::RawPtr(ty::TypeAndMut {

clippy_lints/src/pass_by_ref_or_value.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::cmp;
2+
use std::iter;
23

34
use clippy_utils::diagnostics::span_lint_and_sugg;
45
use clippy_utils::is_self_ty;
@@ -122,7 +123,7 @@ impl<'tcx> PassByRefOrValue {
122123

123124
let fn_body = cx.enclosing_body.map(|id| cx.tcx.hir().body(id));
124125

125-
for (index, (input, &ty)) in decl.inputs.iter().zip(fn_sig.inputs()).enumerate() {
126+
for (index, (input, &ty)) in iter::zip(decl.inputs, fn_sig.inputs()).enumerate() {
126127
// All spans generated from a proc-macro invocation are the same...
127128
match span {
128129
Some(s) if s == input.span => return,

clippy_lints/src/pattern_type_mismatch.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_middle::ty::subst::SubstsRef;
1010
use rustc_middle::ty::{AdtDef, FieldDef, Ty, TyKind, VariantDef};
1111
use rustc_session::{declare_lint_pass, declare_tool_lint};
1212
use rustc_span::source_map::Span;
13+
use std::iter;
1314

1415
declare_clippy_lint! {
1516
/// **What it does:** Checks for patterns that aren't exact representations of the types
@@ -134,7 +135,7 @@ impl<'tcx> LateLintPass<'tcx> for PatternTypeMismatch {
134135
hir_id: HirId,
135136
) {
136137
if let Some(fn_sig) = cx.typeck_results().liberated_fn_sigs().get(hir_id) {
137-
for (param, ty) in body.params.iter().zip(fn_sig.inputs().iter()) {
138+
for (param, ty) in iter::zip(body.params, fn_sig.inputs()) {
138139
apply_lint(cx, param.pat, ty, DerefPossible::Impossible);
139140
}
140141
}

clippy_lints/src/unit_return_expecting_ord.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn get_trait_predicates_for_trait_id<'tcx>(
4444
for (pred, _) in generics.predicates {
4545
if_chain! {
4646
if let PredicateKind::Trait(poly_trait_pred, _) = pred.kind().skip_binder();
47-
let trait_pred = cx.tcx.erase_late_bound_regions(ty::Binder::bind(poly_trait_pred));
47+
let trait_pred = cx.tcx.erase_late_bound_regions(pred.kind().rebind(poly_trait_pred));
4848
if let Some(trait_def_id) = trait_id;
4949
if trait_def_id == trait_pred.trait_ref.def_id;
5050
then {
@@ -58,12 +58,12 @@ fn get_trait_predicates_for_trait_id<'tcx>(
5858
fn get_projection_pred<'tcx>(
5959
cx: &LateContext<'tcx>,
6060
generics: GenericPredicates<'tcx>,
61-
pred: TraitPredicate<'tcx>,
61+
trait_pred: TraitPredicate<'tcx>,
6262
) -> Option<ProjectionPredicate<'tcx>> {
6363
generics.predicates.iter().find_map(|(proj_pred, _)| {
64-
if let ty::PredicateKind::Projection(proj_pred) = proj_pred.kind().skip_binder() {
65-
let projection_pred = cx.tcx.erase_late_bound_regions(ty::Binder::bind(proj_pred));
66-
if projection_pred.projection_ty.substs == pred.trait_ref.substs {
64+
if let ty::PredicateKind::Projection(pred) = proj_pred.kind().skip_binder() {
65+
let projection_pred = cx.tcx.erase_late_bound_regions(proj_pred.kind().rebind(pred));
66+
if projection_pred.projection_ty.substs == trait_pred.trait_ref.substs {
6767
return Some(projection_pred);
6868
}
6969
}

clippy_lints/src/unnecessary_sort_by.rs

+10-18
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_middle::ty::{self, subst::GenericArgKind};
99
use rustc_session::{declare_lint_pass, declare_tool_lint};
1010
use rustc_span::sym;
1111
use rustc_span::symbol::Ident;
12+
use std::iter;
1213

1314
declare_clippy_lint! {
1415
/// **What it does:**
@@ -79,17 +80,14 @@ fn mirrored_exprs(
7980
mirrored_exprs(cx, left_expr, a_ident, right_expr, b_ident)
8081
},
8182
// Two arrays with mirrored contents
82-
(ExprKind::Array(left_exprs), ExprKind::Array(right_exprs)) => left_exprs
83-
.iter()
84-
.zip(right_exprs.iter())
85-
.all(|(left, right)| mirrored_exprs(cx, left, a_ident, right, b_ident)),
83+
(ExprKind::Array(left_exprs), ExprKind::Array(right_exprs)) => {
84+
iter::zip(*left_exprs, *right_exprs).all(|(left, right)| mirrored_exprs(cx, left, a_ident, right, b_ident))
85+
},
8686
// The two exprs are function calls.
8787
// Check to see that the function itself and its arguments are mirrored
8888
(ExprKind::Call(left_expr, left_args), ExprKind::Call(right_expr, right_args)) => {
8989
mirrored_exprs(cx, left_expr, a_ident, right_expr, b_ident)
90-
&& left_args
91-
.iter()
92-
.zip(right_args.iter())
90+
&& iter::zip(*left_args, *right_args)
9391
.all(|(left, right)| mirrored_exprs(cx, left, a_ident, right, b_ident))
9492
},
9593
// The two exprs are method calls.
@@ -100,16 +98,13 @@ fn mirrored_exprs(
10098
ExprKind::MethodCall(right_segment, _, right_args, _),
10199
) => {
102100
left_segment.ident == right_segment.ident
103-
&& left_args
104-
.iter()
105-
.zip(right_args.iter())
101+
&& iter::zip(*left_args, *right_args)
106102
.all(|(left, right)| mirrored_exprs(cx, left, a_ident, right, b_ident))
107103
},
108104
// Two tuples with mirrored contents
109-
(ExprKind::Tup(left_exprs), ExprKind::Tup(right_exprs)) => left_exprs
110-
.iter()
111-
.zip(right_exprs.iter())
112-
.all(|(left, right)| mirrored_exprs(cx, left, a_ident, right, b_ident)),
105+
(ExprKind::Tup(left_exprs), ExprKind::Tup(right_exprs)) => {
106+
iter::zip(*left_exprs, *right_exprs).all(|(left, right)| mirrored_exprs(cx, left, a_ident, right, b_ident))
107+
},
113108
// Two binary ops, which are the same operation and which have mirrored arguments
114109
(ExprKind::Binary(left_op, left_left, left_right), ExprKind::Binary(right_op, right_left, right_right)) => {
115110
left_op.node == right_op.node
@@ -146,10 +141,7 @@ fn mirrored_exprs(
146141
},
147142
)),
148143
) => {
149-
(left_segments
150-
.iter()
151-
.zip(right_segments.iter())
152-
.all(|(left, right)| left.ident == right.ident)
144+
(iter::zip(*left_segments, *right_segments).all(|(left, right)| left.ident == right.ident)
153145
&& left_segments
154146
.iter()
155147
.all(|seg| &seg.ident != a_ident && &seg.ident != b_ident))

clippy_lints/src/utils/inspector.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,6 @@ fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) {
306306
match op {
307307
hir::InlineAsmOperand::In { expr, .. }
308308
| hir::InlineAsmOperand::InOut { expr, .. }
309-
| hir::InlineAsmOperand::Const { expr }
310309
| hir::InlineAsmOperand::Sym { expr } => print_expr(cx, expr, indent + 1),
311310
hir::InlineAsmOperand::Out { expr, .. } => {
312311
if let Some(expr) = expr {
@@ -319,6 +318,10 @@ fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) {
319318
print_expr(cx, out_expr, indent + 1);
320319
}
321320
},
321+
hir::InlineAsmOperand::Const { anon_const } => {
322+
println!("{}anon_const:", ind);
323+
print_expr(cx, &cx.tcx.hir().body(anon_const.body).value, indent + 1);
324+
},
322325
}
323326
}
324327
},

clippy_utils/src/consts.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc_span::symbol::Symbol;
1515
use std::cmp::Ordering::{self, Equal};
1616
use std::convert::TryInto;
1717
use std::hash::{Hash, Hasher};
18+
use std::iter;
1819

1920
/// A `LitKind`-like enum to fold constant `Expr`s into.
2021
#[derive(Debug, Clone)]
@@ -139,9 +140,7 @@ impl Constant {
139140
(&Self::F64(l), &Self::F64(r)) => l.partial_cmp(&r),
140141
(&Self::F32(l), &Self::F32(r)) => l.partial_cmp(&r),
141142
(&Self::Bool(ref l), &Self::Bool(ref r)) => Some(l.cmp(r)),
142-
(&Self::Tuple(ref l), &Self::Tuple(ref r)) | (&Self::Vec(ref l), &Self::Vec(ref r)) => l
143-
.iter()
144-
.zip(r.iter())
143+
(&Self::Tuple(ref l), &Self::Tuple(ref r)) | (&Self::Vec(ref l), &Self::Vec(ref r)) => iter::zip(l, r)
145144
.map(|(li, ri)| Self::partial_cmp(tcx, cmp_type, li, ri))
146145
.find(|r| r.map_or(true, |o| o != Ordering::Equal))
147146
.unwrap_or_else(|| Some(l.len().cmp(&r.len()))),

clippy_utils/src/hir_utils.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,8 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
675675
self.hash_expr(out_expr);
676676
}
677677
},
678-
InlineAsmOperand::Const { expr } | InlineAsmOperand::Sym { expr } => self.hash_expr(expr),
678+
InlineAsmOperand::Const { anon_const } => self.hash_body(anon_const.body),
679+
InlineAsmOperand::Sym { expr } => self.hash_expr(expr),
679680
}
680681
}
681682
},

clippy_utils/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![feature(box_patterns)]
22
#![feature(in_band_lifetimes)]
3+
#![feature(iter_zip)]
34
#![feature(rustc_private)]
45
#![recursion_limit = "512"]
56
#![allow(clippy::missing_errors_doc, clippy::missing_panics_doc, clippy::must_use_candidate)]

clippy_utils/src/numeric_literal.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use rustc_ast::ast::{Lit, LitFloatType, LitIntType, LitKind};
2+
use std::iter;
23

34
#[derive(Debug, PartialEq, Copy, Clone)]
45
pub enum Radix {
@@ -192,7 +193,7 @@ impl<'a> NumericLiteral<'a> {
192193
}
193194
}
194195

195-
for (c, i) in digits.zip((0..group_size).cycle()) {
196+
for (c, i) in iter::zip(digits, (0..group_size).cycle()) {
196197
if i == 0 {
197198
output.push('_');
198199
}

clippy_utils/src/qualify_min_const_fn.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -210,21 +210,19 @@ fn check_statement(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: DefId, statemen
210210
StatementKind::Assign(box (place, rval)) => {
211211
check_place(tcx, *place, span, body)?;
212212
check_rvalue(tcx, body, def_id, rval, span)
213-
}
213+
},
214214

215-
StatementKind::FakeRead(_, place) |
215+
StatementKind::FakeRead(box (_, place)) => check_place(tcx, *place, span, body),
216216
// just an assignment
217217
StatementKind::SetDiscriminant { place, .. } => check_place(tcx, **place, span, body),
218218

219219
StatementKind::LlvmInlineAsm { .. } => Err((span, "cannot use inline assembly in const fn".into())),
220220

221-
StatementKind::CopyNonOverlapping(box rustc_middle::mir::CopyNonOverlapping{
222-
dst, src, count,
223-
}) => {
224-
check_operand(tcx, dst, span, body)?;
225-
check_operand(tcx, src, span, body)?;
226-
check_operand(tcx, count, span, body)
227-
}
221+
StatementKind::CopyNonOverlapping(box rustc_middle::mir::CopyNonOverlapping { dst, src, count }) => {
222+
check_operand(tcx, dst, span, body)?;
223+
check_operand(tcx, src, span, body)?;
224+
check_operand(tcx, count, span, body)
225+
},
228226
// These are all NOPs
229227
StatementKind::StorageLive(_)
230228
| StatementKind::StorageDead(_)

rust-toolchain

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2021-03-25"
2+
channel = "nightly-2021-04-08"
33
components = ["llvm-tools-preview", "rustc-dev", "rust-src"]

0 commit comments

Comments
 (0)