Skip to content

Commit 02a109e

Browse files
committed
Extends rules to impls for types which refer to adts, like &Foo things
1 parent 820b20e commit 02a109e

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

compiler/rustc_passes/src/dead.rs

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ fn adt_of<'tcx>(ty: &hir::Ty<'tcx>) -> Option<(LocalDefId, DefKind)> {
5555
None
5656
}
5757
}
58+
TyKind::Slice(ty) | TyKind::Array(ty, _) => adt_of(ty),
59+
TyKind::Ptr(ty) | TyKind::Ref(_, ty) => adt_of(ty.ty),
5860
_ => None,
5961
}
6062
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#![deny(dead_code)]
2+
3+
struct Foo; //~ ERROR struct `Foo` is never constructed
4+
5+
trait Trait { //~ ERROR trait `Trait` is never used
6+
fn foo(&self) {}
7+
}
8+
9+
impl Trait for Foo {}
10+
11+
impl Trait for [Foo] {}
12+
impl<const N: usize> Trait for [Foo; N] {}
13+
14+
impl Trait for *const Foo {}
15+
impl Trait for *mut Foo {}
16+
17+
impl Trait for &Foo {}
18+
impl Trait for &&Foo {}
19+
impl Trait for &mut Foo {}
20+
21+
impl Trait for [&Foo] {}
22+
impl Trait for &[Foo] {}
23+
impl Trait for &*const Foo {}
24+
25+
pub trait Trait2 {
26+
fn foo(&self) {}
27+
}
28+
29+
impl Trait2 for Foo {}
30+
31+
impl Trait2 for [Foo] {}
32+
impl<const N: usize> Trait2 for [Foo; N] {}
33+
34+
impl Trait2 for *const Foo {}
35+
impl Trait2 for *mut Foo {}
36+
37+
impl Trait2 for &Foo {}
38+
impl Trait2 for &&Foo {}
39+
impl Trait2 for &mut Foo {}
40+
41+
impl Trait2 for [&Foo] {}
42+
impl Trait2 for &[Foo] {}
43+
impl Trait2 for &*const Foo {}
44+
45+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: struct `Foo` is never constructed
2+
--> $DIR/unused-impl-for-non-adts.rs:3:8
3+
|
4+
LL | struct Foo;
5+
| ^^^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/unused-impl-for-non-adts.rs:1:9
9+
|
10+
LL | #![deny(dead_code)]
11+
| ^^^^^^^^^
12+
13+
error: trait `Trait` is never used
14+
--> $DIR/unused-impl-for-non-adts.rs:5:7
15+
|
16+
LL | trait Trait {
17+
| ^^^^^
18+
19+
error: aborting due to 2 previous errors
20+

0 commit comments

Comments
 (0)