diff options
| author | Kiet Tran <ktt3ja@gmail.com> | 2013-12-08 02:55:27 -0500 |
|---|---|---|
| committer | Kiet Tran <ktt3ja@gmail.com> | 2013-12-08 02:55:27 -0500 |
| commit | c06dd0e0afb4b78ab4e482a7488adcf1c865bd19 (patch) | |
| tree | 4850d80648a57d527feda65f921bdf47940111f8 /src/test/compile-fail | |
| parent | 49b751dda19af57a2545a67879dd217e601b84c6 (diff) | |
| download | rust-c06dd0e0afb4b78ab4e482a7488adcf1c865bd19.tar.gz rust-c06dd0e0afb4b78ab4e482a7488adcf1c865bd19.zip | |
Add dead-code warning pass
Diffstat (limited to 'src/test/compile-fail')
26 files changed, 197 insertions, 0 deletions
diff --git a/src/test/compile-fail/issue-2150.rs b/src/test/compile-fail/issue-2150.rs index 64344ab4277..2c54b622021 100644 --- a/src/test/compile-fail/issue-2150.rs +++ b/src/test/compile-fail/issue-2150.rs @@ -10,6 +10,7 @@ #[deny(unreachable_code)]; #[allow(unused_variable)]; +#[allow(dead_code)]; fn fail_len(v: ~[int]) -> uint { let mut i = 3; diff --git a/src/test/compile-fail/issue-6804.rs b/src/test/compile-fail/issue-6804.rs index c2e0c40d8ca..23d9f3199c1 100644 --- a/src/test/compile-fail/issue-6804.rs +++ b/src/test/compile-fail/issue-6804.rs @@ -1,3 +1,5 @@ +#[allow(dead_code)]; + // Matching against NaN should result in a warning use std::f64::NAN; diff --git a/src/test/compile-fail/issue-7246.rs b/src/test/compile-fail/issue-7246.rs index dacc31a573a..ce31ac2e8fa 100644 --- a/src/test/compile-fail/issue-7246.rs +++ b/src/test/compile-fail/issue-7246.rs @@ -9,6 +9,8 @@ // except according to those terms. #[deny(unreachable_code)]; +#[allow(dead_code)]; + use std::ptr; pub unsafe fn g() { return; diff --git a/src/test/compile-fail/lint-change-warnings.rs b/src/test/compile-fail/lint-change-warnings.rs index 977abc4dc0d..e9985430adf 100644 --- a/src/test/compile-fail/lint-change-warnings.rs +++ b/src/test/compile-fail/lint-change-warnings.rs @@ -9,6 +9,7 @@ // except according to those terms. #[deny(warnings)]; +#[allow(dead_code)]; fn main() { while true {} //~ ERROR: infinite diff --git a/src/test/compile-fail/lint-ctypes-enum.rs b/src/test/compile-fail/lint-ctypes-enum.rs index 857e3bb4b8d..2e47695f0fc 100644 --- a/src/test/compile-fail/lint-ctypes-enum.rs +++ b/src/test/compile-fail/lint-ctypes-enum.rs @@ -9,6 +9,7 @@ // except according to those terms. #[deny(ctypes)]; +#[allow(dead_code)]; enum Z { } enum U { A } diff --git a/src/test/compile-fail/lint-dead-code-1.rs b/src/test/compile-fail/lint-dead-code-1.rs new file mode 100644 index 00000000000..7d7cbce6e89 --- /dev/null +++ b/src/test/compile-fail/lint-dead-code-1.rs @@ -0,0 +1,69 @@ +// Copyright 2013 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. + +#[allow(unused_variable)]; +#[deny(dead_code)]; + +#[crate_type="lib"]; + +pub use foo2::Bar2; +mod foo { + pub struct Bar; //~ ERROR: code is never used +} + +mod foo2 { + pub struct Bar2; +} + +pub static pub_static: int = 0; +static priv_static: int = 0; //~ ERROR: code is never used +static used_static: int = 0; +pub static used_static2: int = used_static; + +pub fn pub_fn() { + used_fn(); + let used_struct1 = UsedStruct1 { x: 1 }; + let used_struct2 = UsedStruct2(1); + let used_struct3 = UsedStruct3; + let e = foo3; + SemiUsedStruct::la_la_la(); + +} +fn priv_fn() { //~ ERROR: code is never used + let unused_struct = PrivStruct; +} +fn used_fn() {} + +pub type typ = ~UsedStruct4; +pub struct PubStruct(); +struct PrivStruct; //~ ERROR: code is never used +struct UsedStruct1 { x: int } +struct UsedStruct2(int); +struct UsedStruct3; +struct UsedStruct4; +// 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() {} +} + +pub enum pub_enum { foo1, bar1 } +enum priv_enum { foo2, bar2 } //~ ERROR: code is never used +enum used_enum { foo3, bar3 } + +fn foo() { //~ ERROR: code is never used + bar(); + let unused_enum = foo2; +} + +fn bar() { //~ ERROR: code is never used + foo(); +} diff --git a/src/test/compile-fail/lint-dead-code-2.rs b/src/test/compile-fail/lint-dead-code-2.rs new file mode 100644 index 00000000000..663e7890bbe --- /dev/null +++ b/src/test/compile-fail/lint-dead-code-2.rs @@ -0,0 +1,50 @@ +// Copyright 2013 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. + +#[allow(unused_variable)]; +#[deny(dead_code)]; + +struct Foo; + +trait Bar { + fn bar1(&self); + fn bar2(&self) { + self.bar1(); + } +} + +impl Bar for Foo { + fn bar1(&self) { + live_fn(); + } +} + +fn live_fn() {} + +fn dead_fn() {} //~ ERROR: code is never used + +#[main] +fn dead_fn2() {} //~ ERROR: code is never used + +fn used_fn() {} + +#[start] +fn start(_: int, _: **u8) -> int { + used_fn(); + let foo = Foo; + foo.bar2(); + 0 +} + +// this is not main +fn main() { //~ ERROR: code is never used + dead_fn(); + dead_fn2(); +} diff --git a/src/test/compile-fail/lint-dead-code-3.rs b/src/test/compile-fail/lint-dead-code-3.rs new file mode 100644 index 00000000000..8a5f239ed05 --- /dev/null +++ b/src/test/compile-fail/lint-dead-code-3.rs @@ -0,0 +1,50 @@ +// Copyright 2013 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. + +#[allow(unused_variable)]; +#[deny(dead_code)]; + +#[crate_type="lib"]; + +struct Foo; //~ ERROR: code is never used +impl Foo { + fn foo(&self) { //~ ERROR: code is never used + bar() + } +} + +fn bar() { //~ ERROR: code is never used + fn baz() {} //~ ERROR: code is never used + + Foo.foo(); + baz(); +} + +// no warning +struct Foo2; +impl Foo2 { fn foo2(&self) { bar2() } } +fn bar2() { + fn baz2() {} + + Foo2.foo2(); + baz2(); +} + +pub fn pub_fn() { + let foo2_struct = Foo2; + foo2_struct.foo2(); +} + +// not warned because it's used in the parameter of `free` below +enum c_void {} + +extern { + fn free(p: *c_void); +} diff --git a/src/test/compile-fail/lint-heap-memory.rs b/src/test/compile-fail/lint-heap-memory.rs index fadda4173a6..b550c227898 100644 --- a/src/test/compile-fail/lint-heap-memory.rs +++ b/src/test/compile-fail/lint-heap-memory.rs @@ -10,6 +10,7 @@ #[feature(managed_boxes)]; #[forbid(heap_memory)]; +#[allow(dead_code)]; struct Foo { x: @int //~ ERROR type uses managed diff --git a/src/test/compile-fail/lint-impl-fn.rs b/src/test/compile-fail/lint-impl-fn.rs index 3cc0495206d..ad35a22b4ef 100644 --- a/src/test/compile-fail/lint-impl-fn.rs +++ b/src/test/compile-fail/lint-impl-fn.rs @@ -9,6 +9,7 @@ // except according to those terms. #[allow(while_true)]; +#[allow(dead_code)]; struct A(int); diff --git a/src/test/compile-fail/lint-missing-doc.rs b/src/test/compile-fail/lint-missing-doc.rs index 12d9cbe0dbc..a083948bf84 100644 --- a/src/test/compile-fail/lint-missing-doc.rs +++ b/src/test/compile-fail/lint-missing-doc.rs @@ -13,6 +13,7 @@ #[feature(struct_variant)]; #[feature(globs)]; #[deny(missing_doc)]; +#[allow(dead_code)]; //! Some garbage docs for the crate here #[doc="More garbage"]; diff --git a/src/test/compile-fail/lint-non-camel-case-types.rs b/src/test/compile-fail/lint-non-camel-case-types.rs index 2cabdfe5bb0..6d217656cd0 100644 --- a/src/test/compile-fail/lint-non-camel-case-types.rs +++ b/src/test/compile-fail/lint-non-camel-case-types.rs @@ -9,6 +9,7 @@ // except according to those terms. #[forbid(non_camel_case_types)]; +#[allow(dead_code)]; struct foo { //~ ERROR type `foo` should have a camel case identifier bar: int, diff --git a/src/test/compile-fail/lint-non-uppercase-statics.rs b/src/test/compile-fail/lint-non-uppercase-statics.rs index 4da4d3ada38..d41a4ccda8d 100644 --- a/src/test/compile-fail/lint-non-uppercase-statics.rs +++ b/src/test/compile-fail/lint-non-uppercase-statics.rs @@ -9,6 +9,7 @@ // except according to those terms. #[forbid(non_uppercase_statics)]; +#[allow(dead_code)]; static foo: int = 1; //~ ERROR static constant should have an uppercase identifier diff --git a/src/test/compile-fail/lint-obsolete-attr.rs b/src/test/compile-fail/lint-obsolete-attr.rs index 91976978315..442bcaa0923 100644 --- a/src/test/compile-fail/lint-obsolete-attr.rs +++ b/src/test/compile-fail/lint-obsolete-attr.rs @@ -12,6 +12,7 @@ // injected intrinsics by the compiler. #[deny(attribute_usage)]; +#[allow(dead_code)]; #[abi="stdcall"] extern {} //~ ERROR: obsolete attribute diff --git a/src/test/compile-fail/lint-stability.rs b/src/test/compile-fail/lint-stability.rs index 1046a638ff9..9cc06cc5395 100644 --- a/src/test/compile-fail/lint-stability.rs +++ b/src/test/compile-fail/lint-stability.rs @@ -15,6 +15,7 @@ #[deny(unstable)]; #[deny(deprecated)]; #[deny(experimental)]; +#[allow(dead_code)]; mod cross_crate { extern mod lint_stability; diff --git a/src/test/compile-fail/lint-type-limits.rs b/src/test/compile-fail/lint-type-limits.rs index 08714e3a044..f609debb5bd 100644 --- a/src/test/compile-fail/lint-type-limits.rs +++ b/src/test/compile-fail/lint-type-limits.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#[allow(dead_code)]; + // compile-flags: -D type-limits fn main() { } diff --git a/src/test/compile-fail/lint-unsafe-block.rs b/src/test/compile-fail/lint-unsafe-block.rs index 7f3075e90bc..529d3e921a0 100644 --- a/src/test/compile-fail/lint-unsafe-block.rs +++ b/src/test/compile-fail/lint-unsafe-block.rs @@ -9,6 +9,7 @@ // except according to those terms. #[allow(unused_unsafe)]; +#[allow(dead_code)]; #[deny(unsafe_block)]; #[feature(macro_rules)]; diff --git a/src/test/compile-fail/lint-unused-import-tricky-globs.rs b/src/test/compile-fail/lint-unused-import-tricky-globs.rs index 85edbd1d147..9d6140b8fd2 100644 --- a/src/test/compile-fail/lint-unused-import-tricky-globs.rs +++ b/src/test/compile-fail/lint-unused-import-tricky-globs.rs @@ -10,6 +10,7 @@ #[feature(globs)]; #[deny(unused_imports)]; +#[allow(dead_code)]; mod A { pub fn p() {} diff --git a/src/test/compile-fail/lint-unused-import-tricky-names.rs b/src/test/compile-fail/lint-unused-import-tricky-names.rs index 0347c673779..24511296a0b 100644 --- a/src/test/compile-fail/lint-unused-import-tricky-names.rs +++ b/src/test/compile-fail/lint-unused-import-tricky-names.rs @@ -9,6 +9,7 @@ // except according to those terms. #[deny(unused_imports)]; +#[allow(dead_code)]; // Regression test for issue #6633 mod issue6633 { diff --git a/src/test/compile-fail/lint-unused-imports.rs b/src/test/compile-fail/lint-unused-imports.rs index 9bb58453539..e248184d5e2 100644 --- a/src/test/compile-fail/lint-unused-imports.rs +++ b/src/test/compile-fail/lint-unused-imports.rs @@ -10,6 +10,7 @@ #[feature(globs)]; #[deny(unused_imports)]; +#[allow(dead_code)]; use cal = bar::c::cc; diff --git a/src/test/compile-fail/lint-unused-mut-variables.rs b/src/test/compile-fail/lint-unused-mut-variables.rs index 798c1194af8..271aedd3f6a 100644 --- a/src/test/compile-fail/lint-unused-mut-variables.rs +++ b/src/test/compile-fail/lint-unused-mut-variables.rs @@ -12,6 +12,7 @@ #[allow(dead_assignment)]; #[allow(unused_variable)]; +#[allow(dead_code)]; #[deny(unused_mut)]; fn main() { diff --git a/src/test/compile-fail/lint-unused-unsafe.rs b/src/test/compile-fail/lint-unused-unsafe.rs index f28322d3bf7..96a4c2adca3 100644 --- a/src/test/compile-fail/lint-unused-unsafe.rs +++ b/src/test/compile-fail/lint-unused-unsafe.rs @@ -10,6 +10,7 @@ // Exercise the unused_unsafe attribute in some positive and negative cases +#[allow(dead_code)]; #[deny(unused_unsafe)]; mod foo { diff --git a/src/test/compile-fail/liveness-dead.rs b/src/test/compile-fail/liveness-dead.rs index df78b25187b..a3d388d7c34 100644 --- a/src/test/compile-fail/liveness-dead.rs +++ b/src/test/compile-fail/liveness-dead.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#[allow(dead_code)]; #[deny(dead_assignment)]; fn f1(x: &mut int) { diff --git a/src/test/compile-fail/match-static-const-lc.rs b/src/test/compile-fail/match-static-const-lc.rs index 1cdceaca6b4..fd605b79dbe 100644 --- a/src/test/compile-fail/match-static-const-lc.rs +++ b/src/test/compile-fail/match-static-const-lc.rs @@ -10,6 +10,7 @@ // Issue #7526: lowercase static constants in patterns look like bindings +#[allow(dead_code)]; #[deny(non_uppercase_pattern_statics)]; pub static a : int = 97; diff --git a/src/test/compile-fail/static-assert.rs b/src/test/compile-fail/static-assert.rs index 019a4b88aed..4f7f7dd7408 100644 --- a/src/test/compile-fail/static-assert.rs +++ b/src/test/compile-fail/static-assert.rs @@ -1,3 +1,5 @@ +#[allow(dead_code)]; + #[static_assert] static A: bool = false; //~ ERROR static assertion failed diff --git a/src/test/compile-fail/static-assert2.rs b/src/test/compile-fail/static-assert2.rs index 42e475dac8b..ceaa3889179 100644 --- a/src/test/compile-fail/static-assert2.rs +++ b/src/test/compile-fail/static-assert2.rs @@ -1,3 +1,5 @@ +#[allow(dead_code)]; + #[static_assert] static E: bool = 1 == 2; //~ ERROR static assertion failed |
