]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/lint-unused-imports.rs
Fix invalid associated type rendering in rustdoc
[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 #![deny(unused_imports)]
12 #![allow(dead_code)]
13
14 use bar::c::cc as cal;
15
16 use std::mem::*;            // shouldn't get errors for not using
17                             // everything imported
18 use std::fmt::{};
19 //~^ ERROR unused import: `use std::fmt::{};`
20
21 // Should get errors for both 'Some' and 'None'
22 use std::option::Option::{Some, None};
23 //~^ ERROR unused imports: `None`, `Some`
24 //~| ERROR unused imports: `None`, `Some`
25
26 use test::A;       //~ ERROR unused import: `test::A`
27 // Be sure that if we just bring some methods into scope that they're also
28 // counted as being used.
29 use test::B;
30 // But only when actually used: do not get confused by the method with the same name.
31 use test::B2; //~ ERROR unused import: `test::B2`
32
33 // Make sure this import is warned about when at least one of its imported names
34 // is unused
35 use test2::{foo, bar}; //~ ERROR unused import: `bar`
36
37 mod test2 {
38     pub fn foo() {}
39     pub fn bar() {}
40 }
41
42 mod test {
43     pub trait A { fn a(&self) {} }
44     pub trait B { fn b(&self) {} }
45     pub trait B2 { fn b(&self) {} }
46     pub struct C;
47     impl A for C {}
48     impl B for C {}
49 }
50
51 mod foo {
52     pub struct Point{pub x: isize, pub y: isize}
53     pub struct Square{pub p: Point, pub h: usize, pub w: usize}
54 }
55
56 mod bar {
57     // Don't ignore on 'pub use' because we're not sure if it's used or not
58     pub use std::cmp::PartialEq;
59     pub struct Square;
60
61     pub mod c {
62         use foo::Point;
63         use foo::Square; //~ ERROR unused import: `foo::Square`
64         pub fn cc(_p: Point) -> super::Square {
65             fn f() -> super::Square {
66                 super::Square
67             }
68             f()
69         }
70     }
71
72     #[allow(unused_imports)]
73     mod foo {
74         use std::cmp::PartialEq;
75     }
76 }
77
78 fn g() {
79     use self::g; //~ ERROR unused import: `self::g`
80     fn f() {
81         self::g();
82     }
83 }
84
85 // c.f. issue #35135
86 #[allow(unused_variables)]
87 fn h() {
88     use test2::foo; //~ ERROR unused import: `test2::foo`
89     let foo = 0;
90 }
91
92 fn main() {
93     cal(foo::Point{x:3, y:9});
94     let mut a = 3;
95     let mut b = 4;
96     swap(&mut a, &mut b);
97     test::C.b();
98     let _a = foo();
99 }