2012-12-10 19:32:48 -06:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2014-03-21 20:05:05 -05:00
|
|
|
#![deny(unused_imports)]
|
|
|
|
#![allow(dead_code)]
|
2013-02-05 01:01:02 -06:00
|
|
|
|
2014-08-12 21:25:05 -05:00
|
|
|
use bar::c::cc as cal;
|
2011-11-10 09:31:55 -06:00
|
|
|
|
2014-01-31 14:35:36 -06:00
|
|
|
use std::mem::*; // shouldn't get errors for not using
|
|
|
|
// everything imported
|
2013-02-05 01:01:02 -06:00
|
|
|
|
2013-03-26 15:08:59 -05:00
|
|
|
// Should get errors for both 'Some' and 'None'
|
2014-11-28 10:57:41 -06:00
|
|
|
use std::option::Option::{Some, None}; //~ ERROR unused import
|
|
|
|
//~^ ERROR unused import
|
2013-02-05 01:01:02 -06:00
|
|
|
|
2013-10-13 20:48:47 -05:00
|
|
|
use test::A; //~ ERROR unused import
|
2013-02-05 11:29:45 -06:00
|
|
|
// Be sure that if we just bring some methods into scope that they're also
|
|
|
|
// counted as being used.
|
2013-10-13 20:48:47 -05:00
|
|
|
use test::B;
|
2016-04-19 08:43:10 -05:00
|
|
|
// But only when actually used: do not get confused by the method with the same name.
|
|
|
|
use test::B2; //~ ERROR unused import
|
2013-02-05 11:29:45 -06:00
|
|
|
|
2013-03-26 15:08:59 -05:00
|
|
|
// Make sure this import is warned about when at least one of its imported names
|
|
|
|
// is unused
|
2014-04-17 17:59:07 -05:00
|
|
|
use test2::{foo, bar}; //~ ERROR unused import
|
|
|
|
|
|
|
|
mod test2 {
|
|
|
|
pub fn foo() {}
|
|
|
|
pub fn bar() {}
|
|
|
|
}
|
2013-03-26 15:08:59 -05:00
|
|
|
|
2013-10-13 20:48:47 -05:00
|
|
|
mod test {
|
|
|
|
pub trait A { fn a(&self) {} }
|
|
|
|
pub trait B { fn b(&self) {} }
|
2016-04-19 08:43:10 -05:00
|
|
|
pub trait B2 { fn b(&self) {} }
|
2013-10-13 20:48:47 -05:00
|
|
|
pub struct C;
|
|
|
|
impl A for C {}
|
|
|
|
impl B for C {}
|
|
|
|
}
|
|
|
|
|
2011-11-10 09:31:55 -06:00
|
|
|
mod foo {
|
2015-01-08 04:54:35 -06:00
|
|
|
pub struct Point{pub x: isize, pub y: isize}
|
2015-01-08 05:02:42 -06:00
|
|
|
pub struct Square{pub p: Point, pub h: usize, pub w: usize}
|
2011-11-10 09:31:55 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
mod bar {
|
2013-02-25 10:37:17 -06:00
|
|
|
// Don't ignore on 'pub use' because we're not sure if it's used or not
|
2014-05-29 19:45:07 -05:00
|
|
|
pub use std::cmp::PartialEq;
|
2015-12-11 21:30:53 -06:00
|
|
|
pub struct Square;
|
2013-02-25 10:37:17 -06:00
|
|
|
|
2013-01-30 16:30:22 -06:00
|
|
|
pub mod c {
|
2013-02-05 01:01:02 -06:00
|
|
|
use foo::Point;
|
|
|
|
use foo::Square; //~ ERROR unused import
|
2015-12-11 21:30:53 -06:00
|
|
|
pub fn cc(_p: Point) -> super::Square {
|
2016-01-30 22:25:49 -06:00
|
|
|
fn f() -> super::Square {
|
|
|
|
super::Square
|
|
|
|
}
|
|
|
|
f()
|
2015-12-11 21:30:53 -06:00
|
|
|
}
|
2011-11-10 09:31:55 -06:00
|
|
|
}
|
2013-02-25 11:12:22 -06:00
|
|
|
|
|
|
|
#[allow(unused_imports)]
|
|
|
|
mod foo {
|
2014-05-29 19:45:07 -05:00
|
|
|
use std::cmp::PartialEq;
|
2013-02-25 11:12:22 -06:00
|
|
|
}
|
2011-11-10 09:31:55 -06:00
|
|
|
}
|
|
|
|
|
2016-02-24 02:46:25 -06:00
|
|
|
fn g() {
|
|
|
|
use self::g; //~ ERROR unused import
|
|
|
|
fn f() {
|
|
|
|
self::g();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-10 09:31:55 -06:00
|
|
|
fn main() {
|
2013-02-05 01:01:02 -06:00
|
|
|
cal(foo::Point{x:3, y:9});
|
2015-01-31 10:23:42 -06:00
|
|
|
let mut a = 3;
|
|
|
|
let mut b = 4;
|
2014-01-31 14:35:36 -06:00
|
|
|
swap(&mut a, &mut b);
|
2013-10-13 20:48:47 -05:00
|
|
|
test::C.b();
|
2014-04-17 17:59:07 -05:00
|
|
|
let _a = foo();
|
2011-11-10 09:31:55 -06:00
|
|
|
}
|