Skip to content
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

Fixed build for latest rust master #2713

Merged
merged 6 commits into from
May 4, 2018
Merged
Show file tree
Hide file tree
Changes from 4 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
66 changes: 32 additions & 34 deletions clippy_lints/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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,
);
},
);
}
},
_ => {},
}
}
},
_ => {},
}
}
}
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ pub fn check_attrs<'a>(cx: &EarlyContext, valid_idents: &[String], attrs: &'a [a
spans.extend_from_slice(&current_spans);
doc.push_str(&current);
}
} else if let Some(name) = attr.name() {
} else {
// ignore mix of sugared and non-sugared doc
if name == "doc" {
if attr.name() == "doc" {
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/inline_fn_without_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change == to !=.
With that change all tests passed on my Linux box.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, superb. Let's see what travis says

continue;
}

Expand Down
1 change: 0 additions & 1 deletion clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ extern crate regex_syntax;

extern crate quine_mc_cluskey;

extern crate rustc_const_math;
extern crate rustc_errors;
extern crate rustc_plugin;

Expand Down
25 changes: 16 additions & 9 deletions clippy_lints/src/map_unit_fn.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -210,25 +211,31 @@ 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);

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);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/missing_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 2 additions & 7 deletions clippy_lints/src/needless_pass_by_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/returns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
2 changes: 1 addition & 1 deletion clippy_lints/src/utils/author.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
})
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/utils/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub fn file_from_args(
args: &[codemap::Spanned<ast::NestedMetaItemKind>],
) -> Result<Option<path::PathBuf>, (&'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))
Expand Down
19 changes: 13 additions & 6 deletions clippy_lints/src/utils/higher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ pub fn range(expr: &hir::Expr) -> Option<Range> {
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)
{
Expand All @@ -77,12 +90,6 @@ pub fn range(expr: &hir::Expr) -> Option<Range> {
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)?),
Expand Down
12 changes: 6 additions & 6 deletions clippy_lints/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -645,12 +645,12 @@ pub fn multispan_sugg<I>(db: &mut DiagnosticBuilder, help_msg: String, sugg: I)
where
I: IntoIterator<Item = (Span, String)>,
{
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,
}
Expand All @@ -660,7 +660,7 @@ where
],
msg: help_msg,
show_code_when_inline: true,
approximate: false,
applicability: Applicability::Unspecified,
};
db.suggestions.push(sugg);
}
Expand Down Expand Up @@ -743,7 +743,7 @@ fn parse_attrs<F: FnMut(u64)>(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)
Expand Down
2 changes: 2 additions & 0 deletions clippy_lints/src/utils/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down
8 changes: 1 addition & 7 deletions tests/ui/no_effect.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
|
Expand Down Expand Up @@ -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

4 changes: 2 additions & 2 deletions tests/ui/redundant_field_names.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 };
}
14 changes: 1 addition & 13 deletions tests/ui/redundant_field_names.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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