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