]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/lint-dead-code-3.rs
Imported Upstream version 1.0.0~beta
[rustc.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_variables)]
12 #![allow(non_camel_case_types)]
13 #![deny(dead_code)]
14 #![feature(libc)]
15
16 #![crate_type="lib"]
17
18 extern crate libc;
19
20 pub use extern_foo as x;
21 extern {
22 pub fn extern_foo();
23 }
24
25 struct Foo; //~ ERROR: struct is never used
26 impl Foo {
27 fn foo(&self) { //~ ERROR: method is never used
28 bar()
29 }
30 }
31
32 fn bar() { //~ ERROR: function is never used
33 fn baz() {} //~ ERROR: function is never used
34
35 Foo.foo();
36 baz();
37 }
38
39 // no warning
40 struct Foo2;
41 impl Foo2 { fn foo2(&self) { bar2() } }
42 fn bar2() {
43 fn baz2() {}
44
45 Foo2.foo2();
46 baz2();
47 }
48
49 pub fn pub_fn() {
50 let foo2_struct = Foo2;
51 foo2_struct.foo2();
52
53 blah::baz();
54 }
55
56 mod blah {
57 use libc::size_t;
58 // not warned because it's used in the parameter of `free` and return of
59 // `malloc` below, which are also used.
60 enum c_void {}
61
62 extern {
63 fn free(p: *const c_void);
64 fn malloc(size: size_t) -> *const c_void;
65 }
66
67 pub fn baz() {
68 unsafe { free(malloc(4)); }
69 }
70 }
71
72 enum c_void {} //~ ERROR: enum is never used
73 extern {
74 fn free(p: *const c_void); //~ ERROR: foreign function is never used
75 }
76
77 // Check provided method
78 mod inner {
79 pub trait Trait {
80 fn f(&self) { f(); }
81 }
82
83 impl Trait for isize {}
84
85 fn f() {}
86 }
87
88 pub fn foo() {
89 let a: &inner::Trait = &1_isize;
90 a.f();
91 }