/src/test/codegen-units/item-collection/unused-traits-and-generics.rs

https://gitlab.com/alx741/rust · Rust · 89 lines · 53 code · 20 blank · 16 comment · 1 complexity · 1879bb621990a5c59771cf843d42fcc5 MD5 · raw file

  1. // Copyright 2012-2015 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. // ignore-tidy-linelength
  11. // compile-flags:-Zprint-trans-items=eager
  12. #![crate_type="lib"]
  13. #![deny(dead_code)]
  14. // This test asserts that no codegen items are generated for generic items that
  15. // are never instantiated in the local crate.
  16. pub trait Trait {
  17. fn foo() {}
  18. fn bar(&self) {}
  19. }
  20. pub fn foo<T: Copy>(x: T) -> (T, T) {
  21. (x, x)
  22. }
  23. pub struct Struct<T> {
  24. x: T
  25. }
  26. impl<T> Struct<T> {
  27. pub fn foo(self) -> T {
  28. self.x
  29. }
  30. pub fn bar() {}
  31. }
  32. pub enum Enum<T> {
  33. A(T),
  34. B { x: T }
  35. }
  36. impl<T> Enum<T> {
  37. pub fn foo(self) -> T {
  38. match self {
  39. Enum::A(x) => x,
  40. Enum::B { x } => x,
  41. }
  42. }
  43. pub fn bar() {}
  44. }
  45. pub struct TupleStruct<T>(T);
  46. impl<T> TupleStruct<T> {
  47. pub fn foo(self) -> T {
  48. self.0
  49. }
  50. pub fn bar() {}
  51. }
  52. pub type Pair<T> = (T, T);
  53. pub struct NonGeneric {
  54. x: i32
  55. }
  56. impl NonGeneric {
  57. pub fn foo(self) -> i32 {
  58. self.x
  59. }
  60. pub fn generic_foo<T>(&self, x: T) -> (T, i32) {
  61. (x, self.x)
  62. }
  63. pub fn generic_bar<T: Copy>(x: T) -> (T, T) {
  64. (x, x)
  65. }
  66. }
  67. // Only the non-generic methods should be instantiated:
  68. //~ TRANS_ITEM fn unused_traits_and_generics::{{impl}}[3]::foo[0]
  69. //~ TRANS_ITEM drop-glue i8