]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/lint-unused-imports.rs
rollup merge of #19577: aidancully/master
[rust.git] / src / test / compile-fail / lint-unused-imports.rs
1 // Copyright 2012 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 #![feature(globs)]
12 #![deny(unused_imports)]
13 #![allow(dead_code)]
14
15 use bar::c::cc as cal;
16
17 use std::mem::*;            // shouldn't get errors for not using
18                             // everything imported
19
20 // Should get errors for both 'Some' and 'None'
21 use std::option::Option::{Some, None}; //~ ERROR unused import
22                                      //~^ ERROR unused import
23
24 use test::A;       //~ ERROR unused import
25 // Be sure that if we just bring some methods into scope that they're also
26 // counted as being used.
27 use test::B;
28
29 // Make sure this import is warned about when at least one of its imported names
30 // is unused
31 use test2::{foo, bar}; //~ ERROR unused import
32
33 mod test2 {
34     pub fn foo() {}
35     pub fn bar() {}
36 }
37
38 mod test {
39     pub trait A { fn a(&self) {} }
40     pub trait B { fn b(&self) {} }
41     pub struct C;
42     impl A for C {}
43     impl B for C {}
44 }
45
46 mod foo {
47     pub struct Point{pub x: int, pub y: int}
48     pub struct Square{pub p: Point, pub h: uint, pub w: uint}
49 }
50
51 mod bar {
52     // Don't ignore on 'pub use' because we're not sure if it's used or not
53     pub use std::cmp::PartialEq;
54
55     pub mod c {
56         use foo::Point;
57         use foo::Square; //~ ERROR unused import
58         pub fn cc(p: Point) -> int { return 2i * (p.x + p.y); }
59     }
60
61     #[allow(unused_imports)]
62     mod foo {
63         use std::cmp::PartialEq;
64     }
65 }
66
67 fn main() {
68     cal(foo::Point{x:3, y:9});
69     let mut a = 3i;
70     let mut b = 4i;
71     swap(&mut a, &mut b);
72     test::C.b();
73     let _a = foo();
74 }