Skip to content

Commit 5df84f2

Browse files
committed
Merge branch 'origin/master' into suspicious_map
2 parents 72e4e4a + e92c489 commit 5df84f2

26 files changed

+153
-174
lines changed

PUBLISH.md

-14
This file was deleted.
+20-25
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
use if_chain::if_chain;
21
use rustc::hir::{Expr, ExprKind};
32
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
43
use rustc::{declare_lint_pass, declare_tool_lint};
5-
use syntax_pos::Span;
64

75
use crate::consts::{constant, Constant};
8-
use crate::utils::{in_macro_or_desugar, is_direct_expn_of, span_help_and_lint};
6+
use crate::utils::{in_macro_or_desugar, is_direct_expn_of, is_expn_of, span_help_and_lint};
97

108
declare_clippy_lint! {
119
/// **What it does:** Checks for `assert!(true)` and `assert!(false)` calls.
@@ -33,42 +31,39 @@ declare_lint_pass!(AssertionsOnConstants => [ASSERTIONS_ON_CONSTANTS]);
3331

3432
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
3533
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
36-
let mut is_debug_assert = false;
37-
let debug_assert_not_in_macro_or_desugar = |span: Span| {
38-
is_debug_assert = true;
39-
// Check that `debug_assert!` itself is not inside a macro
40-
!in_macro_or_desugar(span)
41-
};
42-
if_chain! {
43-
if let Some(assert_span) = is_direct_expn_of(e.span, "assert");
44-
if !in_macro_or_desugar(assert_span)
45-
|| is_direct_expn_of(assert_span, "debug_assert")
46-
.map_or(false, debug_assert_not_in_macro_or_desugar);
47-
if let ExprKind::Unary(_, ref lit) = e.node;
48-
if let Some(bool_const) = constant(cx, cx.tables, lit);
49-
then {
50-
match bool_const.0 {
51-
Constant::Bool(true) => {
34+
let lint_assert_cb = |is_debug_assert: bool| {
35+
if let ExprKind::Unary(_, ref lit) = e.node {
36+
if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.tables, lit) {
37+
if is_true {
5238
span_help_and_lint(
5339
cx,
5440
ASSERTIONS_ON_CONSTANTS,
5541
e.span,
5642
"`assert!(true)` will be optimized out by the compiler",
57-
"remove it"
43+
"remove it",
5844
);
59-
},
60-
Constant::Bool(false) if !is_debug_assert => {
45+
} else if !is_debug_assert {
6146
span_help_and_lint(
6247
cx,
6348
ASSERTIONS_ON_CONSTANTS,
6449
e.span,
6550
"`assert!(false)` should probably be replaced",
66-
"use `panic!()` or `unreachable!()`"
51+
"use `panic!()` or `unreachable!()`",
6752
);
68-
},
69-
_ => (),
53+
}
7054
}
7155
}
56+
};
57+
if let Some(debug_assert_span) = is_expn_of(e.span, "debug_assert") {
58+
if in_macro_or_desugar(debug_assert_span) {
59+
return;
60+
}
61+
lint_assert_cb(true);
62+
} else if let Some(assert_span) = is_direct_expn_of(e.span, "assert") {
63+
if in_macro_or_desugar(assert_span) {
64+
return;
65+
}
66+
lint_assert_cb(false);
7267
}
7368
}
7469
}

clippy_lints/src/copies.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -298,14 +298,14 @@ fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat) -> FxHashMap<LocalI
298298
bindings_impl(cx, as_pat, map);
299299
}
300300
},
301-
PatKind::Struct(_, ref fields, _) => {
301+
PatKind::Or(ref fields) | PatKind::Tuple(ref fields, _) => {
302302
for pat in fields {
303-
bindings_impl(cx, &pat.node.pat, map);
303+
bindings_impl(cx, pat, map);
304304
}
305305
},
306-
PatKind::Tuple(ref fields, _) => {
306+
PatKind::Struct(_, ref fields, _) => {
307307
for pat in fields {
308-
bindings_impl(cx, pat, map);
308+
bindings_impl(cx, &pat.pat, map);
309309
}
310310
},
311311
PatKind::Slice(ref lhs, ref mid, ref rhs) => {

clippy_lints/src/dbg_macro.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ declare_lint_pass!(DbgMacro => [DBG_MACRO]);
3131

3232
impl EarlyLintPass for DbgMacro {
3333
fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &ast::Mac) {
34-
if mac.node.path == sym!(dbg) {
35-
if let Some(sugg) = tts_span(mac.node.tts.clone()).and_then(|span| snippet_opt(cx, span)) {
34+
if mac.path == sym!(dbg) {
35+
if let Some(sugg) = tts_span(mac.tts.clone()).and_then(|span| snippet_opt(cx, span)) {
3636
span_lint_and_sugg(
3737
cx,
3838
DBG_MACRO,

clippy_lints/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
445445
reg.register_early_lint_pass(box utils::internal_lints::ClippyLintsInternal);
446446
reg.register_late_lint_pass(box utils::internal_lints::CompilerLintFunctions::new());
447447
reg.register_late_lint_pass(box utils::internal_lints::LintWithoutLintPass::default());
448-
reg.register_late_lint_pass(box utils::internal_lints::OuterExpnInfoPass);
448+
reg.register_late_lint_pass(box utils::internal_lints::OuterExpnDataPass);
449449
reg.register_late_lint_pass(box utils::inspector::DeepCodeInspector);
450450
reg.register_late_lint_pass(box utils::author::Author);
451451
reg.register_late_lint_pass(box types::Types);
@@ -682,7 +682,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
682682
utils::internal_lints::CLIPPY_LINTS_INTERNAL,
683683
utils::internal_lints::COMPILER_LINT_FUNCTIONS,
684684
utils::internal_lints::LINT_WITHOUT_LINT_PASS,
685-
utils::internal_lints::OUTER_EXPN_EXPN_INFO,
685+
utils::internal_lints::OUTER_EXPN_EXPN_DATA,
686686
]);
687687

688688
reg.register_lint_group("clippy::all", Some("clippy"), vec![

clippy_lints/src/matches.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ declare_clippy_lint! {
4141
}
4242

4343
declare_clippy_lint! {
44-
/// **What it does:** Checks for matches with a two arms where an `if let else` will
44+
/// **What it does:** Checks for matches with two arms where an `if let else` will
4545
/// usually suffice.
4646
///
4747
/// **Why is this bad?** Just readability – `if let` nests less than a `match`.
@@ -76,7 +76,7 @@ declare_clippy_lint! {
7676
/// ```
7777
pub SINGLE_MATCH_ELSE,
7878
pedantic,
79-
"a match statement with a two arms where the second arm's pattern is a placeholder instead of a specific match pattern"
79+
"a match statement with two arms where the second arm's pattern is a placeholder instead of a specific match pattern"
8080
}
8181

8282
declare_clippy_lint! {

clippy_lints/src/misc.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -625,13 +625,17 @@ fn is_used(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
625625
/// generated by `#[derive(...)]` or the like).
626626
fn in_attributes_expansion(expr: &Expr) -> bool {
627627
use syntax::ext::hygiene::MacroKind;
628-
expr.span.ctxt().outer_expn_info().map_or(false, |info| {
629-
if let ExpnKind::Macro(MacroKind::Attr, _) = info.kind {
628+
if expr.span.from_expansion() {
629+
let data = expr.span.ctxt().outer_expn_data();
630+
631+
if let ExpnKind::Macro(MacroKind::Attr, _) = data.kind {
630632
true
631633
} else {
632634
false
633635
}
634-
})
636+
} else {
637+
false
638+
}
635639
}
636640

637641
/// Tests whether `res` is a variable defined outside a macro.

clippy_lints/src/misc_early.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl EarlyLintPass for MiscEarlyLints {
234234
.name;
235235

236236
for field in pfields {
237-
if let PatKind::Wild = field.node.pat.node {
237+
if let PatKind::Wild = field.pat.node {
238238
wilds += 1;
239239
}
240240
}
@@ -252,7 +252,7 @@ impl EarlyLintPass for MiscEarlyLints {
252252
let mut normal = vec![];
253253

254254
for field in pfields {
255-
match field.node.pat.node {
255+
match field.pat.node {
256256
PatKind::Wild => {},
257257
_ => {
258258
if let Ok(n) = cx.sess().source_map().span_to_snippet(field.span) {
@@ -262,7 +262,7 @@ impl EarlyLintPass for MiscEarlyLints {
262262
}
263263
}
264264
for field in pfields {
265-
if let PatKind::Wild = field.node.pat.node {
265+
if let PatKind::Wild = field.pat.node {
266266
wilds -= 1;
267267
if wilds > 0 {
268268
span_lint(

clippy_lints/src/non_expressive_names.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ impl<'a, 'tcx, 'b> Visitor<'tcx> for SimilarNamesNameVisitor<'a, 'tcx, 'b> {
131131
PatKind::Ident(_, ident, _) => self.check_ident(ident),
132132
PatKind::Struct(_, ref fields, _) => {
133133
for field in fields {
134-
if !field.node.is_shorthand {
135-
self.visit_pat(&field.node.pat);
134+
if !field.is_shorthand {
135+
self.visit_pat(&field.pat);
136136
}
137137
}
138138
},

clippy_lints/src/panic_unimplemented.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PanicUnimplemented {
6969

7070
fn get_outer_span(expr: &Expr) -> Span {
7171
if_chain! {
72-
if let Some(first) = expr.span.ctxt().outer_expn_info();
73-
if let Some(second) = first.call_site.ctxt().outer_expn_info();
72+
if expr.span.from_expansion();
73+
let first = expr.span.ctxt().outer_expn_data();
74+
if first.call_site.from_expansion();
75+
let second = first.call_site.ctxt().outer_expn_data();
7476
then {
7577
second.call_site
7678
} else {

clippy_lints/src/ranges.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ranges {
147147
}) = higher::range(cx, expr);
148148
if let Some(y) = y_plus_one(end);
149149
then {
150-
let span = expr.span
151-
.ctxt()
152-
.outer_expn_info()
153-
.map_or(expr.span, |info| info.call_site);
150+
let span = if expr.span.from_expansion() {
151+
expr.span
152+
.ctxt()
153+
.outer_expn_data()
154+
.call_site
155+
} else {
156+
expr.span
157+
};
154158
span_lint_and_then(
155159
cx,
156160
RANGE_PLUS_ONE,

clippy_lints/src/returns.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,11 @@ fn attr_is_cfg(attr: &ast::Attribute) -> bool {
317317

318318
// get the def site
319319
fn get_def(span: Span) -> Option<Span> {
320-
span.ctxt().outer_expn_info().and_then(|info| Some(info.def_site))
320+
if span.from_expansion() {
321+
Some(span.ctxt().outer_expn_data().def_site)
322+
} else {
323+
None
324+
}
321325
}
322326

323327
// is this expr a `()` unit?

clippy_lints/src/shadow.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -190,20 +190,20 @@ fn check_pat<'a, 'tcx>(
190190
if let Some(init_struct) = init {
191191
if let ExprKind::Struct(_, ref efields, _) = init_struct.node {
192192
for field in pfields {
193-
let name = field.node.ident.name;
193+
let name = field.ident.name;
194194
let efield = efields
195195
.iter()
196196
.find_map(|f| if f.ident.name == name { Some(&*f.expr) } else { None });
197-
check_pat(cx, &field.node.pat, efield, span, bindings);
197+
check_pat(cx, &field.pat, efield, span, bindings);
198198
}
199199
} else {
200200
for field in pfields {
201-
check_pat(cx, &field.node.pat, init, span, bindings);
201+
check_pat(cx, &field.pat, init, span, bindings);
202202
}
203203
}
204204
} else {
205205
for field in pfields {
206-
check_pat(cx, &field.node.pat, None, span, bindings);
206+
check_pat(cx, &field.pat, None, span, bindings);
207207
}
208208
}
209209
},

clippy_lints/src/utils/author.rs

+6
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,12 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
549549
println!(" if {}.len() == {};", fields_pat, fields.len());
550550
println!(" // unimplemented: field checks");
551551
},
552+
PatKind::Or(ref fields) => {
553+
let fields_pat = self.next("fields");
554+
println!("Or(ref {}) = {};", fields_pat, current);
555+
println!(" if {}.len() == {};", fields_pat, fields.len());
556+
println!(" // unimplemented: field checks");
557+
},
552558
PatKind::TupleStruct(ref path, ref fields, skip_pos) => {
553559
let path_pat = self.next("path");
554560
let fields_pat = self.next("fields");

clippy_lints/src/utils/inspector.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,12 @@ fn print_pat(cx: &LateContext<'_, '_>, pat: &hir::Pat, indent: usize) {
410410
print_pat(cx, inner, indent + 1);
411411
}
412412
},
413+
hir::PatKind::Or(ref fields) => {
414+
println!("{}Or", ind);
415+
for field in fields {
416+
print_pat(cx, field, indent + 1);
417+
}
418+
},
413419
hir::PatKind::Struct(ref path, ref fields, ignore) => {
414420
println!("{}Struct", ind);
415421
println!(
@@ -420,11 +426,11 @@ fn print_pat(cx: &LateContext<'_, '_>, pat: &hir::Pat, indent: usize) {
420426
println!("{}ignore leftover fields: {}", ind, ignore);
421427
println!("{}fields:", ind);
422428
for field in fields {
423-
println!("{} field name: {}", ind, field.node.ident.name);
424-
if field.node.is_shorthand {
429+
println!("{} field name: {}", ind, field.ident.name);
430+
if field.is_shorthand {
425431
println!("{} in shorthand notation", ind);
426432
}
427-
print_pat(cx, &field.node.pat, indent + 1);
433+
print_pat(cx, &field.pat, indent + 1);
428434
}
429435
},
430436
hir::PatKind::TupleStruct(ref path, ref fields, opt_dots_position) => {

0 commit comments

Comments
 (0)