Skip to content

Rustup to rustc 1.40.0-nightly (50f8aadd 2019-11-07) #4788

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

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

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

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

Expand Down
10 changes: 6 additions & 4 deletions clippy_lints/src/approx_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint_pass, declare_tool_lint};
use std::f64::consts as f64;
use syntax::ast::{FloatTy, LitKind};
use syntax::ast::{FloatTy, LitFloatType, LitKind};
use syntax::symbol;

declare_clippy_lint! {
Expand Down Expand Up @@ -62,9 +62,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ApproxConstant {

fn check_lit(cx: &LateContext<'_, '_>, lit: &LitKind, e: &Expr) {
match *lit {
LitKind::Float(s, FloatTy::F32) => check_known_consts(cx, e, s, "f32"),
LitKind::Float(s, FloatTy::F64) => check_known_consts(cx, e, s, "f64"),
LitKind::FloatUnsuffixed(s) => check_known_consts(cx, e, s, "f{32, 64}"),
LitKind::Float(s, LitFloatType::Suffixed(fty)) => match fty {
FloatTy::F32 => check_known_consts(cx, e, s, "f32"),
FloatTy::F64 => check_known_consts(cx, e, s, "f64"),
},
LitKind::Float(s, LitFloatType::Unsuffixed) => check_known_consts(cx, e, s, "f{32, 64}"),
_ => (),
}
}
Expand Down
13 changes: 8 additions & 5 deletions clippy_lints/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use rustc::ty;
use rustc::{declare_lint_pass, declare_tool_lint};
use rustc_errors::Applicability;
use semver::Version;
use syntax::ast::{AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
use syntax::ast::{AttrKind, AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
use syntax::source_map::Span;
use syntax_pos::symbol::Symbol;

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

for attr in attrs {
if attr.is_sugared_doc {
return;
}
let attr_item = if let AttrKind::Normal(ref attr) = attr.kind {
attr
} else {
continue;
};

if attr.style == AttrStyle::Outer {
if attr.tokens.is_empty() || !is_present_in_source(cx, attr.span) {
if attr_item.tokens.is_empty() || !is_present_in_source(cx, attr.span) {
return;
}

Expand Down
8 changes: 5 additions & 3 deletions clippy_lints/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,11 @@ pub fn lit_to_constant(lit: &LitKind, ty: Option<Ty<'_>>) -> Constant {
LitKind::ByteStr(ref s) => Constant::Binary(Lrc::clone(s)),
LitKind::Char(c) => Constant::Char(c),
LitKind::Int(n, _) => Constant::Int(n),
LitKind::Float(ref is, FloatTy::F32) => Constant::F32(is.as_str().parse().unwrap()),
LitKind::Float(ref is, FloatTy::F64) => Constant::F64(is.as_str().parse().unwrap()),
LitKind::FloatUnsuffixed(ref is) => match ty.expect("type of float is known").kind {
LitKind::Float(ref is, LitFloatType::Suffixed(fty)) => match fty {
FloatTy::F32 => Constant::F32(is.as_str().parse().unwrap()),
FloatTy::F64 => Constant::F64(is.as_str().parse().unwrap()),
},
LitKind::Float(ref is, LitFloatType::Unsuffixed) => match ty.expect("type of float is known").kind {
ty::Float(FloatTy::F32) => Constant::F32(is.as_str().parse().unwrap()),
ty::Float(FloatTy::F64) => Constant::F64(is.as_str().parse().unwrap()),
_ => bug!(),
Expand Down
9 changes: 9 additions & 0 deletions clippy_lints/src/deprecated_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,12 @@ declare_deprecated_lint! {
pub UNUSED_COLLECT,
"`collect` has been marked as #[must_use] in rustc and that covers all cases of this lint"
}

declare_deprecated_lint! {
/// **What it does:** Nothing. This lint has been deprecated.
///
/// **Deprecation reason:** This lint has been uplifted to rustc and is now called
/// `array_into_iter`.
pub INTO_ITER_ON_ARRAY,
"this lint has been uplifted to rustc and is now called `array_into_iter`"
}
14 changes: 6 additions & 8 deletions clippy_lints/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, impl_lint_pass};
use rustc_data_structures::fx::FxHashSet;
use std::ops::Range;
use syntax::ast::Attribute;
use syntax::ast::{AttrKind, Attribute};
use syntax::source_map::{BytePos, Span};
use syntax_pos::Pos;
use url::Url;
Expand Down Expand Up @@ -247,13 +247,11 @@ pub fn check_attrs<'a>(cx: &LateContext<'_, '_>, valid_idents: &FxHashSet<String
let mut spans = vec![];

for attr in attrs {
if attr.is_sugared_doc {
if let Some(ref current) = attr.value_str() {
let current = current.to_string();
let (current, current_spans) = strip_doc_comment_decoration(&current, attr.span);
spans.extend_from_slice(&current_spans);
doc.push_str(&current);
}
if let AttrKind::DocComment(ref comment) = attr.kind {
let comment = comment.to_string();
let (comment, current_spans) = strip_doc_comment_decoration(&comment, attr.span);
spans.extend_from_slice(&current_spans);
doc.push_str(&comment);
} else if attr.check_name(sym!(doc)) {
// ignore mix of sugared and non-sugared doc
return true; // don't trigger the safety check
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/excessive_precision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExcessivePrecision {
let ty = cx.tables.expr_ty(expr);
if let ty::Float(fty) = ty.kind;
if let hir::ExprKind::Lit(ref lit) = expr.kind;
if let LitKind::Float(sym, _) | LitKind::FloatUnsuffixed(sym) = lit.node;
if let LitKind::Float(sym, _) = lit.node;
if let Some(sugg) = Self::check(sym, fty);
then {
span_lint_and_sugg(
Expand Down
7 changes: 4 additions & 3 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,10 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf
"clippy::unused_collect",
"`collect` has been marked as #[must_use] in rustc and that covers all cases of this lint",
);
store.register_removed(
"clippy::into_iter_on_array",
"this lint has been uplifted to rustc and is now called `array_into_iter`",
);
// end deprecated lints, do not remove this comment, it’s used in `update_lints`

// begin register lints, do not remove this comment, it’s used in `update_lints`
Expand Down Expand Up @@ -584,7 +588,6 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf
&methods::FLAT_MAP_IDENTITY,
&methods::GET_UNWRAP,
&methods::INEFFICIENT_TO_STRING,
&methods::INTO_ITER_ON_ARRAY,
&methods::INTO_ITER_ON_REF,
&methods::ITER_CLONED_COLLECT,
&methods::ITER_NTH,
Expand Down Expand Up @@ -1142,7 +1145,6 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf
LintId::of(&methods::FILTER_NEXT),
LintId::of(&methods::FLAT_MAP_IDENTITY),
LintId::of(&methods::INEFFICIENT_TO_STRING),
LintId::of(&methods::INTO_ITER_ON_ARRAY),
LintId::of(&methods::INTO_ITER_ON_REF),
LintId::of(&methods::ITER_CLONED_COLLECT),
LintId::of(&methods::ITER_NTH),
Expand Down Expand Up @@ -1481,7 +1483,6 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf
LintId::of(&mem_discriminant::MEM_DISCRIMINANT_NON_ENUM),
LintId::of(&mem_replace::MEM_REPLACE_WITH_UNINIT),
LintId::of(&methods::CLONE_DOUBLE_REF),
LintId::of(&methods::INTO_ITER_ON_ARRAY),
LintId::of(&methods::TEMPORARY_CSTRING_AS_PTR),
LintId::of(&methods::UNINIT_ASSUMED_INIT),
LintId::of(&minmax::MIN_MAX),
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/literal_representation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ impl LiteralDigitGrouping {
}
}
},
LitKind::Float(..) | LitKind::FloatUnsuffixed(..) => {
LitKind::Float(..) => {
// Lint floating-point literals.
if_chain! {
if let Some(src) = snippet_opt(cx, lit.span);
Expand Down
9 changes: 8 additions & 1 deletion clippy_lints/src/main_recursion.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use rustc::hir::{Crate, Expr, ExprKind, QPath};
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, impl_lint_pass};
use syntax::ast::AttrKind;
use syntax::symbol::sym;

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

impl LateLintPass<'_, '_> for MainRecursion {
fn check_crate(&mut self, _: &LateContext<'_, '_>, krate: &Crate) {
self.has_no_std_attr = krate.attrs.iter().any(|attr| attr.path == sym::no_std);
self.has_no_std_attr = krate.attrs.iter().any(|attr| {
if let AttrKind::Normal(ref attr) = attr.kind {
attr.path == sym::no_std
} else {
false
}
});
}

fn check_expr_post(&mut self, cx: &LateContext<'_, '_>, expr: &Expr) {
Expand Down
45 changes: 4 additions & 41 deletions clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -968,34 +968,6 @@ declare_clippy_lint! {
"using `filter_map` when a more succinct alternative exists"
}

declare_clippy_lint! {
/// **What it does:** Checks for `into_iter` calls on types which should be replaced by `iter` or
/// `iter_mut`.
///
/// **Why is this bad?** Arrays and `PathBuf` do not yet have an `into_iter` method which move out
/// their content into an iterator. Auto-referencing resolves the `into_iter` call to its reference
/// instead, like `<&[T; N] as IntoIterator>::into_iter`, which just iterates over item references
/// like calling `iter` would. Furthermore, when the standard library actually
/// [implements the `into_iter` method](https://github.com/rust-lang/rust/issues/25725) which moves
/// the content out of the array, the original use of `into_iter` got inferred with the wrong type
/// and the code will be broken.
///
/// **Known problems:** None
///
/// **Example:**
///
/// ```rust
/// let _ = [1, 2, 3].into_iter().map(|x| *x).collect::<Vec<u32>>();
/// ```
/// Could be written as:
/// ```rust
/// let _ = [1, 2, 3].iter().map(|x| *x).collect::<Vec<u32>>();
/// ```
pub INTO_ITER_ON_ARRAY,
correctness,
"using `.into_iter()` on an array"
}

declare_clippy_lint! {
/// **What it does:** Checks for `into_iter` calls on references which should be replaced by `iter`
/// or `iter_mut`.
Expand Down Expand Up @@ -1133,7 +1105,6 @@ declare_lint_pass!(Methods => [
USELESS_ASREF,
UNNECESSARY_FOLD,
UNNECESSARY_FILTER_MAP,
INTO_ITER_ON_ARRAY,
INTO_ITER_ON_REF,
SUSPICIOUS_MAP,
UNINIT_ASSUMED_INIT,
Expand Down Expand Up @@ -2786,16 +2757,8 @@ fn lint_asref(cx: &LateContext<'_, '_>, expr: &hir::Expr, call_name: &str, as_re
}
}

fn ty_has_iter_method(
cx: &LateContext<'_, '_>,
self_ref_ty: Ty<'_>,
) -> Option<(&'static Lint, &'static str, &'static str)> {
fn ty_has_iter_method(cx: &LateContext<'_, '_>, self_ref_ty: Ty<'_>) -> Option<(&'static str, &'static str)> {
has_iter_method(cx, self_ref_ty).map(|ty_name| {
let lint = if ty_name == "array" || ty_name == "PathBuf" {
INTO_ITER_ON_ARRAY
} else {
INTO_ITER_ON_REF
};
let mutbl = match self_ref_ty.kind {
ty::Ref(_, _, mutbl) => mutbl,
_ => unreachable!(),
Expand All @@ -2804,18 +2767,18 @@ fn ty_has_iter_method(
hir::MutImmutable => "iter",
hir::MutMutable => "iter_mut",
};
(lint, ty_name, method_name)
(ty_name, method_name)
})
}

fn lint_into_iter(cx: &LateContext<'_, '_>, expr: &hir::Expr, self_ref_ty: Ty<'_>, method_span: Span) {
if !match_trait_method(cx, expr, &paths::INTO_ITERATOR) {
return;
}
if let Some((lint, kind, method_name)) = ty_has_iter_method(cx, self_ref_ty) {
if let Some((kind, method_name)) = ty_has_iter_method(cx, self_ref_ty) {
span_lint_and_sugg(
cx,
lint,
INTO_ITER_ON_REF,
method_span,
&format!(
"this .into_iter() call is equivalent to .{}() and will not move the {}",
Expand Down
8 changes: 4 additions & 4 deletions clippy_lints/src/misc_early.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,8 @@ impl MiscEarlyLints {

if let LitKind::Int(value, lit_int_type) = lit.kind {
let suffix = match lit_int_type {
LitIntType::Signed(ty) => ty.ty_to_string(),
LitIntType::Unsigned(ty) => ty.ty_to_string(),
LitIntType::Signed(ty) => ty.name_str(),
LitIntType::Unsigned(ty) => ty.name_str(),
LitIntType::Unsuffixed => "",
};

Expand Down Expand Up @@ -543,8 +543,8 @@ impl MiscEarlyLints {
},
);
}
} else if let LitKind::Float(_, float_ty) = lit.kind {
let suffix = float_ty.ty_to_string();
} else if let LitKind::Float(_, LitFloatType::Suffixed(float_ty)) = lit.kind {
let suffix = float_ty.name_str();
let maybe_last_sep_idx = lit_snip.len() - suffix.len() - 1;
if lit_snip.as_bytes()[maybe_last_sep_idx] != b'_' {
span_lint_and_sugg(
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/precedence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl EarlyLintPass for Precedence {
if let Some(slf) = args.first() {
if let ExprKind::Lit(ref lit) = slf.kind {
match lit.kind {
LitKind::Int(..) | LitKind::Float(..) | LitKind::FloatUnsuffixed(..) => {
LitKind::Int(..) | LitKind::Float(..) => {
let mut applicability = Applicability::MachineApplicable;
span_lint_and_sugg(
cx,
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/transmute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
|db| {
let arg = sugg::Sugg::hir(cx, &args[0], "..");
let arg = if let ty::Int(_) = from_ty.kind {
arg.as_ty(ast::UintTy::U32)
arg.as_ty(ast::UintTy::U32.name_str())
} else {
arg
};
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use rustc::{declare_lint_pass, declare_tool_lint, impl_lint_pass};
use rustc_errors::Applicability;
use rustc_target::spec::abi::Abi;
use rustc_typeck::hir_ty_to_ty;
use syntax::ast::{FloatTy, IntTy, LitIntType, LitKind, UintTy};
use syntax::ast::{FloatTy, IntTy, LitFloatType, LitIntType, LitKind, UintTy};
use syntax::errors::DiagnosticBuilder;
use syntax::source_map::Span;
use syntax::symbol::{sym, Symbol};
Expand Down Expand Up @@ -1186,7 +1186,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Casts {
}
}
match lit.node {
LitKind::Int(_, LitIntType::Unsuffixed) | LitKind::FloatUnsuffixed(_) => {},
LitKind::Int(_, LitIntType::Unsuffixed) | LitKind::Float(_, LitFloatType::Unsuffixed) => {},
_ => {
if cast_from.kind == cast_to.kind && !in_external_macro(cx.sess(), expr.span) {
span_lint(
Expand Down
5 changes: 5 additions & 0 deletions clippy_lints/src/utils/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ pub fn get_attr<'a>(
name: &'static str,
) -> impl Iterator<Item = &'a ast::Attribute> {
attrs.iter().filter(move |attr| {
let attr = if let ast::AttrKind::Normal(ref attr) = attr.kind {
attr
} else {
return false;
};
let attr_segments = &attr.path.segments;
if attr_segments.len() == 2 && attr_segments[0].ident.to_string() == "clippy" {
if let Some(deprecation_status) =
Expand Down
14 changes: 9 additions & 5 deletions clippy_lints/src/utils/author.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintContext, LintPass};
use rustc::session::Session;
use rustc::{declare_lint_pass, declare_tool_lint};
use rustc_data_structures::fx::FxHashMap;
use syntax::ast::{Attribute, LitKind};
use syntax::ast::{Attribute, LitFloatType, LitKind};

declare_clippy_lint! {
/// **What it does:** Generates clippy code that detects the offending pattern
Expand Down Expand Up @@ -288,10 +288,14 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
LitKind::Byte(b) => println!(" if let LitKind::Byte({}) = {}.node;", b, lit_pat),
// FIXME: also check int type
LitKind::Int(i, _) => println!(" if let LitKind::Int({}, _) = {}.node;", i, lit_pat),
LitKind::Float(..) => println!(" if let LitKind::Float(..) = {}.node;", lit_pat),
LitKind::FloatUnsuffixed(_) => {
println!(" if let LitKind::FloatUnsuffixed(_) = {}.node;", lit_pat)
},
LitKind::Float(_, LitFloatType::Suffixed(_)) => println!(
" if let LitKind::Float(_, LitFloatType::Suffixed(_)) = {}.node;",
lit_pat
),
LitKind::Float(_, LitFloatType::Unsuffixed) => println!(
" if let LitKind::Float(_, LitFloatType::Unsuffixed) = {}.node;",
lit_pat
),
LitKind::ByteStr(ref vec) => {
let vec_pat = self.next("vec");
println!(" if let LitKind::ByteStr(ref {}) = {}.node;", vec_pat, lit_pat);
Expand Down
9 changes: 1 addition & 8 deletions src/lintlist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub use lint::Lint;
pub use lint::LINT_LEVELS;

// begin lint list, do not remove this comment, it’s used in `update_lints`
pub const ALL_LINTS: [Lint; 332] = [
pub const ALL_LINTS: [Lint; 331] = [
Lint {
name: "absurd_extreme_comparisons",
group: "correctness",
Expand Down Expand Up @@ -812,13 +812,6 @@ pub const ALL_LINTS: [Lint; 332] = [
deprecation: None,
module: "integer_division",
},
Lint {
name: "into_iter_on_array",
group: "correctness",
desc: "using `.into_iter()` on an array",
deprecation: None,
module: "methods",
},
Lint {
name: "into_iter_on_ref",
group: "style",
Expand Down
Loading