about summary refs log tree commit diff
path: root/tests/ui/lint/dead-code/no-dead-code-for-static-trait-impl.rs
blob: 8d54eda6bcaae144087b3f7a2971737b5aa28b13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//! Regression test to ensure false positive `dead_code` diagnostic warnings are not triggered for
//! structs and enums that implement static trait functions or use associated constants.
//!
//! Aliased versions of all cases are also tested
//!
//! Issue: <https://github.com/rust-lang/rust/issues/23808>

//@ check-pass
#![deny(dead_code)]

trait Const {
    const C: ();
}

trait StaticFn {
    fn sfn();
}

macro_rules! impl_const {($($T:ident),*) => {$(
    impl Const for $T {
        const C: () = ();
    }
)*}}

macro_rules! impl_static_fn {($($T:ident),*) => {$(
    impl StaticFn for $T {
        fn sfn() {}
    }
)*}}

struct ConstStruct;
enum ConstEnum {}
struct AliasedConstStruct;
type AliasConstStruct = AliasedConstStruct;
enum AliasedConstEnum {}
type AliasConstEnum = AliasedConstEnum;

impl_const!(ConstStruct, ConstEnum, AliasedConstStruct, AliasedConstEnum);

struct StaticFnStruct;
enum StaticFnEnum {}
struct AliasedStaticFnStruct;
type AliasStaticFnStruct = AliasedStaticFnStruct;
enum AliasedStaticFnEnum {}
type AliasStaticFnEnum = AliasedStaticFnEnum;

impl_static_fn!(StaticFnStruct, StaticFnEnum, AliasedStaticFnStruct, AliasedStaticFnEnum);

fn main() {
    // Use the associated constant for all the types, they should be considered "used"
    let () = ConstStruct::C;
    let () = ConstEnum::C;
    let () = AliasConstStruct::C;
    let () = AliasConstEnum::C;

    // Use the associated static function for all the types, they should be considered "used"
    StaticFnStruct::sfn();
    StaticFnEnum::sfn();
    AliasStaticFnStruct::sfn();
    AliasStaticFnEnum::sfn();
}