Skip to content

Commit 7531a08

Browse files
committed
Auto merge of #4788 - Manishearth:rustup, r=flip1995
Rustup to rustc 1.40.0-nightly (50f8aad 2019-11-07) changelog: Deprecate [`into_iter_on_array`] lint r? @phansch @oli-obk
2 parents 43a3796 + 08fd397 commit 7531a08

27 files changed

+124
-166
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
88

9-
[There are 332 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
9+
[There are 331 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
1010

1111
We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you:
1212

clippy_lints/src/approx_const.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc::hir::*;
33
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
44
use rustc::{declare_lint_pass, declare_tool_lint};
55
use std::f64::consts as f64;
6-
use syntax::ast::{FloatTy, LitKind};
6+
use syntax::ast::{FloatTy, LitFloatType, LitKind};
77
use syntax::symbol;
88

99
declare_clippy_lint! {
@@ -62,9 +62,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ApproxConstant {
6262

6363
fn check_lit(cx: &LateContext<'_, '_>, lit: &LitKind, e: &Expr) {
6464
match *lit {
65-
LitKind::Float(s, FloatTy::F32) => check_known_consts(cx, e, s, "f32"),
66-
LitKind::Float(s, FloatTy::F64) => check_known_consts(cx, e, s, "f64"),
67-
LitKind::FloatUnsuffixed(s) => check_known_consts(cx, e, s, "f{32, 64}"),
65+
LitKind::Float(s, LitFloatType::Suffixed(fty)) => match fty {
66+
FloatTy::F32 => check_known_consts(cx, e, s, "f32"),
67+
FloatTy::F64 => check_known_consts(cx, e, s, "f64"),
68+
},
69+
LitKind::Float(s, LitFloatType::Unsuffixed) => check_known_consts(cx, e, s, "f{32, 64}"),
6870
_ => (),
6971
}
7072
}

clippy_lints/src/attrs.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc::ty;
1515
use rustc::{declare_lint_pass, declare_tool_lint};
1616
use rustc_errors::Applicability;
1717
use semver::Version;
18-
use syntax::ast::{AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
18+
use syntax::ast::{AttrKind, AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
1919
use syntax::source_map::Span;
2020
use syntax_pos::symbol::Symbol;
2121

@@ -417,11 +417,14 @@ fn check_attrs(cx: &LateContext<'_, '_>, span: Span, name: Name, attrs: &[Attrib
417417
}
418418

419419
for attr in attrs {
420-
if attr.is_sugared_doc {
421-
return;
422-
}
420+
let attr_item = if let AttrKind::Normal(ref attr) = attr.kind {
421+
attr
422+
} else {
423+
continue;
424+
};
425+
423426
if attr.style == AttrStyle::Outer {
424-
if attr.tokens.is_empty() || !is_present_in_source(cx, attr.span) {
427+
if attr_item.tokens.is_empty() || !is_present_in_source(cx, attr.span) {
425428
return;
426429
}
427430

clippy_lints/src/consts.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,11 @@ pub fn lit_to_constant(lit: &LitKind, ty: Option<Ty<'_>>) -> Constant {
161161
LitKind::ByteStr(ref s) => Constant::Binary(Lrc::clone(s)),
162162
LitKind::Char(c) => Constant::Char(c),
163163
LitKind::Int(n, _) => Constant::Int(n),
164-
LitKind::Float(ref is, FloatTy::F32) => Constant::F32(is.as_str().parse().unwrap()),
165-
LitKind::Float(ref is, FloatTy::F64) => Constant::F64(is.as_str().parse().unwrap()),
166-
LitKind::FloatUnsuffixed(ref is) => match ty.expect("type of float is known").kind {
164+
LitKind::Float(ref is, LitFloatType::Suffixed(fty)) => match fty {
165+
FloatTy::F32 => Constant::F32(is.as_str().parse().unwrap()),
166+
FloatTy::F64 => Constant::F64(is.as_str().parse().unwrap()),
167+
},
168+
LitKind::Float(ref is, LitFloatType::Unsuffixed) => match ty.expect("type of float is known").kind {
167169
ty::Float(FloatTy::F32) => Constant::F32(is.as_str().parse().unwrap()),
168170
ty::Float(FloatTy::F64) => Constant::F64(is.as_str().parse().unwrap()),
169171
_ => bug!(),

clippy_lints/src/deprecated_lints.rs

+9
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,12 @@ declare_deprecated_lint! {
130130
pub UNUSED_COLLECT,
131131
"`collect` has been marked as #[must_use] in rustc and that covers all cases of this lint"
132132
}
133+
134+
declare_deprecated_lint! {
135+
/// **What it does:** Nothing. This lint has been deprecated.
136+
///
137+
/// **Deprecation reason:** This lint has been uplifted to rustc and is now called
138+
/// `array_into_iter`.
139+
pub INTO_ITER_ON_ARRAY,
140+
"this lint has been uplifted to rustc and is now called `array_into_iter`"
141+
}

clippy_lints/src/doc.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
66
use rustc::{declare_tool_lint, impl_lint_pass};
77
use rustc_data_structures::fx::FxHashSet;
88
use std::ops::Range;
9-
use syntax::ast::Attribute;
9+
use syntax::ast::{AttrKind, Attribute};
1010
use syntax::source_map::{BytePos, Span};
1111
use syntax_pos::Pos;
1212
use url::Url;
@@ -247,13 +247,11 @@ pub fn check_attrs<'a>(cx: &LateContext<'_, '_>, valid_idents: &FxHashSet<String
247247
let mut spans = vec![];
248248

249249
for attr in attrs {
250-
if attr.is_sugared_doc {
251-
if let Some(ref current) = attr.value_str() {
252-
let current = current.to_string();
253-
let (current, current_spans) = strip_doc_comment_decoration(&current, attr.span);
254-
spans.extend_from_slice(&current_spans);
255-
doc.push_str(&current);
256-
}
250+
if let AttrKind::DocComment(ref comment) = attr.kind {
251+
let comment = comment.to_string();
252+
let (comment, current_spans) = strip_doc_comment_decoration(&comment, attr.span);
253+
spans.extend_from_slice(&current_spans);
254+
doc.push_str(&comment);
257255
} else if attr.check_name(sym!(doc)) {
258256
// ignore mix of sugared and non-sugared doc
259257
return true; // don't trigger the safety check

clippy_lints/src/excessive_precision.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExcessivePrecision {
4343
let ty = cx.tables.expr_ty(expr);
4444
if let ty::Float(fty) = ty.kind;
4545
if let hir::ExprKind::Lit(ref lit) = expr.kind;
46-
if let LitKind::Float(sym, _) | LitKind::FloatUnsuffixed(sym) = lit.node;
46+
if let LitKind::Float(sym, _) = lit.node;
4747
if let Some(sugg) = Self::check(sym, fty);
4848
then {
4949
span_lint_and_sugg(

clippy_lints/src/lib.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,10 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf
430430
"clippy::unused_collect",
431431
"`collect` has been marked as #[must_use] in rustc and that covers all cases of this lint",
432432
);
433+
store.register_removed(
434+
"clippy::into_iter_on_array",
435+
"this lint has been uplifted to rustc and is now called `array_into_iter`",
436+
);
433437
// end deprecated lints, do not remove this comment, it’s used in `update_lints`
434438

435439
// begin register lints, do not remove this comment, it’s used in `update_lints`
@@ -584,7 +588,6 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf
584588
&methods::FLAT_MAP_IDENTITY,
585589
&methods::GET_UNWRAP,
586590
&methods::INEFFICIENT_TO_STRING,
587-
&methods::INTO_ITER_ON_ARRAY,
588591
&methods::INTO_ITER_ON_REF,
589592
&methods::ITER_CLONED_COLLECT,
590593
&methods::ITER_NTH,
@@ -1142,7 +1145,6 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf
11421145
LintId::of(&methods::FILTER_NEXT),
11431146
LintId::of(&methods::FLAT_MAP_IDENTITY),
11441147
LintId::of(&methods::INEFFICIENT_TO_STRING),
1145-
LintId::of(&methods::INTO_ITER_ON_ARRAY),
11461148
LintId::of(&methods::INTO_ITER_ON_REF),
11471149
LintId::of(&methods::ITER_CLONED_COLLECT),
11481150
LintId::of(&methods::ITER_NTH),
@@ -1481,7 +1483,6 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf
14811483
LintId::of(&mem_discriminant::MEM_DISCRIMINANT_NON_ENUM),
14821484
LintId::of(&mem_replace::MEM_REPLACE_WITH_UNINIT),
14831485
LintId::of(&methods::CLONE_DOUBLE_REF),
1484-
LintId::of(&methods::INTO_ITER_ON_ARRAY),
14851486
LintId::of(&methods::TEMPORARY_CSTRING_AS_PTR),
14861487
LintId::of(&methods::UNINIT_ASSUMED_INIT),
14871488
LintId::of(&minmax::MIN_MAX),

clippy_lints/src/literal_representation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ impl LiteralDigitGrouping {
373373
}
374374
}
375375
},
376-
LitKind::Float(..) | LitKind::FloatUnsuffixed(..) => {
376+
LitKind::Float(..) => {
377377
// Lint floating-point literals.
378378
if_chain! {
379379
if let Some(src) = snippet_opt(cx, lit.span);

clippy_lints/src/main_recursion.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use rustc::hir::{Crate, Expr, ExprKind, QPath};
22
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
33
use rustc::{declare_tool_lint, impl_lint_pass};
4+
use syntax::ast::AttrKind;
45
use syntax::symbol::sym;
56

67
use crate::utils::{is_entrypoint_fn, snippet, span_help_and_lint};
@@ -34,7 +35,13 @@ impl_lint_pass!(MainRecursion => [MAIN_RECURSION]);
3435

3536
impl LateLintPass<'_, '_> for MainRecursion {
3637
fn check_crate(&mut self, _: &LateContext<'_, '_>, krate: &Crate) {
37-
self.has_no_std_attr = krate.attrs.iter().any(|attr| attr.path == sym::no_std);
38+
self.has_no_std_attr = krate.attrs.iter().any(|attr| {
39+
if let AttrKind::Normal(ref attr) = attr.kind {
40+
attr.path == sym::no_std
41+
} else {
42+
false
43+
}
44+
});
3845
}
3946

4047
fn check_expr_post(&mut self, cx: &LateContext<'_, '_>, expr: &Expr) {

clippy_lints/src/methods/mod.rs

+4-41
Original file line numberDiff line numberDiff line change
@@ -968,34 +968,6 @@ declare_clippy_lint! {
968968
"using `filter_map` when a more succinct alternative exists"
969969
}
970970

971-
declare_clippy_lint! {
972-
/// **What it does:** Checks for `into_iter` calls on types which should be replaced by `iter` or
973-
/// `iter_mut`.
974-
///
975-
/// **Why is this bad?** Arrays and `PathBuf` do not yet have an `into_iter` method which move out
976-
/// their content into an iterator. Auto-referencing resolves the `into_iter` call to its reference
977-
/// instead, like `<&[T; N] as IntoIterator>::into_iter`, which just iterates over item references
978-
/// like calling `iter` would. Furthermore, when the standard library actually
979-
/// [implements the `into_iter` method](https://github.com/rust-lang/rust/issues/25725) which moves
980-
/// the content out of the array, the original use of `into_iter` got inferred with the wrong type
981-
/// and the code will be broken.
982-
///
983-
/// **Known problems:** None
984-
///
985-
/// **Example:**
986-
///
987-
/// ```rust
988-
/// let _ = [1, 2, 3].into_iter().map(|x| *x).collect::<Vec<u32>>();
989-
/// ```
990-
/// Could be written as:
991-
/// ```rust
992-
/// let _ = [1, 2, 3].iter().map(|x| *x).collect::<Vec<u32>>();
993-
/// ```
994-
pub INTO_ITER_ON_ARRAY,
995-
correctness,
996-
"using `.into_iter()` on an array"
997-
}
998-
999971
declare_clippy_lint! {
1000972
/// **What it does:** Checks for `into_iter` calls on references which should be replaced by `iter`
1001973
/// or `iter_mut`.
@@ -1133,7 +1105,6 @@ declare_lint_pass!(Methods => [
11331105
USELESS_ASREF,
11341106
UNNECESSARY_FOLD,
11351107
UNNECESSARY_FILTER_MAP,
1136-
INTO_ITER_ON_ARRAY,
11371108
INTO_ITER_ON_REF,
11381109
SUSPICIOUS_MAP,
11391110
UNINIT_ASSUMED_INIT,
@@ -2786,16 +2757,8 @@ fn lint_asref(cx: &LateContext<'_, '_>, expr: &hir::Expr, call_name: &str, as_re
27862757
}
27872758
}
27882759

2789-
fn ty_has_iter_method(
2790-
cx: &LateContext<'_, '_>,
2791-
self_ref_ty: Ty<'_>,
2792-
) -> Option<(&'static Lint, &'static str, &'static str)> {
2760+
fn ty_has_iter_method(cx: &LateContext<'_, '_>, self_ref_ty: Ty<'_>) -> Option<(&'static str, &'static str)> {
27932761
has_iter_method(cx, self_ref_ty).map(|ty_name| {
2794-
let lint = if ty_name == "array" || ty_name == "PathBuf" {
2795-
INTO_ITER_ON_ARRAY
2796-
} else {
2797-
INTO_ITER_ON_REF
2798-
};
27992762
let mutbl = match self_ref_ty.kind {
28002763
ty::Ref(_, _, mutbl) => mutbl,
28012764
_ => unreachable!(),
@@ -2804,18 +2767,18 @@ fn ty_has_iter_method(
28042767
hir::MutImmutable => "iter",
28052768
hir::MutMutable => "iter_mut",
28062769
};
2807-
(lint, ty_name, method_name)
2770+
(ty_name, method_name)
28082771
})
28092772
}
28102773

28112774
fn lint_into_iter(cx: &LateContext<'_, '_>, expr: &hir::Expr, self_ref_ty: Ty<'_>, method_span: Span) {
28122775
if !match_trait_method(cx, expr, &paths::INTO_ITERATOR) {
28132776
return;
28142777
}
2815-
if let Some((lint, kind, method_name)) = ty_has_iter_method(cx, self_ref_ty) {
2778+
if let Some((kind, method_name)) = ty_has_iter_method(cx, self_ref_ty) {
28162779
span_lint_and_sugg(
28172780
cx,
2818-
lint,
2781+
INTO_ITER_ON_REF,
28192782
method_span,
28202783
&format!(
28212784
"this .into_iter() call is equivalent to .{}() and will not move the {}",

clippy_lints/src/misc_early.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,8 @@ impl MiscEarlyLints {
482482

483483
if let LitKind::Int(value, lit_int_type) = lit.kind {
484484
let suffix = match lit_int_type {
485-
LitIntType::Signed(ty) => ty.ty_to_string(),
486-
LitIntType::Unsigned(ty) => ty.ty_to_string(),
485+
LitIntType::Signed(ty) => ty.name_str(),
486+
LitIntType::Unsigned(ty) => ty.name_str(),
487487
LitIntType::Unsuffixed => "",
488488
};
489489

@@ -543,8 +543,8 @@ impl MiscEarlyLints {
543543
},
544544
);
545545
}
546-
} else if let LitKind::Float(_, float_ty) = lit.kind {
547-
let suffix = float_ty.ty_to_string();
546+
} else if let LitKind::Float(_, LitFloatType::Suffixed(float_ty)) = lit.kind {
547+
let suffix = float_ty.name_str();
548548
let maybe_last_sep_idx = lit_snip.len() - suffix.len() - 1;
549549
if lit_snip.as_bytes()[maybe_last_sep_idx] != b'_' {
550550
span_lint_and_sugg(

clippy_lints/src/precedence.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl EarlyLintPass for Precedence {
9090
if let Some(slf) = args.first() {
9191
if let ExprKind::Lit(ref lit) = slf.kind {
9292
match lit.kind {
93-
LitKind::Int(..) | LitKind::Float(..) | LitKind::FloatUnsuffixed(..) => {
93+
LitKind::Int(..) | LitKind::Float(..) => {
9494
let mut applicability = Applicability::MachineApplicable;
9595
span_lint_and_sugg(
9696
cx,

clippy_lints/src/transmute.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
390390
|db| {
391391
let arg = sugg::Sugg::hir(cx, &args[0], "..");
392392
let arg = if let ty::Int(_) = from_ty.kind {
393-
arg.as_ty(ast::UintTy::U32)
393+
arg.as_ty(ast::UintTy::U32.name_str())
394394
} else {
395395
arg
396396
};

clippy_lints/src/types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc::{declare_lint_pass, declare_tool_lint, impl_lint_pass};
1515
use rustc_errors::Applicability;
1616
use rustc_target::spec::abi::Abi;
1717
use rustc_typeck::hir_ty_to_ty;
18-
use syntax::ast::{FloatTy, IntTy, LitIntType, LitKind, UintTy};
18+
use syntax::ast::{FloatTy, IntTy, LitFloatType, LitIntType, LitKind, UintTy};
1919
use syntax::errors::DiagnosticBuilder;
2020
use syntax::source_map::Span;
2121
use syntax::symbol::{sym, Symbol};
@@ -1186,7 +1186,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Casts {
11861186
}
11871187
}
11881188
match lit.node {
1189-
LitKind::Int(_, LitIntType::Unsuffixed) | LitKind::FloatUnsuffixed(_) => {},
1189+
LitKind::Int(_, LitIntType::Unsuffixed) | LitKind::Float(_, LitFloatType::Unsuffixed) => {},
11901190
_ => {
11911191
if cast_from.kind == cast_to.kind && !in_external_macro(cx.sess(), expr.span) {
11921192
span_lint(

clippy_lints/src/utils/attrs.rs

+5
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ pub fn get_attr<'a>(
5757
name: &'static str,
5858
) -> impl Iterator<Item = &'a ast::Attribute> {
5959
attrs.iter().filter(move |attr| {
60+
let attr = if let ast::AttrKind::Normal(ref attr) = attr.kind {
61+
attr
62+
} else {
63+
return false;
64+
};
6065
let attr_segments = &attr.path.segments;
6166
if attr_segments.len() == 2 && attr_segments[0].ident.to_string() == "clippy" {
6267
if let Some(deprecation_status) =

clippy_lints/src/utils/author.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintContext, LintPass};
99
use rustc::session::Session;
1010
use rustc::{declare_lint_pass, declare_tool_lint};
1111
use rustc_data_structures::fx::FxHashMap;
12-
use syntax::ast::{Attribute, LitKind};
12+
use syntax::ast::{Attribute, LitFloatType, LitKind};
1313

1414
declare_clippy_lint! {
1515
/// **What it does:** Generates clippy code that detects the offending pattern
@@ -288,10 +288,14 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
288288
LitKind::Byte(b) => println!(" if let LitKind::Byte({}) = {}.node;", b, lit_pat),
289289
// FIXME: also check int type
290290
LitKind::Int(i, _) => println!(" if let LitKind::Int({}, _) = {}.node;", i, lit_pat),
291-
LitKind::Float(..) => println!(" if let LitKind::Float(..) = {}.node;", lit_pat),
292-
LitKind::FloatUnsuffixed(_) => {
293-
println!(" if let LitKind::FloatUnsuffixed(_) = {}.node;", lit_pat)
294-
},
291+
LitKind::Float(_, LitFloatType::Suffixed(_)) => println!(
292+
" if let LitKind::Float(_, LitFloatType::Suffixed(_)) = {}.node;",
293+
lit_pat
294+
),
295+
LitKind::Float(_, LitFloatType::Unsuffixed) => println!(
296+
" if let LitKind::Float(_, LitFloatType::Unsuffixed) = {}.node;",
297+
lit_pat
298+
),
295299
LitKind::ByteStr(ref vec) => {
296300
let vec_pat = self.next("vec");
297301
println!(" if let LitKind::ByteStr(ref {}) = {}.node;", vec_pat, lit_pat);

src/lintlist/mod.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub use lint::Lint;
66
pub use lint::LINT_LEVELS;
77

88
// begin lint list, do not remove this comment, it’s used in `update_lints`
9-
pub const ALL_LINTS: [Lint; 332] = [
9+
pub const ALL_LINTS: [Lint; 331] = [
1010
Lint {
1111
name: "absurd_extreme_comparisons",
1212
group: "correctness",
@@ -812,13 +812,6 @@ pub const ALL_LINTS: [Lint; 332] = [
812812
deprecation: None,
813813
module: "integer_division",
814814
},
815-
Lint {
816-
name: "into_iter_on_array",
817-
group: "correctness",
818-
desc: "using `.into_iter()` on an array",
819-
deprecation: None,
820-
module: "methods",
821-
},
822815
Lint {
823816
name: "into_iter_on_ref",
824817
group: "style",

0 commit comments

Comments
 (0)