diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index c822c59deeb3..bc345347dc6a 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -125,14 +125,14 @@ impl LintPass for AttrPass { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass { fn check_attribute(&mut self, cx: &LateContext<'a, 'tcx>, attr: &'tcx Attribute) { if let Some(ref items) = attr.meta_item_list() { - if items.is_empty() || attr.name().map_or(true, |n| n != "deprecated") { + if items.is_empty() || attr.name() != "deprecated" { return; } for item in items { if_chain! { if let NestedMetaItemKind::MetaItem(ref mi) = item.node; if let MetaItemKind::NameValue(ref lit) = mi.node; - if mi.ident.name == "since"; + if mi.name() == "since"; then { check_semver(cx, item.span, lit); } @@ -149,40 +149,38 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass { ItemExternCrate(_) | ItemUse(_, _) => { for attr in &item.attrs { if let Some(ref lint_list) = attr.meta_item_list() { - if let Some(name) = attr.name() { - match &*name.as_str() { - "allow" | "warn" | "deny" | "forbid" => { - // whitelist `unused_imports` and `deprecated` - for lint in lint_list { - if is_word(lint, "unused_imports") || is_word(lint, "deprecated") { - if let ItemUse(_, _) = item.node { - return; - } + match &*attr.name().as_str() { + "allow" | "warn" | "deny" | "forbid" => { + // whitelist `unused_imports` and `deprecated` + for lint in lint_list { + if is_word(lint, "unused_imports") || is_word(lint, "deprecated") { + if let ItemUse(_, _) = item.node { + return; } } - let line_span = last_line_of_span(cx, attr.span); + } + let line_span = last_line_of_span(cx, attr.span); - if let Some(mut sugg) = snippet_opt(cx, line_span) { - if sugg.contains("#[") { - span_lint_and_then( - cx, - USELESS_ATTRIBUTE, - line_span, - "useless lint attribute", - |db| { - sugg = sugg.replacen("#[", "#![", 1); - db.span_suggestion( - line_span, - "if you just forgot a `!`, use", - sugg, - ); - }, - ); - } + if let Some(mut sugg) = snippet_opt(cx, line_span) { + if sugg.contains("#[") { + span_lint_and_then( + cx, + USELESS_ATTRIBUTE, + line_span, + "useless lint attribute", + |db| { + sugg = sugg.replacen("#[", "#![", 1); + db.span_suggestion( + line_span, + "if you just forgot a `!`, use", + sugg, + ); + }, + ); } - }, - _ => {}, - } + } + }, + _ => {}, } } } @@ -294,7 +292,7 @@ fn check_attrs(cx: &LateContext, span: Span, name: &Name, attrs: &[Attribute]) { } if let Some(ref values) = attr.meta_item_list() { - if values.len() != 1 || attr.name().map_or(true, |n| n != "inline") { + if values.len() != 1 || attr.name() != "inline" { continue; } if is_word(&values[0], "always") { @@ -328,7 +326,7 @@ fn check_semver(cx: &LateContext, span: Span, lit: &Lit) { fn is_word(nmi: &NestedMetaItem, expected: &str) -> bool { if let NestedMetaItemKind::MetaItem(ref mi) = nmi.node { - mi.is_word() && mi.ident.name == expected + mi.is_word() && mi.name() == expected } else { false } diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 10043df9cbf9..7d3e812c9c59 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -150,11 +150,9 @@ pub fn check_attrs<'a>(cx: &EarlyContext, valid_idents: &[String], attrs: &'a [a spans.extend_from_slice(¤t_spans); doc.push_str(¤t); } - } else if let Some(name) = attr.name() { + } else if attr.name() == "doc" { // ignore mix of sugared and non-sugared doc - if name == "doc" { - return; - } + return; } } diff --git a/clippy_lints/src/inline_fn_without_body.rs b/clippy_lints/src/inline_fn_without_body.rs index af7de542a91d..34196a1728f2 100644 --- a/clippy_lints/src/inline_fn_without_body.rs +++ b/clippy_lints/src/inline_fn_without_body.rs @@ -45,7 +45,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { fn check_attrs(cx: &LateContext, name: &Name, attrs: &[Attribute]) { for attr in attrs { - if attr.name().map_or(true, |n| n != "inline") { + if attr.name() != "inline" { continue; } diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 0a500f9ad6e5..821093735dfe 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -42,7 +42,6 @@ extern crate regex_syntax; extern crate quine_mc_cluskey; -extern crate rustc_const_math; extern crate rustc_errors; extern crate rustc_plugin; diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index 7defccf4697c..fb8814d6d873 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -1,6 +1,7 @@ use rustc::hir; use rustc::lint::*; use rustc::ty; +use rustc_errors::{Applicability}; use syntax::codemap::Span; use utils::{in_macro, iter_input_pats, match_type, method_chain_args, snippet, span_lint_and_then}; use utils::paths; @@ -210,7 +211,10 @@ fn lint_map_unit_fn(cx: &LateContext, stmt: &hir::Stmt, expr: &hir::Expr, map_ar snippet(cx, fn_arg.span, "_")); span_lint_and_then(cx, lint, expr.span, &msg, |db| { - db.span_approximate_suggestion(stmt.span, "try this", suggestion); + db.span_suggestion_with_applicability(stmt.span, + "try this", + suggestion, + Applicability::Unspecified); }); } else if let Some((binding, closure_expr)) = unit_closure(cx, fn_arg) { let msg = suggestion_msg("closure", map_type); @@ -218,17 +222,20 @@ fn lint_map_unit_fn(cx: &LateContext, stmt: &hir::Stmt, expr: &hir::Expr, map_ar span_lint_and_then(cx, lint, expr.span, &msg, |db| { if let Some(reduced_expr_span) = reduce_unit_expression(cx, closure_expr) { let suggestion = format!("if let {0}({1}) = {2} {{ {3} }}", - variant, - snippet(cx, binding.pat.span, "_"), - snippet(cx, var_arg.span, "_"), - snippet(cx, reduced_expr_span, "_")); + variant, + snippet(cx, binding.pat.span, "_"), + snippet(cx, var_arg.span, "_"), + snippet(cx, reduced_expr_span, "_")); db.span_suggestion(stmt.span, "try this", suggestion); } else { let suggestion = format!("if let {0}({1}) = {2} {{ ... }}", - variant, - snippet(cx, binding.pat.span, "_"), - snippet(cx, var_arg.span, "_")); - db.span_approximate_suggestion(stmt.span, "try this", suggestion); + variant, + snippet(cx, binding.pat.span, "_"), + snippet(cx, var_arg.span, "_")); + db.span_suggestion_with_applicability(stmt.span, + "try this", + suggestion, + Applicability::Unspecified); } }); } diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 6a83417157b2..d9a6463641e3 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -84,7 +84,7 @@ impl MissingDoc { let has_doc = attrs .iter() - .any(|a| a.is_value_str() && a.name().map_or(false, |n| n == "doc")); + .any(|a| a.is_value_str() && a.name() == "doc"); if !has_doc { cx.span_lint( MISSING_DOCS_IN_PRIVATE_ITEMS, diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 944f20fe99d5..dc78f428ef97 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -77,13 +77,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue { return; } for a in attrs { - if_chain! { - if a.meta_item_list().is_some(); - if let Some(name) = a.name(); - if name == "proc_macro_derive"; - then { - return; - } + if a.meta_item_list().is_some() && a.name() == "proc_macro_derive" { + return; } } }, diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index 5e5e93783d32..ae77dd7b4a87 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -149,5 +149,5 @@ impl EarlyLintPass for ReturnPass { } fn attr_is_cfg(attr: &ast::Attribute) -> bool { - attr.meta_item_list().is_some() && attr.name().map_or(false, |n| n == "cfg") + attr.meta_item_list().is_some() && attr.name() == "cfg" } diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 8e81d9440b06..fccb47817e0c 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -463,7 +463,7 @@ fn has_attr(attrs: &[Attribute]) -> bool { attrs.iter().any(|attr| { attr.check_name("clippy") && attr.meta_item_list().map_or(false, |list| { list.len() == 1 && match list[0].node { - ast::NestedMetaItemKind::MetaItem(ref it) => it.ident.name == "author", + ast::NestedMetaItemKind::MetaItem(ref it) => it.name() == "author", ast::NestedMetaItemKind::Literal(_) => false, } }) diff --git a/clippy_lints/src/utils/conf.rs b/clippy_lints/src/utils/conf.rs index 607082e8ad23..58e71705011a 100644 --- a/clippy_lints/src/utils/conf.rs +++ b/clippy_lints/src/utils/conf.rs @@ -13,7 +13,7 @@ pub fn file_from_args( args: &[codemap::Spanned], ) -> Result, (&'static str, codemap::Span)> { for arg in args.iter().filter_map(|a| a.meta_item()) { - if arg.ident.name == "conf_file" { + if arg.name() == "conf_file" { return match arg.node { ast::MetaItemKind::Word | ast::MetaItemKind::List(_) => { Err(("`conf_file` must be a named value", arg.span)) diff --git a/clippy_lints/src/utils/higher.rs b/clippy_lints/src/utils/higher.rs index 091261ffbec4..011d2f7b8a25 100644 --- a/clippy_lints/src/utils/higher.rs +++ b/clippy_lints/src/utils/higher.rs @@ -69,6 +69,19 @@ pub fn range(expr: &hir::Expr) -> Option { None } }, + hir::ExprCall(ref path, ref args) => if let hir::ExprPath(ref path) = path.node { + if match_qpath(path, &paths::RANGE_INCLUSIVE_STD_NEW) || match_qpath(path, &paths::RANGE_INCLUSIVE_NEW) { + Some(Range { + start: Some(&args[0]), + end: Some(&args[1]), + limits: ast::RangeLimits::Closed, + }) + } else { + None + } + } else { + None + }, hir::ExprStruct(ref path, ref fields, None) => if match_qpath(path, &paths::RANGE_FROM_STD) || match_qpath(path, &paths::RANGE_FROM) { @@ -77,12 +90,6 @@ pub fn range(expr: &hir::Expr) -> Option { end: None, limits: ast::RangeLimits::HalfOpen, }) - } else if match_qpath(path, &paths::RANGE_INCLUSIVE_STD) || match_qpath(path, &paths::RANGE_INCLUSIVE) { - Some(Range { - start: Some(get_field("start", fields)?), - end: Some(get_field("end", fields)?), - limits: ast::RangeLimits::Closed, - }) } else if match_qpath(path, &paths::RANGE_STD) || match_qpath(path, &paths::RANGE) { Some(Range { start: Some(get_field("start", fields)?), diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 00b9fa37c151..9234926d534c 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -9,7 +9,7 @@ use rustc::lint::{LateContext, Level, Lint, LintContext}; use rustc::session::Session; use rustc::traits; use rustc::ty::{self, Ty, TyCtxt, layout::{self, IntegerExt}}; -use rustc_errors; +use rustc_errors::{Applicability, CodeSuggestion, Substitution, SubstitutionPart}; use std::borrow::Cow; use std::env; use std::mem; @@ -643,12 +643,12 @@ pub fn multispan_sugg(db: &mut DiagnosticBuilder, help_msg: String, sugg: I) where I: IntoIterator, { - let sugg = rustc_errors::CodeSuggestion { + let sugg = CodeSuggestion { substitutions: vec![ - rustc_errors::Substitution { + Substitution { parts: sugg.into_iter() .map(|(span, snippet)| { - rustc_errors::SubstitutionPart { + SubstitutionPart { snippet, span, } @@ -658,7 +658,7 @@ where ], msg: help_msg, show_code_when_inline: true, - approximate: false, + applicability: Applicability::Unspecified, }; db.suggestions.push(sugg); } @@ -741,7 +741,7 @@ fn parse_attrs(sess: &Session, attrs: &[ast::Attribute], name: &' continue; } if let Some(ref value) = attr.value_str() { - if attr.name().map_or(false, |n| n == name) { + if attr.name() == name { if let Ok(value) = FromStr::from_str(&value.as_str()) { attr::mark_used(attr); f(value) diff --git a/clippy_lints/src/utils/paths.rs b/clippy_lints/src/utils/paths.rs index fbc3cc303a8e..a1cb6670bc5e 100644 --- a/clippy_lints/src/utils/paths.rs +++ b/clippy_lints/src/utils/paths.rs @@ -66,7 +66,9 @@ pub const RANGE_FROM_STD: [&str; 3] = ["std", "ops", "RangeFrom"]; pub const RANGE_FULL: [&str; 3] = ["core", "ops", "RangeFull"]; pub const RANGE_FULL_STD: [&str; 3] = ["std", "ops", "RangeFull"]; pub const RANGE_INCLUSIVE: [&str; 3] = ["core", "ops", "RangeInclusive"]; +pub const RANGE_INCLUSIVE_NEW: [&str; 4] = ["core", "ops", "RangeInclusive", "new"]; pub const RANGE_INCLUSIVE_STD: [&str; 3] = ["std", "ops", "RangeInclusive"]; +pub const RANGE_INCLUSIVE_STD_NEW: [&str; 4] = ["std", "ops", "RangeInclusive", "new"]; pub const RANGE_STD: [&str; 3] = ["std", "ops", "Range"]; pub const RANGE_TO: [&str; 3] = ["core", "ops", "RangeTo"]; pub const RANGE_TO_INCLUSIVE: [&str; 3] = ["core", "ops", "RangeToInclusive"]; diff --git a/tests/ui/no_effect.stderr b/tests/ui/no_effect.stderr index 64c0267a8b80..7ff0425ebb9c 100644 --- a/tests/ui/no_effect.stderr +++ b/tests/ui/no_effect.stderr @@ -108,12 +108,6 @@ error: statement with no effect 76 | 5..6; | ^^^^^ -error: statement with no effect - --> $DIR/no_effect.rs:77:5 - | -77 | 5..=6; - | ^^^^^^ - error: statement with no effect --> $DIR/no_effect.rs:78:5 | @@ -278,5 +272,5 @@ error: statement can be reduced 116 | FooString { s: String::from("blah"), }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `String::from("blah");` -error: aborting due to 46 previous errors +error: aborting due to 45 previous errors diff --git a/tests/ui/redundant_field_names.rs b/tests/ui/redundant_field_names.rs index a14f0ef40a04..095ac7c0cc15 100644 --- a/tests/ui/redundant_field_names.rs +++ b/tests/ui/redundant_field_names.rs @@ -1,6 +1,6 @@ #![warn(redundant_field_names)] #![allow(unused_variables)] -#![feature(inclusive_range, inclusive_range_fields)] +#![feature(inclusive_range, inclusive_range_fields, inclusive_range_methods)] #[macro_use] extern crate derive_new; @@ -53,6 +53,6 @@ fn main() { let _ = RangeFrom { start: start }; let _ = RangeTo { end: end }; let _ = Range { start: start, end: end }; - let _ = RangeInclusive { start: start, end: end }; + let _ = RangeInclusive::new(start, end); let _ = RangeToInclusive { end: end }; } diff --git a/tests/ui/redundant_field_names.stderr b/tests/ui/redundant_field_names.stderr index 91db8a5f0d16..d757f1871a78 100644 --- a/tests/ui/redundant_field_names.stderr +++ b/tests/ui/redundant_field_names.stderr @@ -36,23 +36,11 @@ error: redundant field names in struct initialization 55 | let _ = Range { start: start, end: end }; | ^^^^^^^^ help: replace it with: `end` -error: redundant field names in struct initialization - --> $DIR/redundant_field_names.rs:56:30 - | -56 | let _ = RangeInclusive { start: start, end: end }; - | ^^^^^^^^^^^^ help: replace it with: `start` - -error: redundant field names in struct initialization - --> $DIR/redundant_field_names.rs:56:44 - | -56 | let _ = RangeInclusive { start: start, end: end }; - | ^^^^^^^^ help: replace it with: `end` - error: redundant field names in struct initialization --> $DIR/redundant_field_names.rs:57:32 | 57 | let _ = RangeToInclusive { end: end }; | ^^^^^^^^ help: replace it with: `end` -error: aborting due to 9 previous errors +error: aborting due to 7 previous errors