/src/test/compile-fail/lint-dead-code-3.rs

https://gitlab.com/alx741/rust · Rust · 91 lines · 59 code · 19 blank · 13 comment · 1 complexity · d0e21dd9f5b65b7a2582dc4b8dc3a9ad MD5 · raw file

  1. // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
  2. // file at the top-level directory of this distribution and at
  3. // http://rust-lang.org/COPYRIGHT.
  4. //
  5. // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
  6. // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
  7. // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
  8. // option. This file may not be copied, modified, or distributed
  9. // except according to those terms.
  10. #![allow(unused_variables)]
  11. #![allow(non_camel_case_types)]
  12. #![deny(dead_code)]
  13. #![feature(libc)]
  14. #![crate_type="lib"]
  15. extern crate libc;
  16. pub use extern_foo as x;
  17. extern {
  18. pub fn extern_foo();
  19. }
  20. struct Foo; //~ ERROR: struct is never used
  21. impl Foo {
  22. fn foo(&self) { //~ ERROR: method is never used
  23. bar()
  24. }
  25. }
  26. fn bar() { //~ ERROR: function is never used
  27. fn baz() {}
  28. Foo.foo();
  29. baz();
  30. }
  31. // no warning
  32. struct Foo2;
  33. impl Foo2 { fn foo2(&self) { bar2() } }
  34. fn bar2() {
  35. fn baz2() {}
  36. Foo2.foo2();
  37. baz2();
  38. }
  39. pub fn pub_fn() {
  40. let foo2_struct = Foo2;
  41. foo2_struct.foo2();
  42. blah::baz();
  43. }
  44. mod blah {
  45. use libc::size_t;
  46. // not warned because it's used in the parameter of `free` and return of
  47. // `malloc` below, which are also used.
  48. enum c_void {}
  49. extern {
  50. fn free(p: *const c_void);
  51. fn malloc(size: size_t) -> *const c_void;
  52. }
  53. pub fn baz() {
  54. unsafe { free(malloc(4)); }
  55. }
  56. }
  57. enum c_void {} //~ ERROR: enum is never used
  58. extern {
  59. fn free(p: *const c_void); //~ ERROR: foreign function is never used
  60. }
  61. // Check provided method
  62. mod inner {
  63. pub trait Trait {
  64. fn f(&self) { f(); }
  65. }
  66. impl Trait for isize {}
  67. fn f() {}
  68. }
  69. pub fn foo() {
  70. let a: &inner::Trait = &1_isize;
  71. a.f();
  72. }