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