2014-03-21 18:05:05 -07:00
|
|
|
#![no_std]
|
2014-10-27 15:37:07 -07:00
|
|
|
#![allow(unused_variables)]
|
2014-03-21 18:05:05 -07:00
|
|
|
#![allow(non_camel_case_types)]
|
2014-10-27 15:37:07 -07:00
|
|
|
#![allow(non_upper_case_globals)]
|
2014-03-21 18:05:05 -07:00
|
|
|
#![deny(dead_code)]
|
2013-12-08 02:55:27 -05:00
|
|
|
|
2014-03-21 18:05:05 -07:00
|
|
|
#![crate_type="lib"]
|
2013-12-08 02:55:27 -05:00
|
|
|
|
2014-10-06 21:16:35 -07:00
|
|
|
pub use foo2::Bar2;
|
2014-04-03 13:38:45 +13:00
|
|
|
|
2013-12-08 02:55:27 -05:00
|
|
|
mod foo {
|
2022-06-10 12:14:24 +09:00
|
|
|
pub struct Bar; //~ ERROR: struct `Bar` is never constructed
|
2013-12-08 02:55:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
mod foo2 {
|
|
|
|
pub struct Bar2;
|
|
|
|
}
|
|
|
|
|
2015-01-08 21:54:35 +11:00
|
|
|
pub static pub_static: isize = 0;
|
2022-06-10 12:14:24 +09:00
|
|
|
static priv_static: isize = 0; //~ ERROR: static `priv_static` is never used
|
2015-01-08 21:54:35 +11:00
|
|
|
const used_static: isize = 0;
|
|
|
|
pub static used_static2: isize = used_static;
|
|
|
|
const USED_STATIC: isize = 0;
|
|
|
|
const STATIC_USED_IN_ENUM_DISCRIMINANT: isize = 10;
|
2013-12-08 02:55:27 -05:00
|
|
|
|
2015-01-08 21:54:35 +11:00
|
|
|
pub const pub_const: isize = 0;
|
2022-06-10 12:14:24 +09:00
|
|
|
const priv_const: isize = 0; //~ ERROR: constant `priv_const` is never used
|
2015-01-08 21:54:35 +11:00
|
|
|
const used_const: isize = 0;
|
|
|
|
pub const used_const2: isize = used_const;
|
|
|
|
const USED_CONST: isize = 1;
|
|
|
|
const CONST_USED_IN_ENUM_DISCRIMINANT: isize = 11;
|
2014-10-10 08:31:13 -07:00
|
|
|
|
2014-06-25 12:47:34 -07:00
|
|
|
pub type typ = *const UsedStruct4;
|
2014-06-22 19:53:56 +02:00
|
|
|
pub struct PubStruct;
|
2022-06-10 12:14:24 +09:00
|
|
|
struct PrivStruct; //~ ERROR: struct `PrivStruct` is never constructed
|
2014-06-06 15:51:42 +02:00
|
|
|
struct UsedStruct1 {
|
|
|
|
#[allow(dead_code)]
|
2015-01-08 21:54:35 +11:00
|
|
|
x: isize
|
2014-06-06 15:51:42 +02:00
|
|
|
}
|
2015-01-08 21:54:35 +11:00
|
|
|
struct UsedStruct2(isize);
|
2013-12-08 02:55:27 -05:00
|
|
|
struct UsedStruct3;
|
2015-11-21 17:39:15 +03:00
|
|
|
pub struct UsedStruct4;
|
2013-12-08 02:55:27 -05:00
|
|
|
// this struct is never used directly, but its method is, so we don't want
|
|
|
|
// to warn it
|
|
|
|
struct SemiUsedStruct;
|
|
|
|
impl SemiUsedStruct {
|
|
|
|
fn la_la_la() {}
|
|
|
|
}
|
2013-12-16 02:15:00 -05:00
|
|
|
struct StructUsedAsField;
|
2014-09-19 12:30:07 -07:00
|
|
|
pub struct StructUsedInEnum;
|
2013-12-16 18:01:36 -05:00
|
|
|
struct StructUsedInGeneric;
|
2013-12-16 02:15:00 -05:00
|
|
|
pub struct PubStruct2 {
|
2014-06-06 15:51:42 +02:00
|
|
|
#[allow(dead_code)]
|
2014-06-25 12:47:34 -07:00
|
|
|
struct_used_as_field: *const StructUsedAsField
|
2013-12-16 02:15:00 -05:00
|
|
|
}
|
2013-12-08 02:55:27 -05:00
|
|
|
|
|
|
|
pub enum pub_enum { foo1, bar1 }
|
2014-06-25 12:47:34 -07:00
|
|
|
pub enum pub_enum2 { a(*const StructUsedInEnum) }
|
2014-10-10 08:49:12 -07:00
|
|
|
pub enum pub_enum3 {
|
|
|
|
Foo = STATIC_USED_IN_ENUM_DISCRIMINANT,
|
|
|
|
Bar = CONST_USED_IN_ENUM_DISCRIMINANT,
|
|
|
|
}
|
2014-09-20 13:26:10 +02:00
|
|
|
|
2022-06-10 12:14:24 +09:00
|
|
|
enum priv_enum { foo2, bar2 } //~ ERROR: enum `priv_enum` is never used
|
2014-09-20 13:26:10 +02:00
|
|
|
enum used_enum {
|
|
|
|
foo3,
|
2022-06-10 12:14:24 +09:00
|
|
|
bar3 //~ ERROR variant `bar3` is never constructed
|
2014-09-20 13:26:10 +02:00
|
|
|
}
|
2013-12-08 02:55:27 -05:00
|
|
|
|
2013-12-16 18:01:36 -05:00
|
|
|
fn f<T>() {}
|
|
|
|
|
2013-12-11 20:49:46 -05:00
|
|
|
pub fn pub_fn() {
|
|
|
|
used_fn();
|
|
|
|
let used_struct1 = UsedStruct1 { x: 1 };
|
|
|
|
let used_struct2 = UsedStruct2(1);
|
|
|
|
let used_struct3 = UsedStruct3;
|
2014-11-06 00:05:53 -08:00
|
|
|
let e = used_enum::foo3;
|
2013-12-11 20:49:46 -05:00
|
|
|
SemiUsedStruct::la_la_la();
|
|
|
|
|
2015-01-31 17:23:42 +01:00
|
|
|
let i = 1;
|
2013-12-11 20:49:46 -05:00
|
|
|
match i {
|
|
|
|
USED_STATIC => (),
|
2014-10-10 08:49:12 -07:00
|
|
|
USED_CONST => (),
|
2013-12-11 20:49:46 -05:00
|
|
|
_ => ()
|
|
|
|
}
|
2013-12-16 18:01:36 -05:00
|
|
|
f::<StructUsedInGeneric>();
|
2013-12-11 20:49:46 -05:00
|
|
|
}
|
2022-06-10 12:14:24 +09:00
|
|
|
fn priv_fn() { //~ ERROR: function `priv_fn` is never used
|
2013-12-11 20:49:46 -05:00
|
|
|
let unused_struct = PrivStruct;
|
|
|
|
}
|
|
|
|
fn used_fn() {}
|
|
|
|
|
2022-06-10 12:14:24 +09:00
|
|
|
fn foo() { //~ ERROR: function `foo` is never used
|
2013-12-08 02:55:27 -05:00
|
|
|
bar();
|
2014-11-06 00:05:53 -08:00
|
|
|
let unused_enum = priv_enum::foo2;
|
2013-12-08 02:55:27 -05:00
|
|
|
}
|
|
|
|
|
2022-06-10 12:14:24 +09:00
|
|
|
fn bar() { //~ ERROR: function `bar` is never used
|
2013-12-08 02:55:27 -05:00
|
|
|
foo();
|
|
|
|
}
|
2014-01-11 03:21:53 -05:00
|
|
|
|
2022-06-10 12:14:24 +09:00
|
|
|
fn baz() -> impl Copy { //~ ERROR: function `baz` is never used
|
2018-10-04 12:38:06 +02:00
|
|
|
"I'm unused, too"
|
|
|
|
}
|
|
|
|
|
2014-01-11 03:21:53 -05:00
|
|
|
// Code with #[allow(dead_code)] should be marked live (and thus anything it
|
|
|
|
// calls is marked live)
|
|
|
|
#[allow(dead_code)]
|
|
|
|
fn g() { h(); }
|
|
|
|
fn h() {}
|