about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-07-03 19:09:05 +0000
committerbors <bors@rust-lang.org>2021-07-03 19:09:05 +0000
commit0a59c24e8ac0b4cc00301f00d6975ae93dac64ec (patch)
tree54003cf4f698e970b5e1d3eec4804be2a02fb536
parentc195db7feeb5fb014a4961a0652e5baae61659d4 (diff)
parentcb4670deb37dac43dc36ad22d97479921a971f71 (diff)
downloadrust-0a59c24e8ac0b4cc00301f00d6975ae93dac64ec.tar.gz
rust-0a59c24e8ac0b4cc00301f00d6975ae93dac64ec.zip
Auto merge of #7428 - camsteffen:use-self-ice, r=flip1995
Fix use_self ICE

changelog: Fix ICE #7423

r? `@flip1995`
-rw-r--r--clippy_lints/src/use_self.rs17
-rw-r--r--tests/ui/crashes/ice-7423.rs13
2 files changed, 16 insertions, 14 deletions
diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs
index 906ac10f461..71117e967e3 100644
--- a/clippy_lints/src/use_self.rs
+++ b/clippy_lints/src/use_self.rs
@@ -87,11 +87,8 @@ const SEGMENTS_MSG: &str = "segments should be composed of at least 1 element";
 
 impl<'tcx> LateLintPass<'tcx> for UseSelf {
     fn check_item(&mut self, _cx: &LateContext<'_>, item: &Item<'_>) {
-        if !is_item_interesting(item) {
-            // This does two things:
-            //  1) Reduce needless churn on `self.stack`
-            //  2) Don't push `StackItem::NoCheck` when entering `ItemKind::OpaqueTy`,
-            //     in order to lint `foo() -> impl <..>`
+        if matches!(item.kind, ItemKind::OpaqueTy(_)) {
+            // skip over `ItemKind::OpaqueTy` in order to lint `foo() -> impl <..>`
             return;
         }
         // We push the self types of `impl`s on a stack here. Only the top type on the stack is
@@ -119,7 +116,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
     }
 
     fn check_item_post(&mut self, _: &LateContext<'_>, item: &Item<'_>) {
-        if is_item_interesting(item) {
+        if !matches!(item.kind, ItemKind::OpaqueTy(_)) {
             self.stack.pop();
         }
     }
@@ -297,11 +294,3 @@ fn lint_path_to_variant(cx: &LateContext<'_>, path: &Path<'_>) {
         span_lint(cx, span);
     }
 }
-
-fn is_item_interesting(item: &Item<'_>) -> bool {
-    use rustc_hir::ItemKind::{Const, Enum, Fn, Impl, Static, Struct, Trait, Union};
-    matches!(
-        item.kind,
-        Impl { .. } | Static(..) | Const(..) | Fn(..) | Enum(..) | Struct(..) | Union(..) | Trait(..)
-    )
-}
diff --git a/tests/ui/crashes/ice-7423.rs b/tests/ui/crashes/ice-7423.rs
new file mode 100644
index 00000000000..31340b012dd
--- /dev/null
+++ b/tests/ui/crashes/ice-7423.rs
@@ -0,0 +1,13 @@
+pub trait Trait {
+    fn f();
+}
+
+impl Trait for usize {
+    fn f() {
+        extern "C" {
+            fn g() -> usize;
+        }
+    }
+}
+
+fn main() {}