Skip to content

Commit 0a59c24

Browse files
committed
Auto merge of rust-lang#7428 - camsteffen:use-self-ice, r=flip1995
Fix use_self ICE changelog: Fix ICE rust-lang#7423 r? `@flip1995`
2 parents c195db7 + cb4670d commit 0a59c24

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

clippy_lints/src/use_self.rs

+3-14
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,8 @@ const SEGMENTS_MSG: &str = "segments should be composed of at least 1 element";
8787

8888
impl<'tcx> LateLintPass<'tcx> for UseSelf {
8989
fn check_item(&mut self, _cx: &LateContext<'_>, item: &Item<'_>) {
90-
if !is_item_interesting(item) {
91-
// This does two things:
92-
// 1) Reduce needless churn on `self.stack`
93-
// 2) Don't push `StackItem::NoCheck` when entering `ItemKind::OpaqueTy`,
94-
// in order to lint `foo() -> impl <..>`
90+
if matches!(item.kind, ItemKind::OpaqueTy(_)) {
91+
// skip over `ItemKind::OpaqueTy` in order to lint `foo() -> impl <..>`
9592
return;
9693
}
9794
// 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 {
119116
}
120117

121118
fn check_item_post(&mut self, _: &LateContext<'_>, item: &Item<'_>) {
122-
if is_item_interesting(item) {
119+
if !matches!(item.kind, ItemKind::OpaqueTy(_)) {
123120
self.stack.pop();
124121
}
125122
}
@@ -297,11 +294,3 @@ fn lint_path_to_variant(cx: &LateContext<'_>, path: &Path<'_>) {
297294
span_lint(cx, span);
298295
}
299296
}
300-
301-
fn is_item_interesting(item: &Item<'_>) -> bool {
302-
use rustc_hir::ItemKind::{Const, Enum, Fn, Impl, Static, Struct, Trait, Union};
303-
matches!(
304-
item.kind,
305-
Impl { .. } | Static(..) | Const(..) | Fn(..) | Enum(..) | Struct(..) | Union(..) | Trait(..)
306-
)
307-
}

tests/ui/crashes/ice-7423.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
pub trait Trait {
2+
fn f();
3+
}
4+
5+
impl Trait for usize {
6+
fn f() {
7+
extern "C" {
8+
fn g() -> usize;
9+
}
10+
}
11+
}
12+
13+
fn main() {}

0 commit comments

Comments
 (0)