File tree 3 files changed +80
-2
lines changed
compiler/rustc_passes/src
3 files changed +80
-2
lines changed Original file line number Diff line number Diff line change @@ -472,7 +472,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
472
472
&& let ItemKind :: Impl ( impl_ref) =
473
473
self . tcx . hir ( ) . expect_item ( local_impl_id) . kind
474
474
{
475
- if matches ! ( trait_item. kind, hir:: TraitItemKind :: Fn ( ..) )
475
+ if ! matches ! ( trait_item. kind, hir:: TraitItemKind :: Type ( ..) )
476
476
&& !ty_ref_to_pub_struct ( self . tcx , impl_ref. self_ty )
477
477
. ty_and_all_fields_are_public
478
478
{
@@ -802,7 +802,7 @@ fn check_item<'tcx>(
802
802
// And we access the Map here to get HirId from LocalDefId
803
803
for local_def_id in local_def_ids {
804
804
// check the function may construct Self
805
- let mut may_construct_self = true ;
805
+ let mut may_construct_self = false ;
806
806
if let Some ( fn_sig) =
807
807
tcx. hir ( ) . fn_sig_by_hir_id ( tcx. local_def_id_to_hir_id ( local_def_id) )
808
808
{
Original file line number Diff line number Diff line change
1
+ #![ deny( dead_code) ]
2
+
3
+ struct T1 ; //~ ERROR struct `T1` is never constructed
4
+ pub struct T2 ( i32 ) ; //~ ERROR struct `T2` is never constructed
5
+ struct T3 ;
6
+
7
+ trait Trait1 { //~ ERROR trait `Trait1` is never used
8
+ const UNUSED : i32 ;
9
+ fn unused ( & self ) { }
10
+ fn construct_self ( ) -> Self ;
11
+ }
12
+
13
+ pub trait Trait2 {
14
+ const USED : i32 ;
15
+ fn used ( & self ) { }
16
+ }
17
+
18
+ pub trait Trait3 {
19
+ const USED : i32 ;
20
+ fn construct_self ( ) -> Self ;
21
+ }
22
+
23
+ impl Trait1 for T1 {
24
+ const UNUSED : i32 = 0 ;
25
+ fn construct_self ( ) -> Self {
26
+ Self
27
+ }
28
+ }
29
+
30
+ impl Trait1 for T2 {
31
+ const UNUSED : i32 = 0 ;
32
+ fn construct_self ( ) -> Self {
33
+ T2 ( 0 )
34
+ }
35
+ }
36
+
37
+ impl Trait2 for T1 {
38
+ const USED : i32 = 0 ;
39
+ }
40
+
41
+ impl Trait2 for T2 {
42
+ const USED : i32 = 0 ;
43
+ }
44
+
45
+ impl Trait3 for T3 {
46
+ const USED : i32 = 0 ;
47
+ fn construct_self ( ) -> Self {
48
+ Self
49
+ }
50
+ }
51
+
52
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ error: struct `T1` is never constructed
2
+ --> $DIR/unused-adt-impl-pub-trait-with-assoc-const.rs:3:8
3
+ |
4
+ LL | struct T1;
5
+ | ^^
6
+ |
7
+ note: the lint level is defined here
8
+ --> $DIR/unused-adt-impl-pub-trait-with-assoc-const.rs:1:9
9
+ |
10
+ LL | #![deny(dead_code)]
11
+ | ^^^^^^^^^
12
+
13
+ error: struct `T2` is never constructed
14
+ --> $DIR/unused-adt-impl-pub-trait-with-assoc-const.rs:4:12
15
+ |
16
+ LL | pub struct T2(i32);
17
+ | ^^
18
+
19
+ error: trait `Trait1` is never used
20
+ --> $DIR/unused-adt-impl-pub-trait-with-assoc-const.rs:7:7
21
+ |
22
+ LL | trait Trait1 {
23
+ | ^^^^^^
24
+
25
+ error: aborting due to 3 previous errors
26
+
You can’t perform that action at this time.
0 commit comments