summaryrefslogtreecommitdiffstats
path: root/tests/ui/lint/dead-code/lint-dead-code-3.rs
blob: 20b568054dfb77acad430b0bb7828d0ddd04f3e6 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#![allow(unused_variables)]
#![allow(non_camel_case_types)]
#![allow(clashing_extern_declarations)]
#![deny(dead_code)]

#![crate_type="lib"]


pub use extern_foo as x;
extern "C" {
    pub fn extern_foo();
}

struct Foo; //~ ERROR: struct `Foo` is never constructed
impl Foo {
    fn foo(&self) { //~ ERROR: method `foo` is never used
        bar()
    }
}

fn bar() { //~ ERROR: function `bar` is never used
    fn baz() {}

    Foo.foo();
    baz();
}

// no warning
struct Foo2;
impl Foo2 { fn foo2(&self) { bar2() } }
fn bar2() {
    fn baz2() {}

    Foo2.foo2();
    baz2();
}

pub fn pub_fn() {
    let foo2_struct = Foo2;
    foo2_struct.foo2();

    blah::baz();
}

mod blah {
    // not warned because it's used in the parameter of `free` and return of
    // `malloc` below, which are also used.
    enum c_void {}

    extern "C" {
        fn free(p: *const c_void);
        fn malloc(size: usize) -> *const c_void;
    }

    pub fn baz() {
        unsafe { free(malloc(4)); }
    }
}

enum c_void {} //~ ERROR: enum `c_void` is never used
extern "C" {
    fn free(p: *const c_void); //~ ERROR: function `free` is never used
}

// Check provided method
mod inner {
    pub trait Trait {
        fn f(&self) { f(); }
    }

    impl Trait for isize {}

    fn f() {}
}

fn anon_const() -> [(); {
    fn blah() {} //~ ERROR: function `blah` is never used
    1
}] {
    [(); {
        fn blah() {} //~ ERROR: function `blah` is never used
        1
    }]
}

pub fn foo() {
    let a: &dyn inner::Trait = &1_isize;
    a.f();
    anon_const();
}