about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-10-15 17:57:10 +0000
committerbors <bors@rust-lang.org>2019-10-15 17:57:10 +0000
commit778ace37e5cc42f007b30c403d8ccc6790594458 (patch)
tree8a499aaea589cd4be9b70b5560daf859c4ed24ec
parent55e7818a06c8d83bead9c81e10e73ba33fb20890 (diff)
parent2f108079da42364273dc288aca6eee2d4cf98c4e (diff)
downloadrust-778ace37e5cc42f007b30c403d8ccc6790594458.tar.gz
rust-778ace37e5cc42f007b30c403d8ccc6790594458.zip
Auto merge of #4671 - flip1995:ice-4671, r=phansch
Fix ICE in `use_self` lint

The ICE is produced by building this span:
https://github.com/rust-lang/rust-clippy/blob/55e7818a06c8d83bead9c81e10e73ba33fb20890/clippy_lints/src/use_self.rs#L55-L60

`span` can start in the file the macro is defined in and end where the macro is called.

changelog: Fix ICE in `use_self` lint
-rw-r--r--.travis.yml12
-rw-r--r--clippy_lints/src/use_self.rs7
-rw-r--r--tests/ui/auxiliary/use_self_macro.rs15
-rw-r--r--tests/ui/ice-4671.rs21
4 files changed, 48 insertions, 7 deletions
diff --git a/.travis.yml b/.travis.yml
index 8f9c5e8f636..13ffb09a686 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -56,14 +56,14 @@ matrix:
       if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
     - env: INTEGRATION=rust-lang-nursery/chalk
       if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
-    # - env: INTEGRATION=rust-lang/rls
-    #   if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
+    - env: INTEGRATION=rust-lang/rls
+      if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
     - env: INTEGRATION=Geal/nom
       if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
     - env: INTEGRATION=rust-lang/rustfmt
       if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
-    # - env: INTEGRATION=hyperium/hyper
-    #   if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
+    - env: INTEGRATION=hyperium/hyper
+      if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
     - env: INTEGRATION=bluss/rust-itertools
       if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
     - env: INTEGRATION=serde-rs/serde
@@ -72,8 +72,8 @@ matrix:
       if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
     - env: INTEGRATION=rust-random/rand
       if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
-    # - env: INTEGRATION=rust-lang-nursery/futures-rs
-    #   if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
+    - env: INTEGRATION=rust-lang-nursery/futures-rs
+      if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
     - env: INTEGRATION=Marwes/combine
       if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
     - env: INTEGRATION=rust-lang-nursery/failure
diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs
index b0925737702..35e154aeaee 100644
--- a/clippy_lints/src/use_self.rs
+++ b/clippy_lints/src/use_self.rs
@@ -10,7 +10,7 @@ use rustc::{declare_lint_pass, declare_tool_lint};
 use rustc_errors::Applicability;
 use syntax_pos::symbol::kw;
 
-use crate::utils::span_lint_and_sugg;
+use crate::utils::{differing_macro_contexts, span_lint_and_sugg};
 
 declare_clippy_lint! {
     /// **What it does:** Checks for unnecessary repetition of structure name when a
@@ -56,6 +56,11 @@ fn span_use_self_lint(cx: &LateContext<'_, '_>, path: &Path, last_segment: Optio
 
     // Path segments only include actual path, no methods or fields.
     let last_path_span = last_segment.ident.span;
+
+    if differing_macro_contexts(path.span, last_path_span) {
+        return;
+    }
+
     // Only take path up to the end of last_path_span.
     let span = path.span.with_hi(last_path_span.hi());
 
diff --git a/tests/ui/auxiliary/use_self_macro.rs b/tests/ui/auxiliary/use_self_macro.rs
new file mode 100644
index 00000000000..a8a85b4baef
--- /dev/null
+++ b/tests/ui/auxiliary/use_self_macro.rs
@@ -0,0 +1,15 @@
+macro_rules! use_self {
+    (
+        impl $ty:ident {
+            fn func(&$this:ident) {
+                [fields($($field:ident)*)]
+            }
+        }
+    ) => (
+        impl  $ty {
+            fn func(&$this) {
+                let $ty { $($field),* } = $this;
+            }
+        }
+    )
+}
diff --git a/tests/ui/ice-4671.rs b/tests/ui/ice-4671.rs
new file mode 100644
index 00000000000..64e8e776941
--- /dev/null
+++ b/tests/ui/ice-4671.rs
@@ -0,0 +1,21 @@
+#![warn(clippy::use_self)]
+
+#[macro_use]
+#[path = "auxiliary/use_self_macro.rs"]
+mod use_self_macro;
+
+struct Foo {
+    a: u32,
+}
+
+use_self! {
+    impl Foo {
+        fn func(&self) {
+            [fields(
+                a
+            )]
+        }
+    }
+}
+
+fn main() {}