]> git.proxmox.com Git - rustc.git/blob - src/test/ui/lint/dead-code/lint-dead-code-3.rs
New upstream version 1.63.0+dfsg1
[rustc.git] / src / test / ui / lint / dead-code / lint-dead-code-3.rs
1 #![allow(unused_variables)]
2 #![allow(non_camel_case_types)]
3 #![allow(clashing_extern_declarations)]
4 #![deny(dead_code)]
5
6 #![crate_type="lib"]
7
8
9 pub use extern_foo as x;
10 extern "C" {
11 pub fn extern_foo();
12 }
13
14 struct Foo; //~ ERROR: struct `Foo` is never constructed
15 impl Foo {
16 fn foo(&self) { //~ ERROR: associated function `foo` is never used
17 bar()
18 }
19 }
20
21 fn bar() { //~ ERROR: function `bar` is never used
22 fn baz() {}
23
24 Foo.foo();
25 baz();
26 }
27
28 // no warning
29 struct Foo2;
30 impl Foo2 { fn foo2(&self) { bar2() } }
31 fn bar2() {
32 fn baz2() {}
33
34 Foo2.foo2();
35 baz2();
36 }
37
38 pub fn pub_fn() {
39 let foo2_struct = Foo2;
40 foo2_struct.foo2();
41
42 blah::baz();
43 }
44
45 mod blah {
46 // not warned because it's used in the parameter of `free` and return of
47 // `malloc` below, which are also used.
48 enum c_void {}
49
50 extern "C" {
51 fn free(p: *const c_void);
52 fn malloc(size: usize) -> *const c_void;
53 }
54
55 pub fn baz() {
56 unsafe { free(malloc(4)); }
57 }
58 }
59
60 enum c_void {} //~ ERROR: enum `c_void` is never used
61 extern "C" {
62 fn free(p: *const c_void); //~ ERROR: function `free` is never used
63 }
64
65 // Check provided method
66 mod inner {
67 pub trait Trait {
68 fn f(&self) { f(); }
69 }
70
71 impl Trait for isize {}
72
73 fn f() {}
74 }
75
76 pub fn foo() {
77 let a: &dyn inner::Trait = &1_isize;
78 a.f();
79 }