]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/lint-dead-code-3.rs
95c1d131b7b2d082bad29fd674ec289a61c9e360
[rust.git] / src / test / compile-fail / lint-dead-code-3.rs
1 // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![allow(unused_variable)]
12 #![allow(non_camel_case_types)]
13 #![deny(dead_code)]
14
15 #![crate_type="lib"]
16
17 extern crate libc;
18
19 struct Foo; //~ ERROR: code is never used
20 impl Foo {
21     fn foo(&self) { //~ ERROR: code is never used
22         bar()
23     }
24 }
25
26 fn bar() { //~ ERROR: code is never used
27     fn baz() {} //~ ERROR: code is never used
28
29     Foo.foo();
30     baz();
31 }
32
33 // no warning
34 struct Foo2;
35 impl Foo2 { fn foo2(&self) { bar2() } }
36 fn bar2() {
37     fn baz2() {}
38
39     Foo2.foo2();
40     baz2();
41 }
42
43 pub fn pub_fn() {
44     let foo2_struct = Foo2;
45     foo2_struct.foo2();
46
47     blah::baz();
48 }
49
50 mod blah {
51     use libc::size_t;
52     // not warned because it's used in the parameter of `free` and return of
53     // `malloc` below, which are also used.
54     enum c_void {}
55
56     extern {
57         fn free(p: *c_void);
58         fn malloc(size: size_t) -> *c_void;
59     }
60
61     pub fn baz() {
62         unsafe { free(malloc(4)); }
63     }
64 }
65
66 enum c_void {} //~ ERROR: code is never used
67 extern {
68     fn free(p: *c_void); //~ ERROR: code is never used
69 }
70
71 // Check provided method
72 mod inner {
73     pub trait Trait {
74         fn f(&self) { f(); }
75     }
76
77     impl Trait for int {}
78
79     fn f() {}
80 }
81
82 pub fn foo() {
83     let a = &1 as &inner::Trait;
84     a.f();
85 }