2014-03-21 18:05:05 -07:00
|
|
|
#![deny(unused_imports)]
|
|
|
|
#![allow(dead_code)]
|
2013-02-05 02:01:02 -05:00
|
|
|
|
2014-08-12 19:25:05 -07:00
|
|
|
use bar::c::cc as cal;
|
2011-11-10 23:31:55 +08:00
|
|
|
|
2014-02-01 04:35:36 +08:00
|
|
|
use std::mem::*; // shouldn't get errors for not using
|
|
|
|
// everything imported
|
2016-11-30 00:07:31 -08:00
|
|
|
use std::fmt::{};
|
2018-12-09 17:40:49 +01:00
|
|
|
//~^ ERROR unused import: `std::fmt::{}`
|
2013-02-05 02:01:02 -05:00
|
|
|
|
2013-03-26 16:08:59 -04:00
|
|
|
// Should get errors for both 'Some' and 'None'
|
2016-10-25 23:24:09 -07:00
|
|
|
use std::option::Option::{Some, None};
|
|
|
|
//~^ ERROR unused imports: `None`, `Some`
|
2013-02-05 02:01:02 -05:00
|
|
|
|
2016-10-24 22:57:33 -07:00
|
|
|
use test::A; //~ ERROR unused import: `test::A`
|
2013-02-05 12:29:45 -05:00
|
|
|
// Be sure that if we just bring some methods into scope that they're also
|
|
|
|
// counted as being used.
|
2013-10-13 18:48:47 -07:00
|
|
|
use test::B;
|
2016-04-19 22:43:10 +09:00
|
|
|
// But only when actually used: do not get confused by the method with the same name.
|
2016-10-24 22:57:33 -07:00
|
|
|
use test::B2; //~ ERROR unused import: `test::B2`
|
2013-02-05 12:29:45 -05:00
|
|
|
|
2013-03-26 16:08:59 -04:00
|
|
|
// Make sure this import is warned about when at least one of its imported names
|
|
|
|
// is unused
|
2016-10-24 22:57:33 -07:00
|
|
|
use test2::{foo, bar}; //~ ERROR unused import: `bar`
|
2014-04-17 15:59:07 -07:00
|
|
|
|
|
|
|
mod test2 {
|
|
|
|
pub fn foo() {}
|
|
|
|
pub fn bar() {}
|
|
|
|
}
|
2013-03-26 16:08:59 -04:00
|
|
|
|
2013-10-13 18:48:47 -07:00
|
|
|
mod test {
|
|
|
|
pub trait A { fn a(&self) {} }
|
|
|
|
pub trait B { fn b(&self) {} }
|
2016-04-19 22:43:10 +09:00
|
|
|
pub trait B2 { fn b(&self) {} }
|
2013-10-13 18:48:47 -07:00
|
|
|
pub struct C;
|
|
|
|
impl A for C {}
|
|
|
|
impl B for C {}
|
|
|
|
}
|
|
|
|
|
2011-11-10 23:31:55 +08:00
|
|
|
mod foo {
|
2015-01-08 21:54:35 +11:00
|
|
|
pub struct Point{pub x: isize, pub y: isize}
|
2015-01-08 22:02:42 +11:00
|
|
|
pub struct Square{pub p: Point, pub h: usize, pub w: usize}
|
2011-11-10 23:31:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
mod bar {
|
2013-02-25 11:37:17 -05:00
|
|
|
// Don't ignore on 'pub use' because we're not sure if it's used or not
|
2014-05-29 17:45:07 -07:00
|
|
|
pub use std::cmp::PartialEq;
|
2015-12-12 03:30:53 +00:00
|
|
|
pub struct Square;
|
2013-02-25 11:37:17 -05:00
|
|
|
|
2013-01-30 14:30:22 -08:00
|
|
|
pub mod c {
|
2013-02-05 02:01:02 -05:00
|
|
|
use foo::Point;
|
2016-10-24 22:57:33 -07:00
|
|
|
use foo::Square; //~ ERROR unused import: `foo::Square`
|
2015-12-12 03:30:53 +00:00
|
|
|
pub fn cc(_p: Point) -> super::Square {
|
2016-01-31 04:25:49 +00:00
|
|
|
fn f() -> super::Square {
|
|
|
|
super::Square
|
|
|
|
}
|
|
|
|
f()
|
2015-12-12 03:30:53 +00:00
|
|
|
}
|
2011-11-10 23:31:55 +08:00
|
|
|
}
|
2013-02-25 12:12:22 -05:00
|
|
|
|
|
|
|
#[allow(unused_imports)]
|
|
|
|
mod foo {
|
2014-05-29 17:45:07 -07:00
|
|
|
use std::cmp::PartialEq;
|
2013-02-25 12:12:22 -05:00
|
|
|
}
|
2011-11-10 23:31:55 +08:00
|
|
|
}
|
|
|
|
|
2016-02-24 08:46:25 +00:00
|
|
|
fn g() {
|
2016-10-24 22:57:33 -07:00
|
|
|
use self::g; //~ ERROR unused import: `self::g`
|
2019-03-17 11:38:38 +01:00
|
|
|
//~^ ERROR the item `g` is imported redundantly
|
2016-02-24 08:46:25 +00:00
|
|
|
fn f() {
|
|
|
|
self::g();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-27 02:59:49 +00:00
|
|
|
// cf. issue #35135.
|
2016-07-29 15:19:29 +00:00
|
|
|
#[allow(unused_variables)]
|
|
|
|
fn h() {
|
2016-10-24 22:57:33 -07:00
|
|
|
use test2::foo; //~ ERROR unused import: `test2::foo`
|
2019-03-17 11:38:38 +01:00
|
|
|
//~^ ERROR the item `foo` is imported redundantly
|
2016-07-29 15:19:29 +00:00
|
|
|
let foo = 0;
|
|
|
|
}
|
|
|
|
|
2011-11-10 23:31:55 +08:00
|
|
|
fn main() {
|
2013-02-05 02:01:02 -05:00
|
|
|
cal(foo::Point{x:3, y:9});
|
2015-01-31 17:23:42 +01:00
|
|
|
let mut a = 3;
|
|
|
|
let mut b = 4;
|
2014-02-01 04:35:36 +08:00
|
|
|
swap(&mut a, &mut b);
|
2013-10-13 18:48:47 -07:00
|
|
|
test::C.b();
|
2014-04-17 15:59:07 -07:00
|
|
|
let _a = foo();
|
2011-11-10 23:31:55 +08:00
|
|
|
}
|