Skip to content

Commit

Permalink
Auto merge of rust-lang#7051 - flip1995:rustup, r=flip1995
Browse files Browse the repository at this point in the history
Rustup

changelog: none

r? `@ghost`
  • Loading branch information
bors committed Apr 8, 2021
2 parents db6ea84 + 61eafbb commit b40ea20
Show file tree
Hide file tree
Showing 24 changed files with 65 additions and 61 deletions.
5 changes: 3 additions & 2 deletions clippy_lints/src/default_numeric_fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use rustc_middle::{
ty::{self, FloatTy, IntTy, PolyFnSig, Ty},
};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use std::iter;

declare_clippy_lint! {
/// **What it does:** Checks for usage of unconstrained numeric literals which may cause default numeric fallback in type
Expand Down Expand Up @@ -107,7 +108,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
match &expr.kind {
ExprKind::Call(func, args) => {
if let Some(fn_sig) = fn_sig_opt(self.cx, func.hir_id) {
for (expr, bound) in args.iter().zip(fn_sig.skip_binder().inputs().iter()) {
for (expr, bound) in iter::zip(*args, fn_sig.skip_binder().inputs()) {
// Push found arg type, then visit arg.
self.ty_bounds.push(TyBound::Ty(bound));
self.visit_expr(expr);
Expand All @@ -120,7 +121,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
ExprKind::MethodCall(_, _, args, _) => {
if let Some(def_id) = self.cx.typeck_results().type_dependent_def_id(expr.hir_id) {
let fn_sig = self.cx.tcx.fn_sig(def_id).skip_binder();
for (expr, bound) in args.iter().zip(fn_sig.inputs().iter()) {
for (expr, bound) in iter::zip(*args, fn_sig.inputs()) {
self.ty_bounds.push(TyBound::Ty(bound));
self.visit_expr(expr);
self.ty_bounds.pop();
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/functions/must_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fn check_needless_must_use(
);
},
);
} else if !attr.is_value_str() && is_must_use_ty(cx, return_ty(cx, item_id)) {
} else if attr.value_str().is_none() && is_must_use_ty(cx, return_ty(cx, item_id)) {
span_lint_and_help(
cx,
DOUBLE_MUST_USE,
Expand Down
1 change: 1 addition & 0 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#![feature(box_syntax)]
#![feature(drain_filter)]
#![feature(in_band_lifetimes)]
#![feature(iter_zip)]
#![feature(once_cell)]
#![feature(rustc_private)]
#![feature(stmt_expr_attributes)]
Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/src/literal_representation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use rustc_errors::Applicability;
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::{declare_tool_lint, impl_lint_pass};
use std::iter;

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

let group_sizes: Vec<usize> = num_lit.integer.split('_').map(str::len).collect();
if UUID_GROUP_LENS.len() == group_sizes.len() {
UUID_GROUP_LENS.iter().zip(&group_sizes).all(|(&a, &b)| a == b)
iter::zip(&UUID_GROUP_LENS, &group_sizes).all(|(&a, &b)| a == b)
} else {
false
}
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/loops/needless_range_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use rustc_middle::hir::map::Map;
use rustc_middle::middle::region;
use rustc_middle::ty::{self, Ty};
use rustc_span::symbol::{sym, Symbol};
use std::iter::Iterator;
use std::iter::{self, Iterator};
use std::mem;

/// Checks for looping over a range and then indexing a sequence with it.
Expand Down Expand Up @@ -367,7 +367,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
},
ExprKind::MethodCall(_, _, args, _) => {
let def_id = self.cx.typeck_results().type_dependent_def_id(expr.hir_id).unwrap();
for (ty, expr) in self.cx.tcx.fn_sig(def_id).inputs().skip_binder().iter().zip(args) {
for (ty, expr) in iter::zip(self.cx.tcx.fn_sig(def_id).inputs().skip_binder(), args) {
self.prefer_mutable = false;
if let ty::Ref(_, _, mutbl) = *ty.kind() {
if mutbl == Mutability::Mut {
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/loops/never_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult {
.map(|(o, _)| match o {
InlineAsmOperand::In { expr, .. }
| InlineAsmOperand::InOut { expr, .. }
| InlineAsmOperand::Const { expr }
| InlineAsmOperand::Sym { expr } => never_loop_expr(expr, main_loop_id),
InlineAsmOperand::Out { expr, .. } => never_loop_expr_all(&mut expr.iter(), main_loop_id),
InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => {
never_loop_expr_all(&mut once(in_expr).chain(out_expr.iter()), main_loop_id)
},
InlineAsmOperand::Const { .. } => NeverLoopResult::Otherwise,
})
.fold(NeverLoopResult::Otherwise, combine_both),
ExprKind::Struct(_, _, None)
Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/src/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use rustc_span::source_map::{Span, Spanned};
use rustc_span::sym;
use std::cmp::Ordering;
use std::collections::hash_map::Entry;
use std::iter;
use std::ops::Bound;

declare_clippy_lint! {
Expand Down Expand Up @@ -1670,7 +1671,7 @@ where

values.sort();

for (a, b) in values.iter().zip(values.iter().skip(1)) {
for (a, b) in iter::zip(&values, values.iter().skip(1)) {
match (a, b) {
(&Kind::Start(_, ra), &Kind::End(_, rb)) => {
if ra.node != rb.node {
Expand Down
8 changes: 4 additions & 4 deletions clippy_lints/src/missing_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ impl MissingDoc {
return;
}

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

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

fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) {
Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/src/mut_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use rustc_middle::ty::TypeFoldable;
use rustc_middle::ty::{Adt, Array, RawPtr, Ref, Slice, Tuple, Ty, TypeAndMut};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::source_map::Span;
use std::iter;

declare_clippy_lint! {
/// **What it does:** Checks for sets/maps with mutable key types.
Expand Down Expand Up @@ -87,7 +88,7 @@ impl<'tcx> LateLintPass<'tcx> for MutableKeyType {
fn check_sig<'tcx>(cx: &LateContext<'tcx>, item_hir_id: hir::HirId, decl: &hir::FnDecl<'_>) {
let fn_def_id = cx.tcx.hir().local_def_id(item_hir_id);
let fn_sig = cx.tcx.fn_sig(fn_def_id);
for (hir_ty, ty) in decl.inputs.iter().zip(fn_sig.inputs().skip_binder().iter()) {
for (hir_ty, ty) in iter::zip(decl.inputs, fn_sig.inputs().skip_binder()) {
check_ty(cx, hir_ty.span, ty);
}
check_ty(cx, decl.output.span(), cx.tcx.erase_late_bound_regions(fn_sig.output()));
Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/src/mut_reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::subst::Subst;
use rustc_middle::ty::{self, Ty};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use std::iter;

declare_clippy_lint! {
/// **What it does:** Detects passing a mutable reference to a function that only
Expand Down Expand Up @@ -64,7 +65,7 @@ fn check_arguments<'tcx>(
match type_definition.kind() {
ty::FnDef(..) | ty::FnPtr(_) => {
let parameters = type_definition.fn_sig(cx.tcx).skip_binder().inputs();
for (argument, parameter) in arguments.iter().zip(parameters.iter()) {
for (argument, parameter) in iter::zip(arguments, parameters) {
match parameter.kind() {
ty::Ref(_, _, Mutability::Not)
| ty::RawPtr(ty::TypeAndMut {
Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/src/pass_by_ref_or_value.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::cmp;
use std::iter;

use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::is_self_ty;
Expand Down Expand Up @@ -122,7 +123,7 @@ impl<'tcx> PassByRefOrValue {

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

for (index, (input, &ty)) in decl.inputs.iter().zip(fn_sig.inputs()).enumerate() {
for (index, (input, &ty)) in iter::zip(decl.inputs, fn_sig.inputs()).enumerate() {
// All spans generated from a proc-macro invocation are the same...
match span {
Some(s) if s == input.span => return,
Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/src/pattern_type_mismatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::{AdtDef, FieldDef, Ty, TyKind, VariantDef};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::source_map::Span;
use std::iter;

declare_clippy_lint! {
/// **What it does:** Checks for patterns that aren't exact representations of the types
Expand Down Expand Up @@ -134,7 +135,7 @@ impl<'tcx> LateLintPass<'tcx> for PatternTypeMismatch {
hir_id: HirId,
) {
if let Some(fn_sig) = cx.typeck_results().liberated_fn_sigs().get(hir_id) {
for (param, ty) in body.params.iter().zip(fn_sig.inputs().iter()) {
for (param, ty) in iter::zip(body.params, fn_sig.inputs()) {
apply_lint(cx, param.pat, ty, DerefPossible::Impossible);
}
}
Expand Down
10 changes: 5 additions & 5 deletions clippy_lints/src/unit_return_expecting_ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn get_trait_predicates_for_trait_id<'tcx>(
for (pred, _) in generics.predicates {
if_chain! {
if let PredicateKind::Trait(poly_trait_pred, _) = pred.kind().skip_binder();
let trait_pred = cx.tcx.erase_late_bound_regions(ty::Binder::bind(poly_trait_pred));
let trait_pred = cx.tcx.erase_late_bound_regions(pred.kind().rebind(poly_trait_pred));
if let Some(trait_def_id) = trait_id;
if trait_def_id == trait_pred.trait_ref.def_id;
then {
Expand All @@ -58,12 +58,12 @@ fn get_trait_predicates_for_trait_id<'tcx>(
fn get_projection_pred<'tcx>(
cx: &LateContext<'tcx>,
generics: GenericPredicates<'tcx>,
pred: TraitPredicate<'tcx>,
trait_pred: TraitPredicate<'tcx>,
) -> Option<ProjectionPredicate<'tcx>> {
generics.predicates.iter().find_map(|(proj_pred, _)| {
if let ty::PredicateKind::Projection(proj_pred) = proj_pred.kind().skip_binder() {
let projection_pred = cx.tcx.erase_late_bound_regions(ty::Binder::bind(proj_pred));
if projection_pred.projection_ty.substs == pred.trait_ref.substs {
if let ty::PredicateKind::Projection(pred) = proj_pred.kind().skip_binder() {
let projection_pred = cx.tcx.erase_late_bound_regions(proj_pred.kind().rebind(pred));
if projection_pred.projection_ty.substs == trait_pred.trait_ref.substs {
return Some(projection_pred);
}
}
Expand Down
28 changes: 10 additions & 18 deletions clippy_lints/src/unnecessary_sort_by.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use rustc_middle::ty::{self, subst::GenericArgKind};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::sym;
use rustc_span::symbol::Ident;
use std::iter;

declare_clippy_lint! {
/// **What it does:**
Expand Down Expand Up @@ -79,17 +80,14 @@ fn mirrored_exprs(
mirrored_exprs(cx, left_expr, a_ident, right_expr, b_ident)
},
// Two arrays with mirrored contents
(ExprKind::Array(left_exprs), ExprKind::Array(right_exprs)) => left_exprs
.iter()
.zip(right_exprs.iter())
.all(|(left, right)| mirrored_exprs(cx, left, a_ident, right, b_ident)),
(ExprKind::Array(left_exprs), ExprKind::Array(right_exprs)) => {
iter::zip(*left_exprs, *right_exprs).all(|(left, right)| mirrored_exprs(cx, left, a_ident, right, b_ident))
},
// The two exprs are function calls.
// Check to see that the function itself and its arguments are mirrored
(ExprKind::Call(left_expr, left_args), ExprKind::Call(right_expr, right_args)) => {
mirrored_exprs(cx, left_expr, a_ident, right_expr, b_ident)
&& left_args
.iter()
.zip(right_args.iter())
&& iter::zip(*left_args, *right_args)
.all(|(left, right)| mirrored_exprs(cx, left, a_ident, right, b_ident))
},
// The two exprs are method calls.
Expand All @@ -100,16 +98,13 @@ fn mirrored_exprs(
ExprKind::MethodCall(right_segment, _, right_args, _),
) => {
left_segment.ident == right_segment.ident
&& left_args
.iter()
.zip(right_args.iter())
&& iter::zip(*left_args, *right_args)
.all(|(left, right)| mirrored_exprs(cx, left, a_ident, right, b_ident))
},
// Two tuples with mirrored contents
(ExprKind::Tup(left_exprs), ExprKind::Tup(right_exprs)) => left_exprs
.iter()
.zip(right_exprs.iter())
.all(|(left, right)| mirrored_exprs(cx, left, a_ident, right, b_ident)),
(ExprKind::Tup(left_exprs), ExprKind::Tup(right_exprs)) => {
iter::zip(*left_exprs, *right_exprs).all(|(left, right)| mirrored_exprs(cx, left, a_ident, right, b_ident))
},
// Two binary ops, which are the same operation and which have mirrored arguments
(ExprKind::Binary(left_op, left_left, left_right), ExprKind::Binary(right_op, right_left, right_right)) => {
left_op.node == right_op.node
Expand Down Expand Up @@ -146,10 +141,7 @@ fn mirrored_exprs(
},
)),
) => {
(left_segments
.iter()
.zip(right_segments.iter())
.all(|(left, right)| left.ident == right.ident)
(iter::zip(*left_segments, *right_segments).all(|(left, right)| left.ident == right.ident)
&& left_segments
.iter()
.all(|seg| &seg.ident != a_ident && &seg.ident != b_ident))
Expand Down
5 changes: 4 additions & 1 deletion clippy_lints/src/utils/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) {
match op {
hir::InlineAsmOperand::In { expr, .. }
| hir::InlineAsmOperand::InOut { expr, .. }
| hir::InlineAsmOperand::Const { expr }
| hir::InlineAsmOperand::Sym { expr } => print_expr(cx, expr, indent + 1),
hir::InlineAsmOperand::Out { expr, .. } => {
if let Some(expr) = expr {
Expand All @@ -319,6 +318,10 @@ fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) {
print_expr(cx, out_expr, indent + 1);
}
},
hir::InlineAsmOperand::Const { anon_const } => {
println!("{}anon_const:", ind);
print_expr(cx, &cx.tcx.hir().body(anon_const.body).value, indent + 1);
},
}
}
},
Expand Down
5 changes: 2 additions & 3 deletions clippy_utils/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use rustc_span::symbol::Symbol;
use std::cmp::Ordering::{self, Equal};
use std::convert::TryInto;
use std::hash::{Hash, Hasher};
use std::iter;

/// A `LitKind`-like enum to fold constant `Expr`s into.
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -139,9 +140,7 @@ impl Constant {
(&Self::F64(l), &Self::F64(r)) => l.partial_cmp(&r),
(&Self::F32(l), &Self::F32(r)) => l.partial_cmp(&r),
(&Self::Bool(ref l), &Self::Bool(ref r)) => Some(l.cmp(r)),
(&Self::Tuple(ref l), &Self::Tuple(ref r)) | (&Self::Vec(ref l), &Self::Vec(ref r)) => l
.iter()
.zip(r.iter())
(&Self::Tuple(ref l), &Self::Tuple(ref r)) | (&Self::Vec(ref l), &Self::Vec(ref r)) => iter::zip(l, r)
.map(|(li, ri)| Self::partial_cmp(tcx, cmp_type, li, ri))
.find(|r| r.map_or(true, |o| o != Ordering::Equal))
.unwrap_or_else(|| Some(l.len().cmp(&r.len()))),
Expand Down
3 changes: 2 additions & 1 deletion clippy_utils/src/hir_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,8 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
self.hash_expr(out_expr);
}
},
InlineAsmOperand::Const { expr } | InlineAsmOperand::Sym { expr } => self.hash_expr(expr),
InlineAsmOperand::Const { anon_const } => self.hash_body(anon_const.body),
InlineAsmOperand::Sym { expr } => self.hash_expr(expr),
}
}
},
Expand Down
1 change: 1 addition & 0 deletions clippy_utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![feature(box_patterns)]
#![feature(in_band_lifetimes)]
#![feature(iter_zip)]
#![feature(rustc_private)]
#![recursion_limit = "512"]
#![allow(clippy::missing_errors_doc, clippy::missing_panics_doc, clippy::must_use_candidate)]
Expand Down
3 changes: 2 additions & 1 deletion clippy_utils/src/numeric_literal.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use rustc_ast::ast::{Lit, LitFloatType, LitIntType, LitKind};
use std::iter;

#[derive(Debug, PartialEq, Copy, Clone)]
pub enum Radix {
Expand Down Expand Up @@ -192,7 +193,7 @@ impl<'a> NumericLiteral<'a> {
}
}

for (c, i) in digits.zip((0..group_size).cycle()) {
for (c, i) in iter::zip(digits, (0..group_size).cycle()) {
if i == 0 {
output.push('_');
}
Expand Down
16 changes: 7 additions & 9 deletions clippy_utils/src/qualify_min_const_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,21 +210,19 @@ fn check_statement(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: DefId, statemen
StatementKind::Assign(box (place, rval)) => {
check_place(tcx, *place, span, body)?;
check_rvalue(tcx, body, def_id, rval, span)
}
},

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

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

StatementKind::CopyNonOverlapping(box rustc_middle::mir::CopyNonOverlapping{
dst, src, count,
}) => {
check_operand(tcx, dst, span, body)?;
check_operand(tcx, src, span, body)?;
check_operand(tcx, count, span, body)
}
StatementKind::CopyNonOverlapping(box rustc_middle::mir::CopyNonOverlapping { dst, src, count }) => {
check_operand(tcx, dst, span, body)?;
check_operand(tcx, src, span, body)?;
check_operand(tcx, count, span, body)
},
// These are all NOPs
StatementKind::StorageLive(_)
| StatementKind::StorageDead(_)
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2021-03-25"
channel = "nightly-2021-04-08"
components = ["llvm-tools-preview", "rustc-dev", "rust-src"]
Loading

0 comments on commit b40ea20

Please sign in to comment.