Skip to content

Commit c1b39c4

Browse files
authored
Merge pull request #2713 from alexreg/nightly-fix
Fixed build for latest rust master
2 parents 77de100 + 9ce6fb3 commit c1b39c4

16 files changed

+82
-94
lines changed

clippy_lints/src/attrs.rs

+32-34
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,14 @@ impl LintPass for AttrPass {
125125
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
126126
fn check_attribute(&mut self, cx: &LateContext<'a, 'tcx>, attr: &'tcx Attribute) {
127127
if let Some(ref items) = attr.meta_item_list() {
128-
if items.is_empty() || attr.name().map_or(true, |n| n != "deprecated") {
128+
if items.is_empty() || attr.name() != "deprecated" {
129129
return;
130130
}
131131
for item in items {
132132
if_chain! {
133133
if let NestedMetaItemKind::MetaItem(ref mi) = item.node;
134134
if let MetaItemKind::NameValue(ref lit) = mi.node;
135-
if mi.ident.name == "since";
135+
if mi.name() == "since";
136136
then {
137137
check_semver(cx, item.span, lit);
138138
}
@@ -149,40 +149,38 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
149149
ItemExternCrate(_) | ItemUse(_, _) => {
150150
for attr in &item.attrs {
151151
if let Some(ref lint_list) = attr.meta_item_list() {
152-
if let Some(name) = attr.name() {
153-
match &*name.as_str() {
154-
"allow" | "warn" | "deny" | "forbid" => {
155-
// whitelist `unused_imports` and `deprecated`
156-
for lint in lint_list {
157-
if is_word(lint, "unused_imports") || is_word(lint, "deprecated") {
158-
if let ItemUse(_, _) = item.node {
159-
return;
160-
}
152+
match &*attr.name().as_str() {
153+
"allow" | "warn" | "deny" | "forbid" => {
154+
// whitelist `unused_imports` and `deprecated`
155+
for lint in lint_list {
156+
if is_word(lint, "unused_imports") || is_word(lint, "deprecated") {
157+
if let ItemUse(_, _) = item.node {
158+
return;
161159
}
162160
}
163-
let line_span = last_line_of_span(cx, attr.span);
161+
}
162+
let line_span = last_line_of_span(cx, attr.span);
164163

165-
if let Some(mut sugg) = snippet_opt(cx, line_span) {
166-
if sugg.contains("#[") {
167-
span_lint_and_then(
168-
cx,
169-
USELESS_ATTRIBUTE,
170-
line_span,
171-
"useless lint attribute",
172-
|db| {
173-
sugg = sugg.replacen("#[", "#![", 1);
174-
db.span_suggestion(
175-
line_span,
176-
"if you just forgot a `!`, use",
177-
sugg,
178-
);
179-
},
180-
);
181-
}
164+
if let Some(mut sugg) = snippet_opt(cx, line_span) {
165+
if sugg.contains("#[") {
166+
span_lint_and_then(
167+
cx,
168+
USELESS_ATTRIBUTE,
169+
line_span,
170+
"useless lint attribute",
171+
|db| {
172+
sugg = sugg.replacen("#[", "#![", 1);
173+
db.span_suggestion(
174+
line_span,
175+
"if you just forgot a `!`, use",
176+
sugg,
177+
);
178+
},
179+
);
182180
}
183-
},
184-
_ => {},
185-
}
181+
}
182+
},
183+
_ => {},
186184
}
187185
}
188186
}
@@ -294,7 +292,7 @@ fn check_attrs(cx: &LateContext, span: Span, name: &Name, attrs: &[Attribute]) {
294292
}
295293

296294
if let Some(ref values) = attr.meta_item_list() {
297-
if values.len() != 1 || attr.name().map_or(true, |n| n != "inline") {
295+
if values.len() != 1 || attr.name() != "inline" {
298296
continue;
299297
}
300298
if is_word(&values[0], "always") {
@@ -328,7 +326,7 @@ fn check_semver(cx: &LateContext, span: Span, lit: &Lit) {
328326

329327
fn is_word(nmi: &NestedMetaItem, expected: &str) -> bool {
330328
if let NestedMetaItemKind::MetaItem(ref mi) = nmi.node {
331-
mi.is_word() && mi.ident.name == expected
329+
mi.is_word() && mi.name() == expected
332330
} else {
333331
false
334332
}

clippy_lints/src/doc.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,9 @@ pub fn check_attrs<'a>(cx: &EarlyContext, valid_idents: &[String], attrs: &'a [a
150150
spans.extend_from_slice(&current_spans);
151151
doc.push_str(&current);
152152
}
153-
} else if let Some(name) = attr.name() {
153+
} else if attr.name() == "doc" {
154154
// ignore mix of sugared and non-sugared doc
155-
if name == "doc" {
156-
return;
157-
}
155+
return;
158156
}
159157
}
160158

clippy_lints/src/inline_fn_without_body.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
4545

4646
fn check_attrs(cx: &LateContext, name: &Name, attrs: &[Attribute]) {
4747
for attr in attrs {
48-
if attr.name().map_or(true, |n| n != "inline") {
48+
if attr.name() != "inline" {
4949
continue;
5050
}
5151

clippy_lints/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ extern crate regex_syntax;
4242

4343
extern crate quine_mc_cluskey;
4444

45-
extern crate rustc_const_math;
4645
extern crate rustc_errors;
4746
extern crate rustc_plugin;
4847

clippy_lints/src/map_unit_fn.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use rustc::hir;
22
use rustc::lint::*;
33
use rustc::ty;
4+
use rustc_errors::{Applicability};
45
use syntax::codemap::Span;
56
use utils::{in_macro, iter_input_pats, match_type, method_chain_args, snippet, span_lint_and_then};
67
use utils::paths;
@@ -210,25 +211,31 @@ fn lint_map_unit_fn(cx: &LateContext, stmt: &hir::Stmt, expr: &hir::Expr, map_ar
210211
snippet(cx, fn_arg.span, "_"));
211212

212213
span_lint_and_then(cx, lint, expr.span, &msg, |db| {
213-
db.span_approximate_suggestion(stmt.span, "try this", suggestion);
214+
db.span_suggestion_with_applicability(stmt.span,
215+
"try this",
216+
suggestion,
217+
Applicability::Unspecified);
214218
});
215219
} else if let Some((binding, closure_expr)) = unit_closure(cx, fn_arg) {
216220
let msg = suggestion_msg("closure", map_type);
217221

218222
span_lint_and_then(cx, lint, expr.span, &msg, |db| {
219223
if let Some(reduced_expr_span) = reduce_unit_expression(cx, closure_expr) {
220224
let suggestion = format!("if let {0}({1}) = {2} {{ {3} }}",
221-
variant,
222-
snippet(cx, binding.pat.span, "_"),
223-
snippet(cx, var_arg.span, "_"),
224-
snippet(cx, reduced_expr_span, "_"));
225+
variant,
226+
snippet(cx, binding.pat.span, "_"),
227+
snippet(cx, var_arg.span, "_"),
228+
snippet(cx, reduced_expr_span, "_"));
225229
db.span_suggestion(stmt.span, "try this", suggestion);
226230
} else {
227231
let suggestion = format!("if let {0}({1}) = {2} {{ ... }}",
228-
variant,
229-
snippet(cx, binding.pat.span, "_"),
230-
snippet(cx, var_arg.span, "_"));
231-
db.span_approximate_suggestion(stmt.span, "try this", suggestion);
232+
variant,
233+
snippet(cx, binding.pat.span, "_"),
234+
snippet(cx, var_arg.span, "_"));
235+
db.span_suggestion_with_applicability(stmt.span,
236+
"try this",
237+
suggestion,
238+
Applicability::Unspecified);
232239
}
233240
});
234241
}

clippy_lints/src/missing_doc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl MissingDoc {
8484

8585
let has_doc = attrs
8686
.iter()
87-
.any(|a| a.is_value_str() && a.name().map_or(false, |n| n == "doc"));
87+
.any(|a| a.is_value_str() && a.name() == "doc");
8888
if !has_doc {
8989
cx.span_lint(
9090
MISSING_DOCS_IN_PRIVATE_ITEMS,

clippy_lints/src/needless_pass_by_value.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
7777
return;
7878
}
7979
for a in attrs {
80-
if_chain! {
81-
if a.meta_item_list().is_some();
82-
if let Some(name) = a.name();
83-
if name == "proc_macro_derive";
84-
then {
85-
return;
86-
}
80+
if a.meta_item_list().is_some() && a.name() == "proc_macro_derive" {
81+
return;
8782
}
8883
}
8984
},

clippy_lints/src/returns.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,5 @@ impl EarlyLintPass for ReturnPass {
149149
}
150150

151151
fn attr_is_cfg(attr: &ast::Attribute) -> bool {
152-
attr.meta_item_list().is_some() && attr.name().map_or(false, |n| n == "cfg")
152+
attr.meta_item_list().is_some() && attr.name() == "cfg"
153153
}

clippy_lints/src/utils/author.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ fn has_attr(attrs: &[Attribute]) -> bool {
463463
attrs.iter().any(|attr| {
464464
attr.check_name("clippy") && attr.meta_item_list().map_or(false, |list| {
465465
list.len() == 1 && match list[0].node {
466-
ast::NestedMetaItemKind::MetaItem(ref it) => it.ident.name == "author",
466+
ast::NestedMetaItemKind::MetaItem(ref it) => it.name() == "author",
467467
ast::NestedMetaItemKind::Literal(_) => false,
468468
}
469469
})

clippy_lints/src/utils/conf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub fn file_from_args(
1313
args: &[codemap::Spanned<ast::NestedMetaItemKind>],
1414
) -> Result<Option<path::PathBuf>, (&'static str, codemap::Span)> {
1515
for arg in args.iter().filter_map(|a| a.meta_item()) {
16-
if arg.ident.name == "conf_file" {
16+
if arg.name() == "conf_file" {
1717
return match arg.node {
1818
ast::MetaItemKind::Word | ast::MetaItemKind::List(_) => {
1919
Err(("`conf_file` must be a named value", arg.span))

clippy_lints/src/utils/higher.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ pub fn range(expr: &hir::Expr) -> Option<Range> {
6969
None
7070
}
7171
},
72+
hir::ExprCall(ref path, ref args) => if let hir::ExprPath(ref path) = path.node {
73+
if match_qpath(path, &paths::RANGE_INCLUSIVE_STD_NEW) || match_qpath(path, &paths::RANGE_INCLUSIVE_NEW) {
74+
Some(Range {
75+
start: Some(&args[0]),
76+
end: Some(&args[1]),
77+
limits: ast::RangeLimits::Closed,
78+
})
79+
} else {
80+
None
81+
}
82+
} else {
83+
None
84+
},
7285
hir::ExprStruct(ref path, ref fields, None) => if match_qpath(path, &paths::RANGE_FROM_STD)
7386
|| match_qpath(path, &paths::RANGE_FROM)
7487
{
@@ -77,12 +90,6 @@ pub fn range(expr: &hir::Expr) -> Option<Range> {
7790
end: None,
7891
limits: ast::RangeLimits::HalfOpen,
7992
})
80-
} else if match_qpath(path, &paths::RANGE_INCLUSIVE_STD) || match_qpath(path, &paths::RANGE_INCLUSIVE) {
81-
Some(Range {
82-
start: Some(get_field("start", fields)?),
83-
end: Some(get_field("end", fields)?),
84-
limits: ast::RangeLimits::Closed,
85-
})
8693
} else if match_qpath(path, &paths::RANGE_STD) || match_qpath(path, &paths::RANGE) {
8794
Some(Range {
8895
start: Some(get_field("start", fields)?),

clippy_lints/src/utils/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc::lint::{LateContext, Level, Lint, LintContext};
99
use rustc::session::Session;
1010
use rustc::traits;
1111
use rustc::ty::{self, Ty, TyCtxt, layout::{self, IntegerExt}};
12-
use rustc_errors;
12+
use rustc_errors::{Applicability, CodeSuggestion, Substitution, SubstitutionPart};
1313
use std::borrow::Cow;
1414
use std::env;
1515
use std::mem;
@@ -643,12 +643,12 @@ pub fn multispan_sugg<I>(db: &mut DiagnosticBuilder, help_msg: String, sugg: I)
643643
where
644644
I: IntoIterator<Item = (Span, String)>,
645645
{
646-
let sugg = rustc_errors::CodeSuggestion {
646+
let sugg = CodeSuggestion {
647647
substitutions: vec![
648-
rustc_errors::Substitution {
648+
Substitution {
649649
parts: sugg.into_iter()
650650
.map(|(span, snippet)| {
651-
rustc_errors::SubstitutionPart {
651+
SubstitutionPart {
652652
snippet,
653653
span,
654654
}
@@ -658,7 +658,7 @@ where
658658
],
659659
msg: help_msg,
660660
show_code_when_inline: true,
661-
approximate: false,
661+
applicability: Applicability::Unspecified,
662662
};
663663
db.suggestions.push(sugg);
664664
}
@@ -741,7 +741,7 @@ fn parse_attrs<F: FnMut(u64)>(sess: &Session, attrs: &[ast::Attribute], name: &'
741741
continue;
742742
}
743743
if let Some(ref value) = attr.value_str() {
744-
if attr.name().map_or(false, |n| n == name) {
744+
if attr.name() == name {
745745
if let Ok(value) = FromStr::from_str(&value.as_str()) {
746746
attr::mark_used(attr);
747747
f(value)

clippy_lints/src/utils/paths.rs

+2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ pub const RANGE_FROM_STD: [&str; 3] = ["std", "ops", "RangeFrom"];
6666
pub const RANGE_FULL: [&str; 3] = ["core", "ops", "RangeFull"];
6767
pub const RANGE_FULL_STD: [&str; 3] = ["std", "ops", "RangeFull"];
6868
pub const RANGE_INCLUSIVE: [&str; 3] = ["core", "ops", "RangeInclusive"];
69+
pub const RANGE_INCLUSIVE_NEW: [&str; 4] = ["core", "ops", "RangeInclusive", "new"];
6970
pub const RANGE_INCLUSIVE_STD: [&str; 3] = ["std", "ops", "RangeInclusive"];
71+
pub const RANGE_INCLUSIVE_STD_NEW: [&str; 4] = ["std", "ops", "RangeInclusive", "new"];
7072
pub const RANGE_STD: [&str; 3] = ["std", "ops", "Range"];
7173
pub const RANGE_TO: [&str; 3] = ["core", "ops", "RangeTo"];
7274
pub const RANGE_TO_INCLUSIVE: [&str; 3] = ["core", "ops", "RangeToInclusive"];

tests/ui/no_effect.stderr

+1-7
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,6 @@ error: statement with no effect
108108
76 | 5..6;
109109
| ^^^^^
110110

111-
error: statement with no effect
112-
--> $DIR/no_effect.rs:77:5
113-
|
114-
77 | 5..=6;
115-
| ^^^^^^
116-
117111
error: statement with no effect
118112
--> $DIR/no_effect.rs:78:5
119113
|
@@ -278,5 +272,5 @@ error: statement can be reduced
278272
116 | FooString { s: String::from("blah"), };
279273
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `String::from("blah");`
280274

281-
error: aborting due to 46 previous errors
275+
error: aborting due to 45 previous errors
282276

tests/ui/redundant_field_names.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![warn(redundant_field_names)]
22
#![allow(unused_variables)]
3-
#![feature(inclusive_range, inclusive_range_fields)]
3+
#![feature(inclusive_range, inclusive_range_fields, inclusive_range_methods)]
44

55
#[macro_use]
66
extern crate derive_new;
@@ -53,6 +53,6 @@ fn main() {
5353
let _ = RangeFrom { start: start };
5454
let _ = RangeTo { end: end };
5555
let _ = Range { start: start, end: end };
56-
let _ = RangeInclusive { start: start, end: end };
56+
let _ = RangeInclusive::new(start, end);
5757
let _ = RangeToInclusive { end: end };
5858
}

tests/ui/redundant_field_names.stderr

+1-13
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,11 @@ error: redundant field names in struct initialization
3636
55 | let _ = Range { start: start, end: end };
3737
| ^^^^^^^^ help: replace it with: `end`
3838

39-
error: redundant field names in struct initialization
40-
--> $DIR/redundant_field_names.rs:56:30
41-
|
42-
56 | let _ = RangeInclusive { start: start, end: end };
43-
| ^^^^^^^^^^^^ help: replace it with: `start`
44-
45-
error: redundant field names in struct initialization
46-
--> $DIR/redundant_field_names.rs:56:44
47-
|
48-
56 | let _ = RangeInclusive { start: start, end: end };
49-
| ^^^^^^^^ help: replace it with: `end`
50-
5139
error: redundant field names in struct initialization
5240
--> $DIR/redundant_field_names.rs:57:32
5341
|
5442
57 | let _ = RangeToInclusive { end: end };
5543
| ^^^^^^^^ help: replace it with: `end`
5644

57-
error: aborting due to 9 previous errors
45+
error: aborting due to 7 previous errors
5846

0 commit comments

Comments
 (0)