rust/tests/ui/lint/dead-code/lint-dead-code-3.rs

91 lines
1.5 KiB
Rust
Raw Normal View History

2014-10-27 17:37:07 -05:00
#![allow(unused_variables)]
#![allow(non_camel_case_types)]
#![allow(clashing_extern_declarations)]
#![deny(dead_code)]
2013-12-08 01:55:27 -06:00
#![crate_type="lib"]
2013-12-08 01:55:27 -06:00
2014-02-26 11:58:41 -06:00
pub use extern_foo as x;
2020-09-01 16:12:52 -05:00
extern "C" {
2015-03-15 15:00:41 -05:00
pub fn extern_foo();
}
struct Foo; //~ ERROR: struct `Foo` is never constructed
2013-12-08 01:55:27 -06:00
impl Foo {
fn foo(&self) { //~ ERROR: method `foo` is never used
2013-12-08 01:55:27 -06:00
bar()
}
}
fn bar() { //~ ERROR: function `bar` is never used
fn baz() {}
2013-12-08 01:55:27 -06:00
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();
blah::baz();
2013-12-08 01:55:27 -06:00
}
mod blah {
// not warned because it's used in the parameter of `free` and return of
// `malloc` below, which are also used.
enum c_void {}
2020-09-01 16:12:52 -05:00
extern "C" {
2014-06-25 14:47:34 -05:00
fn free(p: *const c_void);
fn malloc(size: usize) -> *const c_void;
}
pub fn baz() {
unsafe { free(malloc(4)); }
}
}
2013-12-08 01:55:27 -06:00
enum c_void {} //~ ERROR: enum `c_void` is never used
2020-09-01 16:12:52 -05:00
extern "C" {
fn free(p: *const c_void); //~ ERROR: function `free` is never used
2013-12-08 01:55:27 -06:00
}
// Check provided method
mod inner {
pub trait Trait {
fn f(&self) { f(); }
}
impl Trait for isize {}
fn f() {}
}
fn anon_const() -> [(); {
fn blah() {} //~ ERROR: function `blah` is never used
1
}] {
[(); {
fn blah() {} //~ ERROR: function `blah` is never used
1
}]
}
pub fn foo() {
2019-05-28 13:46:13 -05:00
let a: &dyn inner::Trait = &1_isize;
a.f();
anon_const();
}