/src/test/ui/privacy/where-priv-type.rs

https://gitlab.com/rust-lang/rust · Rust · 90 lines · 57 code · 20 blank · 13 comment · 5 complexity · 1186e91797f6b2fbe377a67c0df96a56 MD5 · raw file

  1. // priv-in-pub lint tests where the private type appears in the
  2. // `where` clause of a public item
  3. #![crate_type = "lib"]
  4. #![feature(generic_const_exprs)]
  5. #![allow(incomplete_features)]
  6. struct PrivTy;
  7. trait PrivTr {}
  8. pub struct PubTy;
  9. pub struct PubTyGeneric<T>(T);
  10. pub trait PubTr {}
  11. impl PubTr for PrivTy {}
  12. pub trait PubTrWithAssocTy { type AssocTy; }
  13. impl PubTrWithAssocTy for PrivTy { type AssocTy = PrivTy; }
  14. pub struct S
  15. //~^ WARNING private type `PrivTy` in public interface
  16. //~| WARNING hard error
  17. where
  18. PrivTy:
  19. {}
  20. pub enum E
  21. //~^ WARNING private type `PrivTy` in public interface
  22. //~| WARNING hard error
  23. where
  24. PrivTy:
  25. {}
  26. pub fn f()
  27. //~^ WARNING private type `PrivTy` in public interface
  28. //~| WARNING hard error
  29. where
  30. PrivTy:
  31. {}
  32. impl S
  33. //~^ ERROR private type `PrivTy` in public interface
  34. where
  35. PrivTy:
  36. {
  37. pub fn f()
  38. //~^ WARNING private type `PrivTy` in public interface
  39. //~| WARNING hard error
  40. where
  41. PrivTy:
  42. {}
  43. }
  44. impl PubTr for PubTy
  45. where
  46. PrivTy:
  47. {}
  48. impl<T> PubTr for PubTyGeneric<T>
  49. where
  50. T: PubTrWithAssocTy<AssocTy=PrivTy>
  51. {}
  52. pub struct Const<const U: u8>;
  53. pub trait Trait {
  54. type AssocTy;
  55. fn assoc_fn() -> Self::AssocTy;
  56. }
  57. impl<const U: u8> Trait for Const<U>
  58. where
  59. Const<{ my_const_fn(U) }>: ,
  60. {
  61. type AssocTy = Const<{ my_const_fn(U) }>;
  62. //~^ ERROR private type
  63. fn assoc_fn() -> Self::AssocTy {
  64. Const
  65. }
  66. }
  67. const fn my_const_fn(val: u8) -> u8 {
  68. // body of this function doesn't matter
  69. val
  70. }