diff options
Diffstat (limited to 'tests/ui/privacy')
91 files changed, 1672 insertions, 685 deletions
diff --git a/tests/ui/privacy/associated-item-privacy-inherent.rs b/tests/ui/privacy/associated-item-privacy-inherent.rs index 7b7c734a9..81703ae10 100644 --- a/tests/ui/privacy/associated-item-privacy-inherent.rs +++ b/tests/ui/privacy/associated-item-privacy-inherent.rs @@ -1,5 +1,5 @@ #![feature(decl_macro, associated_type_defaults)] -#![allow(unused, private_in_public)] +#![allow(private_interfaces)] mod priv_nominal { pub struct Pub; diff --git a/tests/ui/privacy/associated-item-privacy-trait.rs b/tests/ui/privacy/associated-item-privacy-trait.rs index c686a2177..f038ae9e2 100644 --- a/tests/ui/privacy/associated-item-privacy-trait.rs +++ b/tests/ui/privacy/associated-item-privacy-trait.rs @@ -1,5 +1,5 @@ #![feature(decl_macro, associated_type_defaults)] -#![allow(unused, private_in_public)] +#![allow(private_interfaces, private_bounds)] mod priv_trait { trait PrivTr { @@ -23,7 +23,7 @@ mod priv_trait { let _: <Pub as PrivTr>::AssocTy; //~^ ERROR associated type `PrivTr::AssocTy` is private pub type InSignatureTy = <Pub as PrivTr>::AssocTy; - //~^ ERROR trait `PrivTr` is private + //~^ ERROR associated type `PrivTr::AssocTy` is private pub trait InSignatureTr: PrivTr {} //~^ ERROR trait `PrivTr` is private impl PrivTr for u8 {} diff --git a/tests/ui/privacy/associated-item-privacy-trait.stderr b/tests/ui/privacy/associated-item-privacy-trait.stderr index eb905bf7e..4e9dfa4a8 100644 --- a/tests/ui/privacy/associated-item-privacy-trait.stderr +++ b/tests/ui/privacy/associated-item-privacy-trait.stderr @@ -53,11 +53,11 @@ LL | priv_trait::mac!(); | = note: this error originates in the macro `priv_trait::mac` (in Nightly builds, run with -Z macro-backtrace for more info) -error: trait `PrivTr` is private +error: associated type `PrivTr::AssocTy` is private --> $DIR/associated-item-privacy-trait.rs:25:34 | LL | pub type InSignatureTy = <Pub as PrivTr>::AssocTy; - | ^^^^^^^^^^^^^^^^^^^^^^^^ private trait + | ^^^^^^^^^^^^^^^^^^^^^^^^ private associated type ... LL | priv_trait::mac!(); | ------------------ in this macro invocation diff --git a/tests/ui/privacy/associated-item-privacy-type-binding.rs b/tests/ui/privacy/associated-item-privacy-type-binding.rs index 9826b83a3..95a4fbf63 100644 --- a/tests/ui/privacy/associated-item-privacy-type-binding.rs +++ b/tests/ui/privacy/associated-item-privacy-type-binding.rs @@ -1,5 +1,5 @@ #![feature(decl_macro, associated_type_defaults)] -#![allow(unused, private_in_public)] +#![allow(private_interfaces, private_bounds)] mod priv_trait { trait PrivTr { diff --git a/tests/ui/privacy/auxiliary/issue-117997.rs b/tests/ui/privacy/auxiliary/issue-117997.rs new file mode 100644 index 000000000..6f71cc2ba --- /dev/null +++ b/tests/ui/privacy/auxiliary/issue-117997.rs @@ -0,0 +1,35 @@ +// no-prefer-dynamic +// compile-flags: --crate-type=rlib + +pub use impl_mod::TraitImplementer as Implementer; + +pub use trait_mod::get_assoc; + +mod impl_mod { + use crate::trait_mod::TraitWithAssocType; + + pub struct TraitImplementer {} + pub struct AssociatedType {} + + impl AssociatedType { + pub fn method_on_assoc(&self) -> i32 { + todo!() + } + } + + impl TraitWithAssocType for TraitImplementer { + type AssocType = AssociatedType; + } +} + +mod trait_mod { + use crate::Implementer; + + pub fn get_assoc() -> <Implementer as TraitWithAssocType>::AssocType { + todo!() + } + + pub trait TraitWithAssocType { + type AssocType; + } +} diff --git a/tests/ui/privacy/decl-macro.stderr b/tests/ui/privacy/decl-macro.stderr index 5bc6f07ff..1ca75ec36 100644 --- a/tests/ui/privacy/decl-macro.stderr +++ b/tests/ui/privacy/decl-macro.stderr @@ -10,6 +10,6 @@ note: the macro `mac` is defined here LL | macro mac() {} | ^^^^^^^^^^^ -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0603`. diff --git a/tests/ui/privacy/effective_visibilities.stderr b/tests/ui/privacy/effective_visibilities.stderr index f74f812e1..41d63532d 100644 --- a/tests/ui/privacy/effective_visibilities.stderr +++ b/tests/ui/privacy/effective_visibilities.stderr @@ -45,6 +45,8 @@ error: not in the table | LL | struct PrivStruct; | ^^^^^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub --> $DIR/effective_visibilities.rs:25:9 @@ -81,6 +83,8 @@ error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImpl | LL | A( | ^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub --> $DIR/effective_visibilities.rs:38:17 diff --git a/tests/ui/privacy/effective_visibilities_full_priv.rs b/tests/ui/privacy/effective_visibilities_full_priv.rs new file mode 100644 index 000000000..b96eddcab --- /dev/null +++ b/tests/ui/privacy/effective_visibilities_full_priv.rs @@ -0,0 +1,21 @@ +#![feature(rustc_attrs)] +#![allow(private_interfaces)] + +struct SemiPriv; + +mod m { + #[rustc_effective_visibility] + struct Priv; + //~^ ERROR not in the table + //~| ERROR not in the table + + #[rustc_effective_visibility] + pub fn foo() {} //~ ERROR Direct: pub(crate), Reexported: pub(crate), Reachable: pub(crate), ReachableThroughImplTrait: pub(crate) + + #[rustc_effective_visibility] + impl crate::SemiPriv { //~ ERROR Direct: pub(crate), Reexported: pub(crate), Reachable: pub(crate), ReachableThroughImplTrait: pub(crate) + pub fn f(_: Priv) {} + } +} + +fn main() {} diff --git a/tests/ui/privacy/effective_visibilities_full_priv.stderr b/tests/ui/privacy/effective_visibilities_full_priv.stderr new file mode 100644 index 000000000..0577be147 --- /dev/null +++ b/tests/ui/privacy/effective_visibilities_full_priv.stderr @@ -0,0 +1,28 @@ +error: not in the table + --> $DIR/effective_visibilities_full_priv.rs:8:5 + | +LL | struct Priv; + | ^^^^^^^^^^^ + +error: not in the table + --> $DIR/effective_visibilities_full_priv.rs:8:5 + | +LL | struct Priv; + | ^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: Direct: pub(crate), Reexported: pub(crate), Reachable: pub(crate), ReachableThroughImplTrait: pub(crate) + --> $DIR/effective_visibilities_full_priv.rs:13:5 + | +LL | pub fn foo() {} + | ^^^^^^^^^^^^ + +error: Direct: pub(crate), Reexported: pub(crate), Reachable: pub(crate), ReachableThroughImplTrait: pub(crate) + --> $DIR/effective_visibilities_full_priv.rs:16:5 + | +LL | impl crate::SemiPriv { + | ^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 4 previous errors + diff --git a/tests/ui/privacy/export-tag-variant.stderr b/tests/ui/privacy/export-tag-variant.stderr index f73bd454d..778ded2df 100644 --- a/tests/ui/privacy/export-tag-variant.stderr +++ b/tests/ui/privacy/export-tag-variant.stderr @@ -2,7 +2,9 @@ error[E0603]: enum `Y` is private --> $DIR/export-tag-variant.rs:7:26 | LL | fn main() { let z = foo::Y::Y1; } - | ^ private enum + | ^ -- unit variant `Y1` is not publicly re-exported + | | + | private enum | note: the enum `Y` is defined here --> $DIR/export-tag-variant.rs:4:5 @@ -10,6 +12,6 @@ note: the enum `Y` is defined here LL | enum Y { Y1 } | ^^^^^^ -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0603`. diff --git a/tests/ui/privacy/import-list-stem-visibility-issue-119126.rs b/tests/ui/privacy/import-list-stem-visibility-issue-119126.rs new file mode 100644 index 000000000..21f7828fc --- /dev/null +++ b/tests/ui/privacy/import-list-stem-visibility-issue-119126.rs @@ -0,0 +1,14 @@ +// check-pass +// edition: 2018 + +mod outer { + mod inner { + pub mod inner2 {} + } + pub(crate) use inner::{}; + pub(crate) use inner::{{}}; + pub(crate) use inner::{inner2::{}}; + pub(crate) use inner::{inner2::{{}}}; +} + +fn main() {} diff --git a/tests/ui/privacy/issue-111220-2-tuple-struct-fields-projection.stderr b/tests/ui/privacy/issue-111220-2-tuple-struct-fields-projection.stderr index 231a4da8b..eda42c24c 100644 --- a/tests/ui/privacy/issue-111220-2-tuple-struct-fields-projection.stderr +++ b/tests/ui/privacy/issue-111220-2-tuple-struct-fields-projection.stderr @@ -4,6 +4,6 @@ error[E0603]: tuple struct constructor `A` is private LL | let Self(a) = self; | ^^^^^^^ -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0603`. diff --git a/tests/ui/privacy/issue-113860-1.rs b/tests/ui/privacy/issue-113860-1.rs new file mode 100644 index 000000000..86ccca41f --- /dev/null +++ b/tests/ui/privacy/issue-113860-1.rs @@ -0,0 +1,16 @@ +#![feature(staged_api)] +//~^ ERROR module has missing stability attribute + +pub trait Trait { + //~^ ERROR trait has missing stability attribute + fn fun() {} + //~^ ERROR associated function has missing stability attribute +} + +impl Trait for u8 { + //~^ ERROR implementation has missing stability attribute + pub(self) fn fun() {} + //~^ ERROR visibility qualifiers are not permitted here [E0449] +} + +fn main() {} diff --git a/tests/ui/privacy/issue-113860-1.stderr b/tests/ui/privacy/issue-113860-1.stderr new file mode 100644 index 000000000..c33ce26f0 --- /dev/null +++ b/tests/ui/privacy/issue-113860-1.stderr @@ -0,0 +1,49 @@ +error[E0449]: visibility qualifiers are not permitted here + --> $DIR/issue-113860-1.rs:12:5 + | +LL | pub(self) fn fun() {} + | ^^^^^^^^^ + | + = note: trait items always share the visibility of their trait + +error: module has missing stability attribute + --> $DIR/issue-113860-1.rs:1:1 + | +LL | / #![feature(staged_api)] +LL | | +LL | | +LL | | pub trait Trait { +... | +LL | | +LL | | fn main() {} + | |____________^ + +error: trait has missing stability attribute + --> $DIR/issue-113860-1.rs:4:1 + | +LL | / pub trait Trait { +LL | | +LL | | fn fun() {} +LL | | +LL | | } + | |_^ + +error: implementation has missing stability attribute + --> $DIR/issue-113860-1.rs:10:1 + | +LL | / impl Trait for u8 { +LL | | +LL | | pub(self) fn fun() {} +LL | | +LL | | } + | |_^ + +error: associated function has missing stability attribute + --> $DIR/issue-113860-1.rs:6:5 + | +LL | fn fun() {} + | ^^^^^^^^^^^ + +error: aborting due to 5 previous errors + +For more information about this error, try `rustc --explain E0449`. diff --git a/tests/ui/privacy/issue-113860-2.rs b/tests/ui/privacy/issue-113860-2.rs new file mode 100644 index 000000000..59be19d88 --- /dev/null +++ b/tests/ui/privacy/issue-113860-2.rs @@ -0,0 +1,16 @@ +#![feature(staged_api)] +//~^ ERROR module has missing stability attribute + +pub trait Trait { + //~^ ERROR trait has missing stability attribute + type X; + //~^ ERROR associated type has missing stability attribute +} + +impl Trait for u8 { + //~^ ERROR implementation has missing stability attribute + pub(self) type X = Self; + //~^ ERROR visibility qualifiers are not permitted here [E0449] +} + +fn main() {} diff --git a/tests/ui/privacy/issue-113860-2.stderr b/tests/ui/privacy/issue-113860-2.stderr new file mode 100644 index 000000000..6748bc276 --- /dev/null +++ b/tests/ui/privacy/issue-113860-2.stderr @@ -0,0 +1,49 @@ +error[E0449]: visibility qualifiers are not permitted here + --> $DIR/issue-113860-2.rs:12:5 + | +LL | pub(self) type X = Self; + | ^^^^^^^^^ + | + = note: trait items always share the visibility of their trait + +error: module has missing stability attribute + --> $DIR/issue-113860-2.rs:1:1 + | +LL | / #![feature(staged_api)] +LL | | +LL | | +LL | | pub trait Trait { +... | +LL | | +LL | | fn main() {} + | |____________^ + +error: trait has missing stability attribute + --> $DIR/issue-113860-2.rs:4:1 + | +LL | / pub trait Trait { +LL | | +LL | | type X; +LL | | +LL | | } + | |_^ + +error: implementation has missing stability attribute + --> $DIR/issue-113860-2.rs:10:1 + | +LL | / impl Trait for u8 { +LL | | +LL | | pub(self) type X = Self; +LL | | +LL | | } + | |_^ + +error: associated type has missing stability attribute + --> $DIR/issue-113860-2.rs:6:5 + | +LL | type X; + | ^^^^^^^ + +error: aborting due to 5 previous errors + +For more information about this error, try `rustc --explain E0449`. diff --git a/tests/ui/privacy/issue-113860.rs b/tests/ui/privacy/issue-113860.rs new file mode 100644 index 000000000..b94c14fac --- /dev/null +++ b/tests/ui/privacy/issue-113860.rs @@ -0,0 +1,16 @@ +#![feature(staged_api)] +//~^ ERROR module has missing stability attribute + +pub trait Trait { + //~^ ERROR trait has missing stability attribute + const X: u32; + //~^ ERROR associated constant has missing stability attribute +} + +impl Trait for u8 { + //~^ ERROR implementation has missing stability attribute + pub(self) const X: u32 = 3; + //~^ ERROR visibility qualifiers are not permitted here [E0449] +} + +fn main() {} diff --git a/tests/ui/privacy/issue-113860.stderr b/tests/ui/privacy/issue-113860.stderr new file mode 100644 index 000000000..3204f4ff9 --- /dev/null +++ b/tests/ui/privacy/issue-113860.stderr @@ -0,0 +1,49 @@ +error[E0449]: visibility qualifiers are not permitted here + --> $DIR/issue-113860.rs:12:5 + | +LL | pub(self) const X: u32 = 3; + | ^^^^^^^^^ + | + = note: trait items always share the visibility of their trait + +error: module has missing stability attribute + --> $DIR/issue-113860.rs:1:1 + | +LL | / #![feature(staged_api)] +LL | | +LL | | +LL | | pub trait Trait { +... | +LL | | +LL | | fn main() {} + | |____________^ + +error: trait has missing stability attribute + --> $DIR/issue-113860.rs:4:1 + | +LL | / pub trait Trait { +LL | | +LL | | const X: u32; +LL | | +LL | | } + | |_^ + +error: implementation has missing stability attribute + --> $DIR/issue-113860.rs:10:1 + | +LL | / impl Trait for u8 { +LL | | +LL | | pub(self) const X: u32 = 3; +LL | | +LL | | } + | |_^ + +error: associated constant has missing stability attribute + --> $DIR/issue-113860.rs:6:5 + | +LL | const X: u32; + | ^^^^^^^^^^^^^ + +error: aborting due to 5 previous errors + +For more information about this error, try `rustc --explain E0449`. diff --git a/tests/ui/privacy/issue-117997.rs b/tests/ui/privacy/issue-117997.rs new file mode 100644 index 000000000..d8284ef29 --- /dev/null +++ b/tests/ui/privacy/issue-117997.rs @@ -0,0 +1,8 @@ +// aux-build:issue-117997.rs +// build-pass + +extern crate issue_117997; + +pub fn main() { + issue_117997::get_assoc().method_on_assoc(); +} diff --git a/tests/ui/privacy/issue-30079.rs b/tests/ui/privacy/issue-30079.rs index a02a932d0..ddba629f5 100644 --- a/tests/ui/privacy/issue-30079.rs +++ b/tests/ui/privacy/issue-30079.rs @@ -3,8 +3,7 @@ struct SemiPriv; mod m1 { struct Priv; impl ::SemiPriv { - pub fn f(_: Priv) {} //~ WARN private type `m1::Priv` in public interface - //~^ WARNING hard error + pub fn f(_: Priv) {} //~ WARN type `m1::Priv` is more private than the item `m1::<impl SemiPriv>::f` } impl Priv { diff --git a/tests/ui/privacy/issue-30079.stderr b/tests/ui/privacy/issue-30079.stderr index 9179ff339..f1facba7c 100644 --- a/tests/ui/privacy/issue-30079.stderr +++ b/tests/ui/privacy/issue-30079.stderr @@ -1,15 +1,18 @@ -warning: private type `m1::Priv` in public interface (error E0446) +warning: type `m1::Priv` is more private than the item `m1::<impl SemiPriv>::f` --> $DIR/issue-30079.rs:6:9 | LL | pub fn f(_: Priv) {} - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ associated function `m1::<impl SemiPriv>::f` is reachable at visibility `pub(crate)` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> - = note: `#[warn(private_in_public)]` on by default +note: but type `m1::Priv` is only usable at visibility `pub(self)` + --> $DIR/issue-30079.rs:4:5 + | +LL | struct Priv; + | ^^^^^^^^^^^ + = note: `#[warn(private_interfaces)]` on by default error[E0446]: private type `m2::Priv` in public interface - --> $DIR/issue-30079.rs:18:9 + --> $DIR/issue-30079.rs:17:9 | LL | struct Priv; | ----------- `m2::Priv` declared as private @@ -18,7 +21,7 @@ LL | type Target = Priv; | ^^^^^^^^^^^ can't leak private type error[E0446]: private type `m3::Priv` in public interface - --> $DIR/issue-30079.rs:35:9 + --> $DIR/issue-30079.rs:34:9 | LL | struct Priv; | ----------- `m3::Priv` declared as private diff --git a/tests/ui/privacy/issue-46209-private-enum-variant-reexport.rs b/tests/ui/privacy/issue-46209-private-enum-variant-reexport.rs index 6f115e78e..653dcab57 100644 --- a/tests/ui/privacy/issue-46209-private-enum-variant-reexport.rs +++ b/tests/ui/privacy/issue-46209-private-enum-variant-reexport.rs @@ -2,13 +2,17 @@ mod rank { pub use self::Professor::*; //~^ ERROR glob import doesn't reexport anything + //~| ERROR unused import: `self::Professor::*` pub use self::Lieutenant::{JuniorGrade, Full}; //~^ ERROR `JuniorGrade` is private, and cannot be re-exported //~| ERROR `Full` is private, and cannot be re-exported + //~| ERROR unused imports: `Full`, `JuniorGrade` pub use self::PettyOfficer::*; //~^ ERROR glob import doesn't reexport anything + //~| ERROR unused import: `self::PettyOfficer::*` pub use self::Crewman::*; //~^ ERROR glob import doesn't reexport anything + //~| ERROR unused import: `self::Crewman::*` enum Professor { Adjunct, diff --git a/tests/ui/privacy/issue-46209-private-enum-variant-reexport.stderr b/tests/ui/privacy/issue-46209-private-enum-variant-reexport.stderr index 59b181fab..93a39edbb 100644 --- a/tests/ui/privacy/issue-46209-private-enum-variant-reexport.stderr +++ b/tests/ui/privacy/issue-46209-private-enum-variant-reexport.stderr @@ -1,51 +1,95 @@ error[E0364]: `JuniorGrade` is private, and cannot be re-exported - --> $DIR/issue-46209-private-enum-variant-reexport.rs:5:32 + --> $DIR/issue-46209-private-enum-variant-reexport.rs:6:32 | LL | pub use self::Lieutenant::{JuniorGrade, Full}; | ^^^^^^^^^^^ | note: consider marking `JuniorGrade` as `pub` in the imported module - --> $DIR/issue-46209-private-enum-variant-reexport.rs:5:32 + --> $DIR/issue-46209-private-enum-variant-reexport.rs:6:32 | LL | pub use self::Lieutenant::{JuniorGrade, Full}; | ^^^^^^^^^^^ error[E0364]: `Full` is private, and cannot be re-exported - --> $DIR/issue-46209-private-enum-variant-reexport.rs:5:45 + --> $DIR/issue-46209-private-enum-variant-reexport.rs:6:45 | LL | pub use self::Lieutenant::{JuniorGrade, Full}; | ^^^^ | note: consider marking `Full` as `pub` in the imported module - --> $DIR/issue-46209-private-enum-variant-reexport.rs:5:45 + --> $DIR/issue-46209-private-enum-variant-reexport.rs:6:45 | LL | pub use self::Lieutenant::{JuniorGrade, Full}; | ^^^^ -error: glob import doesn't reexport anything because no candidate is public enough +error: glob import doesn't reexport anything with visibility `pub` because no imported item is public enough --> $DIR/issue-46209-private-enum-variant-reexport.rs:3:13 | LL | pub use self::Professor::*; | ^^^^^^^^^^^^^^^^^^ | +note: the most public imported item is `pub(self)` + --> $DIR/issue-46209-private-enum-variant-reexport.rs:3:13 + | +LL | pub use self::Professor::*; + | ^^^^^^^^^^^^^^^^^^ + = help: reduce the glob import's visibility or increase visibility of imported items note: the lint level is defined here --> $DIR/issue-46209-private-enum-variant-reexport.rs:1:8 | LL | #[deny(unused_imports)] | ^^^^^^^^^^^^^^ -error: glob import doesn't reexport anything because no candidate is public enough - --> $DIR/issue-46209-private-enum-variant-reexport.rs:8:13 +error: unused import: `self::Professor::*` + --> $DIR/issue-46209-private-enum-variant-reexport.rs:3:13 + | +LL | pub use self::Professor::*; + | ^^^^^^^^^^^^^^^^^^ + +error: unused imports: `Full`, `JuniorGrade` + --> $DIR/issue-46209-private-enum-variant-reexport.rs:6:32 + | +LL | pub use self::Lieutenant::{JuniorGrade, Full}; + | ^^^^^^^^^^^ ^^^^ + +error: glob import doesn't reexport anything with visibility `pub` because no imported item is public enough + --> $DIR/issue-46209-private-enum-variant-reexport.rs:10:13 + | +LL | pub use self::PettyOfficer::*; + | ^^^^^^^^^^^^^^^^^^^^^ + | +note: the most public imported item is `pub(self)` + --> $DIR/issue-46209-private-enum-variant-reexport.rs:10:13 | LL | pub use self::PettyOfficer::*; | ^^^^^^^^^^^^^^^^^^^^^ + = help: reduce the glob import's visibility or increase visibility of imported items -error: glob import doesn't reexport anything because no candidate is public enough +error: unused import: `self::PettyOfficer::*` --> $DIR/issue-46209-private-enum-variant-reexport.rs:10:13 | +LL | pub use self::PettyOfficer::*; + | ^^^^^^^^^^^^^^^^^^^^^ + +error: glob import doesn't reexport anything with visibility `pub` because no imported item is public enough + --> $DIR/issue-46209-private-enum-variant-reexport.rs:13:13 + | +LL | pub use self::Crewman::*; + | ^^^^^^^^^^^^^^^^ + | +note: the most public imported item is `pub(crate)` + --> $DIR/issue-46209-private-enum-variant-reexport.rs:13:13 + | +LL | pub use self::Crewman::*; + | ^^^^^^^^^^^^^^^^ + = help: reduce the glob import's visibility or increase visibility of imported items + +error: unused import: `self::Crewman::*` + --> $DIR/issue-46209-private-enum-variant-reexport.rs:13:13 + | LL | pub use self::Crewman::*; | ^^^^^^^^^^^^^^^^ -error: aborting due to 5 previous errors +error: aborting due to 9 previous errors For more information about this error, try `rustc --explain E0364`. diff --git a/tests/ui/privacy/issue-75062-fieldless-tuple-struct.stderr b/tests/ui/privacy/issue-75062-fieldless-tuple-struct.stderr index 14a12003e..b00e566f8 100644 --- a/tests/ui/privacy/issue-75062-fieldless-tuple-struct.stderr +++ b/tests/ui/privacy/issue-75062-fieldless-tuple-struct.stderr @@ -10,6 +10,6 @@ note: the tuple struct `Bar` is defined here LL | struct Bar(); | ^^^^^^^^^^^^^ -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0603`. diff --git a/tests/ui/privacy/issue-75906.stderr b/tests/ui/privacy/issue-75906.stderr index 600dc7c87..c5bbef97c 100644 --- a/tests/ui/privacy/issue-75906.stderr +++ b/tests/ui/privacy/issue-75906.stderr @@ -14,6 +14,6 @@ help: consider making the field publicly accessible LL | pub struct Bar(pub u8); | +++ -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0423`. diff --git a/tests/ui/privacy/issue-79593.stderr b/tests/ui/privacy/issue-79593.stderr index 21ba760ad..5bb69836f 100644 --- a/tests/ui/privacy/issue-79593.stderr +++ b/tests/ui/privacy/issue-79593.stderr @@ -16,7 +16,7 @@ error: cannot construct `Pub` with struct literal syntax due to private fields LL | foo::Pub {}; | ^^^^^^^^ | - = note: ... and other private field `private` that was not provided + = note: private field `private` that was not provided error[E0063]: missing field `y` in initializer of `Enum` --> $DIR/issue-79593.rs:23:5 diff --git a/tests/ui/privacy/legacy-ctor-visibility.stderr b/tests/ui/privacy/legacy-ctor-visibility.stderr index c8057d85e..78c79fc95 100644 --- a/tests/ui/privacy/legacy-ctor-visibility.stderr +++ b/tests/ui/privacy/legacy-ctor-visibility.stderr @@ -4,6 +4,6 @@ error[E0423]: expected function, tuple struct or tuple variant, found struct `S` LL | S(10); | ^ -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0423`. diff --git a/tests/ui/privacy/privacy-in-paths.stderr b/tests/ui/privacy/privacy-in-paths.stderr index 2eb3ebb51..9c3d5e97c 100644 --- a/tests/ui/privacy/privacy-in-paths.stderr +++ b/tests/ui/privacy/privacy-in-paths.stderr @@ -2,7 +2,9 @@ error[E0603]: module `bar` is private --> $DIR/privacy-in-paths.rs:24:16 | LL | ::foo::bar::baz::f(); - | ^^^ private module + | ^^^ - function `f` is not publicly re-exported + | | + | private module | note: the module `bar` is defined here --> $DIR/privacy-in-paths.rs:3:5 @@ -21,12 +23,18 @@ note: the module `bar` is defined here | LL | mod bar { | ^^^^^^^ +help: consider importing this struct through its public re-export instead + | +LL | foo::S::f(); + | ~~~~~~ error[E0603]: trait `T` is private --> $DIR/privacy-in-paths.rs:26:23 | LL | <() as ::foo::T>::Assoc::f(); - | ^ private trait + | ^ ----- associated type `Assoc` is not publicly re-exported + | | + | private trait | note: the trait `T` is defined here --> $DIR/privacy-in-paths.rs:8:5 diff --git a/tests/ui/privacy/privacy-ufcs.stderr b/tests/ui/privacy/privacy-ufcs.stderr index e93a458ce..5c986895d 100644 --- a/tests/ui/privacy/privacy-ufcs.stderr +++ b/tests/ui/privacy/privacy-ufcs.stderr @@ -2,7 +2,9 @@ error[E0603]: trait `Bar` is private --> $DIR/privacy-ufcs.rs:12:20 | LL | <i32 as ::foo::Bar>::baz(); - | ^^^ private trait + | ^^^ --- associated function `baz` is not publicly re-exported + | | + | private trait | note: the trait `Bar` is defined here --> $DIR/privacy-ufcs.rs:4:5 @@ -10,6 +12,6 @@ note: the trait `Bar` is defined here LL | trait Bar { | ^^^^^^^^^ -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0603`. diff --git a/tests/ui/privacy/privacy1.stderr b/tests/ui/privacy/privacy1.stderr index 6ebed8ee0..a3552e146 100644 --- a/tests/ui/privacy/privacy1.stderr +++ b/tests/ui/privacy/privacy1.stderr @@ -21,6 +21,7 @@ note: the module `baz` is defined here | LL | mod baz { | ^^^^^^^ + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0603]: module `baz` is private --> $DIR/privacy1.rs:141:18 @@ -50,7 +51,9 @@ error[E0603]: module `baz` is private --> $DIR/privacy1.rs:104:16 | LL | ::bar::baz::A::foo(); - | ^^^ private module + | ^^^ - struct `A` is not publicly re-exported + | | + | private module | note: the module `baz` is defined here --> $DIR/privacy1.rs:50:5 @@ -62,7 +65,9 @@ error[E0603]: module `baz` is private --> $DIR/privacy1.rs:105:16 | LL | ::bar::baz::A::bar(); - | ^^^ private module + | ^^^ - struct `A` is not publicly re-exported + | | + | private module | note: the module `baz` is defined here --> $DIR/privacy1.rs:50:5 @@ -74,7 +79,9 @@ error[E0603]: module `baz` is private --> $DIR/privacy1.rs:107:16 | LL | ::bar::baz::A.foo2(); - | ^^^ private module + | ^^^ - unit struct `A` is not publicly re-exported + | | + | private module | note: the module `baz` is defined here --> $DIR/privacy1.rs:50:5 @@ -86,7 +93,9 @@ error[E0603]: module `baz` is private --> $DIR/privacy1.rs:108:16 | LL | ::bar::baz::A.bar2(); - | ^^^ private module + | ^^^ - unit struct `A` is not publicly re-exported + | | + | private module | note: the module `baz` is defined here --> $DIR/privacy1.rs:50:5 @@ -98,7 +107,9 @@ error[E0603]: trait `B` is private --> $DIR/privacy1.rs:112:16 | LL | ::bar::B::foo(); - | ^ private trait + | ^ --- associated function `foo` is not publicly re-exported + | | + | private trait | note: the trait `B` is defined here --> $DIR/privacy1.rs:40:5 @@ -129,6 +140,10 @@ note: the module `baz` is defined here | LL | mod baz { | ^^^^^^^ +help: consider importing this function through its public re-export instead + | +LL | bar::foo(); + | ~~~~~~~~ error[E0603]: module `baz` is private --> $DIR/privacy1.rs:128:16 @@ -141,6 +156,10 @@ note: the module `baz` is defined here | LL | mod baz { | ^^^^^^^ +help: consider importing this function through its public re-export instead + | +LL | bar::bar(); + | ~~~~~~~~ error[E0603]: trait `B` is private --> $DIR/privacy1.rs:157:17 diff --git a/tests/ui/privacy/privacy2.rs b/tests/ui/privacy/privacy2.rs index c8fa436bd..212bc003e 100644 --- a/tests/ui/privacy/privacy2.rs +++ b/tests/ui/privacy/privacy2.rs @@ -1,3 +1,5 @@ +// compile-flags: -Zdeduplicate-diagnostics=yes + #![feature(start, no_core)] #![no_core] // makes debugging this test *a lot* easier (during resolve) diff --git a/tests/ui/privacy/privacy2.stderr b/tests/ui/privacy/privacy2.stderr index c2a33ce1f..46bb9823d 100644 --- a/tests/ui/privacy/privacy2.stderr +++ b/tests/ui/privacy/privacy2.stderr @@ -1,25 +1,25 @@ error[E0432]: unresolved import `bar::foo` - --> $DIR/privacy2.rs:17:9 + --> $DIR/privacy2.rs:19:9 | LL | use bar::foo; | ^^^^^^^^ no `foo` in `bar` error[E0603]: function import `foo` is private - --> $DIR/privacy2.rs:23:20 + --> $DIR/privacy2.rs:25:20 | LL | use bar::glob::foo; | ^^^ private function import | note: the function import `foo` is defined here... - --> $DIR/privacy2.rs:10:13 + --> $DIR/privacy2.rs:12:13 | LL | use foo; | ^^^ note: ...and refers to the function `foo` which is defined here - --> $DIR/privacy2.rs:14:1 + --> $DIR/privacy2.rs:16:1 | LL | pub fn foo() {} - | ^^^^^^^^^^^^ consider importing it directly + | ^^^^^^^^^^^^ you could import this directly error: requires `sized` lang_item diff --git a/tests/ui/privacy/privacy3.rs b/tests/ui/privacy/privacy3.rs index 5a7cd76a9..3466f5bb1 100644 --- a/tests/ui/privacy/privacy3.rs +++ b/tests/ui/privacy/privacy3.rs @@ -1,3 +1,5 @@ +// compile-flags: -Zdeduplicate-diagnostics=yes + #![feature(start, no_core)] #![no_core] // makes debugging this test *a lot* easier (during resolve) diff --git a/tests/ui/privacy/privacy3.stderr b/tests/ui/privacy/privacy3.stderr index 22c1e48b0..df66c8475 100644 --- a/tests/ui/privacy/privacy3.stderr +++ b/tests/ui/privacy/privacy3.stderr @@ -1,5 +1,5 @@ error[E0432]: unresolved import `bar::gpriv` - --> $DIR/privacy3.rs:18:9 + --> $DIR/privacy3.rs:20:9 | LL | use bar::gpriv; | ^^^^^^^^^^ no `gpriv` in `bar` diff --git a/tests/ui/privacy/privacy4.stderr b/tests/ui/privacy/privacy4.stderr index 7552fa71a..4aa3ae964 100644 --- a/tests/ui/privacy/privacy4.stderr +++ b/tests/ui/privacy/privacy4.stderr @@ -10,6 +10,6 @@ note: the module `glob` is defined here LL | mod glob { | ^^^^^^^^ -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0603`. diff --git a/tests/ui/privacy/private-bounds-locally-allowed.rs b/tests/ui/privacy/private-bounds-locally-allowed.rs new file mode 100644 index 000000000..96a007a64 --- /dev/null +++ b/tests/ui/privacy/private-bounds-locally-allowed.rs @@ -0,0 +1,7 @@ +// check-pass +// compile-flags: --crate-type=lib + +#[allow(private_bounds)] +pub trait Foo: FooImpl {} + +trait FooImpl {} diff --git a/tests/ui/privacy/private-field-ty-err.stderr b/tests/ui/privacy/private-field-ty-err.stderr index 98ba7856e..17d50f24a 100644 --- a/tests/ui/privacy/private-field-ty-err.stderr +++ b/tests/ui/privacy/private-field-ty-err.stderr @@ -4,6 +4,6 @@ error[E0616]: field `len` of struct `Foo` is private LL | if x.len { | ^^^ private field -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0616`. diff --git a/tests/ui/privacy/private-impl-method.stderr b/tests/ui/privacy/private-impl-method.stderr index 18e4531d1..c53232e4c 100644 --- a/tests/ui/privacy/private-impl-method.stderr +++ b/tests/ui/privacy/private-impl-method.stderr @@ -7,6 +7,6 @@ LL | fn foo(&self) {} LL | s.foo(); | ^^^ private method -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0624`. diff --git a/tests/ui/privacy/private-in-public-assoc-ty.rs b/tests/ui/privacy/private-in-public-assoc-ty.rs index d4d379bdb..5f7c4bcf2 100644 --- a/tests/ui/privacy/private-in-public-assoc-ty.rs +++ b/tests/ui/privacy/private-in-public-assoc-ty.rs @@ -22,14 +22,11 @@ mod m { // applies only to the aliased types, not bounds. pub trait PubTr { type Alias1: PrivTr; - //~^ WARN private trait `PrivTr` in public interface - //~| WARN this was previously accepted + //~^ WARN trait `PrivTr` is more private than the item `PubTr::Alias1` type Alias2: PubTrAux1<Priv> = u8; - //~^ WARN private type `Priv` in public interface - //~| WARN this was previously accepted + //~^ WARN type `Priv` is more private than the item `PubTr::Alias2` type Alias3: PubTrAux2<A = Priv> = u8; - //~^ WARN private type `Priv` in public interface - //~| WARN this was previously accepted + //~^ WARN type `Priv` is more private than the item `PubTr::Alias3` type Alias4 = Priv; //~^ ERROR private type `Priv` in public interface diff --git a/tests/ui/privacy/private-in-public-assoc-ty.stderr b/tests/ui/privacy/private-in-public-assoc-ty.stderr index a59027d81..0931e6d99 100644 --- a/tests/ui/privacy/private-in-public-assoc-ty.stderr +++ b/tests/ui/privacy/private-in-public-assoc-ty.stderr @@ -7,36 +7,45 @@ LL | struct Priv; LL | type A = Priv; | ^^^^^^ can't leak private type -warning: private trait `PrivTr` in public interface (error E0445) +warning: trait `PrivTr` is more private than the item `PubTr::Alias1` --> $DIR/private-in-public-assoc-ty.rs:24:9 | LL | type Alias1: PrivTr; - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^ associated type `PubTr::Alias1` is reachable at visibility `pub(crate)` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> - = note: `#[warn(private_in_public)]` on by default +note: but trait `PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-assoc-ty.rs:9:5 + | +LL | trait PrivTr {} + | ^^^^^^^^^^^^ + = note: `#[warn(private_bounds)]` on by default -warning: private type `Priv` in public interface (error E0446) - --> $DIR/private-in-public-assoc-ty.rs:27:9 +warning: type `Priv` is more private than the item `PubTr::Alias2` + --> $DIR/private-in-public-assoc-ty.rs:26:9 | LL | type Alias2: PubTrAux1<Priv> = u8; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated type `PubTr::Alias2` is reachable at visibility `pub(crate)` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +note: but type `Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-assoc-ty.rs:8:5 + | +LL | struct Priv; + | ^^^^^^^^^^^ -warning: private type `Priv` in public interface (error E0446) - --> $DIR/private-in-public-assoc-ty.rs:30:9 +warning: type `Priv` is more private than the item `PubTr::Alias3` + --> $DIR/private-in-public-assoc-ty.rs:28:9 | LL | type Alias3: PubTrAux2<A = Priv> = u8; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated type `PubTr::Alias3` is reachable at visibility `pub(crate)` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +note: but type `Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-assoc-ty.rs:8:5 + | +LL | struct Priv; + | ^^^^^^^^^^^ error[E0446]: private type `Priv` in public interface - --> $DIR/private-in-public-assoc-ty.rs:34:9 + --> $DIR/private-in-public-assoc-ty.rs:31:9 | LL | struct Priv; | ----------- `Priv` declared as private @@ -45,7 +54,7 @@ LL | type Alias4 = Priv; | ^^^^^^^^^^^ can't leak private type error[E0446]: private type `Priv` in public interface - --> $DIR/private-in-public-assoc-ty.rs:41:9 + --> $DIR/private-in-public-assoc-ty.rs:38:9 | LL | struct Priv; | ----------- `Priv` declared as private @@ -53,8 +62,8 @@ LL | struct Priv; LL | type Alias1 = Priv; | ^^^^^^^^^^^ can't leak private type -error[E0445]: private trait `PrivTr` in public interface - --> $DIR/private-in-public-assoc-ty.rs:44:9 +error[E0446]: private trait `PrivTr` in public interface + --> $DIR/private-in-public-assoc-ty.rs:41:9 | LL | trait PrivTr {} | ------------ `PrivTr` declared as private @@ -64,5 +73,4 @@ LL | type Exist = impl PrivTr; error: aborting due to 4 previous errors; 3 warnings emitted -Some errors have detailed explanations: E0445, E0446. -For more information about an error, try `rustc --explain E0445`. +For more information about this error, try `rustc --explain E0446`. diff --git a/tests/ui/privacy/private-in-public-lint.rs b/tests/ui/privacy/private-in-public-lint.rs deleted file mode 100644 index 8b6e43601..000000000 --- a/tests/ui/privacy/private-in-public-lint.rs +++ /dev/null @@ -1,19 +0,0 @@ -mod m1 { - pub struct Pub; - struct Priv; - - impl Pub { - pub fn f() -> Priv {Priv} //~ ERROR private type `m1::Priv` in public interface - } -} - -mod m2 { - pub struct Pub; - struct Priv; - - impl Pub { - pub fn f() -> Priv {Priv} //~ ERROR private type `m2::Priv` in public interface - } -} - -fn main() {} diff --git a/tests/ui/privacy/private-in-public-lint.stderr b/tests/ui/privacy/private-in-public-lint.stderr deleted file mode 100644 index 1e98e3bed..000000000 --- a/tests/ui/privacy/private-in-public-lint.stderr +++ /dev/null @@ -1,21 +0,0 @@ -error[E0446]: private type `m1::Priv` in public interface - --> $DIR/private-in-public-lint.rs:6:9 - | -LL | struct Priv; - | ----------- `m1::Priv` declared as private -... -LL | pub fn f() -> Priv {Priv} - | ^^^^^^^^^^^^^^^^^^ can't leak private type - -error[E0446]: private type `m2::Priv` in public interface - --> $DIR/private-in-public-lint.rs:15:9 - | -LL | struct Priv; - | ----------- `m2::Priv` declared as private -... -LL | pub fn f() -> Priv {Priv} - | ^^^^^^^^^^^^^^^^^^ can't leak private type - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0446`. diff --git a/tests/ui/privacy/private-in-public-non-principal-2.rs b/tests/ui/privacy/private-in-public-non-principal-2.rs index db451d334..d7223c647 100644 --- a/tests/ui/privacy/private-in-public-non-principal-2.rs +++ b/tests/ui/privacy/private-in-public-non-principal-2.rs @@ -1,7 +1,7 @@ #![feature(auto_traits)] #![feature(negative_impls)] -#[allow(private_in_public)] +#[allow(private_interfaces)] mod m { pub trait PubPrincipal {} auto trait PrivNonPrincipal {} diff --git a/tests/ui/privacy/private-in-public-non-principal-2.stderr b/tests/ui/privacy/private-in-public-non-principal-2.stderr index 7cc8bf0de..d3da2326a 100644 --- a/tests/ui/privacy/private-in-public-non-principal-2.stderr +++ b/tests/ui/privacy/private-in-public-non-principal-2.stderr @@ -4,5 +4,5 @@ error: trait `PrivNonPrincipal` is private LL | m::leak_dyn_nonprincipal(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ private trait -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/privacy/private-in-public-non-principal.rs b/tests/ui/privacy/private-in-public-non-principal.rs index ac1d5a9e6..e348a1816 100644 --- a/tests/ui/privacy/private-in-public-non-principal.rs +++ b/tests/ui/privacy/private-in-public-non-principal.rs @@ -5,8 +5,7 @@ pub trait PubPrincipal {} auto trait PrivNonPrincipal {} pub fn leak_dyn_nonprincipal() -> Box<dyn PubPrincipal + PrivNonPrincipal> { loop {} } -//~^ WARN private trait `PrivNonPrincipal` in public interface -//~| WARN this was previously accepted +//~^ WARN trait `PrivNonPrincipal` is more private than the item `leak_dyn_nonprincipal` #[deny(missing_docs)] fn container() { diff --git a/tests/ui/privacy/private-in-public-non-principal.stderr b/tests/ui/privacy/private-in-public-non-principal.stderr index de20cada4..73f2249bc 100644 --- a/tests/ui/privacy/private-in-public-non-principal.stderr +++ b/tests/ui/privacy/private-in-public-non-principal.stderr @@ -1,24 +1,27 @@ -warning: private trait `PrivNonPrincipal` in public interface (error E0445) +warning: trait `PrivNonPrincipal` is more private than the item `leak_dyn_nonprincipal` --> $DIR/private-in-public-non-principal.rs:7:1 | LL | pub fn leak_dyn_nonprincipal() -> Box<dyn PubPrincipal + PrivNonPrincipal> { loop {} } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `leak_dyn_nonprincipal` is reachable at visibility `pub` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> - = note: `#[warn(private_in_public)]` on by default +note: but trait `PrivNonPrincipal` is only usable at visibility `pub(crate)` + --> $DIR/private-in-public-non-principal.rs:5:1 + | +LL | auto trait PrivNonPrincipal {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: `#[warn(private_interfaces)]` on by default error: missing documentation for an associated function - --> $DIR/private-in-public-non-principal.rs:14:9 + --> $DIR/private-in-public-non-principal.rs:13:9 | LL | pub fn check_doc_lint() {} | ^^^^^^^^^^^^^^^^^^^^^^^ | note: the lint level is defined here - --> $DIR/private-in-public-non-principal.rs:11:8 + --> $DIR/private-in-public-non-principal.rs:10:8 | LL | #[deny(missing_docs)] | ^^^^^^^^^^^^ -error: aborting due to previous error; 1 warning emitted +error: aborting due to 1 previous error; 1 warning emitted diff --git a/tests/ui/privacy/private-in-public-type-alias-impl-trait.rs b/tests/ui/privacy/private-in-public-type-alias-impl-trait.rs index fe6ed4673..3fb543e96 100644 --- a/tests/ui/privacy/private-in-public-type-alias-impl-trait.rs +++ b/tests/ui/privacy/private-in-public-type-alias-impl-trait.rs @@ -1,7 +1,7 @@ // build-pass (FIXME(62277): could be check-pass?) #![feature(impl_trait_in_assoc_type)] #![feature(type_alias_impl_trait)] -#![deny(private_in_public)] +#![deny(private_interfaces, private_bounds)] pub type Pub = impl Default; diff --git a/tests/ui/privacy/private-in-public-warn.rs b/tests/ui/privacy/private-in-public-warn.rs index 0fa1de975..99d318e36 100644 --- a/tests/ui/privacy/private-in-public-warn.rs +++ b/tests/ui/privacy/private-in-public-warn.rs @@ -2,7 +2,7 @@ // This test also ensures that the checks are performed even inside private modules. #![feature(associated_type_defaults)] -#![deny(private_in_public)] +#![deny(private_interfaces, private_bounds)] #![allow(improper_ctypes)] mod types { @@ -12,30 +12,21 @@ mod types { type Alias; } - pub type Alias = Priv; //~ ERROR private type `types::Priv` in public interface - //~^ WARNING hard error + pub type Alias = Priv; //~ ERROR type `types::Priv` is more private than the item `types::Alias` pub enum E { - V1(Priv), //~ ERROR private type `types::Priv` in public interface - //~^ WARNING hard error - V2 { field: Priv }, //~ ERROR private type `types::Priv` in public interface - //~^ WARNING hard error + V1(Priv), //~ ERROR type `types::Priv` is more private than the item `E::V1::0` + V2 { field: Priv }, //~ ERROR type `types::Priv` is more private than the item `E::V2::field` } pub trait Tr { - const C: Priv = Priv; //~ ERROR private type `types::Priv` in public interface - //~^ WARNING hard error + const C: Priv = Priv; //~ ERROR type `types::Priv` is more private than the item `Tr::C` type Alias = Priv; //~ ERROR private type `types::Priv` in public interface - fn f1(arg: Priv) {} //~ ERROR private type `types::Priv` in public interface - //~^ WARNING hard error - fn f2() -> Priv { panic!() } //~ ERROR private type `types::Priv` in public interface - //~^ WARNING hard error + fn f1(arg: Priv) {} //~ ERROR type `types::Priv` is more private than the item `Tr::f1` + fn f2() -> Priv { panic!() } //~ ERROR type `types::Priv` is more private than the item `Tr::f2` } extern "C" { - pub static ES: Priv; //~ ERROR private type `types::Priv` in public interface - //~^ WARNING hard error - pub fn ef1(arg: Priv); //~ ERROR private type `types::Priv` in public interface - //~^ WARNING hard error - pub fn ef2() -> Priv; //~ ERROR private type `types::Priv` in public interface - //~^ WARNING hard error + pub static ES: Priv; //~ ERROR type `types::Priv` is more private than the item `types::ES` + pub fn ef1(arg: Priv); //~ ERROR type `types::Priv` is more private than the item `types::ef1` + pub fn ef2() -> Priv; //~ ERROR type `types::Priv` is more private than the item `types::ef2` } impl PubTr for Pub { type Alias = Priv; //~ ERROR private type `types::Priv` in public interface @@ -47,22 +38,16 @@ mod traits { pub struct Pub<T>(T); pub trait PubTr {} - pub type Alias<T: PrivTr> = T; //~ ERROR private trait `traits::PrivTr` in public interface - //~| WARNING hard error - //~| WARNING bounds on generic parameters are not enforced in type aliases - pub trait Tr1: PrivTr {} //~ ERROR private trait `traits::PrivTr` in public interface - //~^ WARNING hard error - pub trait Tr2<T: PrivTr> {} //~ ERROR private trait `traits::PrivTr` in public interface - //~^ WARNING hard error + pub type Alias<T: PrivTr> = T; //~ ERROR trait `traits::PrivTr` is more private than the item `traits::Alias` + //~^ WARNING bounds on generic parameters are not enforced in type aliases + pub trait Tr1: PrivTr {} //~ ERROR trait `traits::PrivTr` is more private than the item `traits::Tr1` + pub trait Tr2<T: PrivTr> {} //~ ERROR trait `traits::PrivTr` is more private than the item `traits::Tr2` pub trait Tr3 { type Alias: PrivTr; - //~^ ERROR private trait `traits::PrivTr` in public interface - //~| WARNING hard error - fn f<T: PrivTr>(arg: T) {} //~ ERROR private trait `traits::PrivTr` in public interface - //~^ WARNING hard error + //~^ ERROR trait `traits::PrivTr` is more private than the item `traits::Tr3::Alias` + fn f<T: PrivTr>(arg: T) {} //~ ERROR trait `traits::PrivTr` is more private than the item `traits::Tr3::f` } - impl<T: PrivTr> Pub<T> {} //~ ERROR private trait `traits::PrivTr` in public interface - //~^ WARNING hard error + impl<T: PrivTr> Pub<T> {} //~ ERROR trait `traits::PrivTr` is more private than the item `traits::Pub<T>` impl<T: PrivTr> PubTr for Pub<T> {} // OK, trait impl predicates } @@ -72,20 +57,16 @@ mod traits_where { pub trait PubTr {} pub type Alias<T> where T: PrivTr = T; - //~^ ERROR private trait `traits_where::PrivTr` in public interface - //~| WARNING hard error + //~^ ERROR trait `traits_where::PrivTr` is more private than the item `traits_where::Alias` //~| WARNING where clauses are not enforced in type aliases pub trait Tr2<T> where T: PrivTr {} - //~^ ERROR private trait `traits_where::PrivTr` in public interface - //~| WARNING hard error + //~^ ERROR trait `traits_where::PrivTr` is more private than the item `traits_where::Tr2` pub trait Tr3 { fn f<T>(arg: T) where T: PrivTr {} - //~^ ERROR private trait `traits_where::PrivTr` in public interface - //~| WARNING hard error + //~^ ERROR trait `traits_where::PrivTr` is more private than the item `traits_where::Tr3::f` } impl<T> Pub<T> where T: PrivTr {} - //~^ ERROR private trait `traits_where::PrivTr` in public interface - //~| WARNING hard error + //~^ ERROR trait `traits_where::PrivTr` is more private than the item `traits_where::Pub<T>` impl<T> PubTr for Pub<T> where T: PrivTr {} // OK, trait impl predicates } @@ -96,14 +77,10 @@ mod generics { pub trait PubTr<T> {} pub trait Tr1: PrivTr<Pub> {} - //~^ ERROR private trait `generics::PrivTr<generics::Pub>` in public interface - //~| WARNING hard error - pub trait Tr2: PubTr<Priv> {} //~ ERROR private type `generics::Priv` in public interface - //~^ WARNING hard error - pub trait Tr3: PubTr<[Priv; 1]> {} //~ ERROR private type `generics::Priv` in public interface - //~^ WARNING hard error - pub trait Tr4: PubTr<Pub<Priv>> {} //~ ERROR private type `generics::Priv` in public interface - //~^ WARNING hard error + //~^ ERROR trait `generics::PrivTr<generics::Pub>` is more private than the item `generics::Tr1` + pub trait Tr2: PubTr<Priv> {} //~ ERROR type `generics::Priv` is more private than the item `generics::Tr2` + pub trait Tr3: PubTr<[Priv; 1]> {} //~ ERROR type `generics::Priv` is more private than the item `generics::Tr3` + pub trait Tr4: PubTr<Pub<Priv>> {} //~ ERROR type `generics::Priv` is more private than the item `Tr4` } mod impls { @@ -200,8 +177,7 @@ mod aliases_pub { pub trait Tr2: PrivUseAliasTr<PrivAlias> {} // OK impl PrivAlias { - pub fn f(arg: Priv) {} //~ ERROR private type `aliases_pub::Priv` in public interface - //~^ WARNING hard error + pub fn f(arg: Priv) {} //~ ERROR type `aliases_pub::Priv` is more private than the item `aliases_pub::<impl Pub2>::f` } impl PrivUseAliasTr for PrivUseAlias { type Check = Priv; //~ ERROR private type `aliases_pub::Priv` in public interface @@ -244,13 +220,10 @@ mod aliases_priv { } pub trait Tr1: PrivUseAliasTr {} - //~^ ERROR private trait `PrivTr1` in public interface - //~| WARNING hard error + //~^ ERROR trait `PrivTr1` is more private than the item `aliases_priv::Tr1` pub trait Tr2: PrivUseAliasTr<PrivAlias> {} - //~^ ERROR private trait `PrivTr1<Priv2>` in public interface - //~| WARNING hard error - //~| ERROR private type `Priv2` in public interface - //~| WARNING hard error + //~^ ERROR trait `PrivTr1<Priv2>` is more private than the item `aliases_priv::Tr2` + //~| ERROR type `Priv2` is more private than the item `aliases_priv::Tr2` impl PrivUseAlias { pub fn f(arg: Priv) {} // OK diff --git a/tests/ui/privacy/private-in-public-warn.stderr b/tests/ui/privacy/private-in-public-warn.stderr index 66f91ce6f..ac7e5547d 100644 --- a/tests/ui/privacy/private-in-public-warn.stderr +++ b/tests/ui/privacy/private-in-public-warn.stderr @@ -1,46 +1,58 @@ -error: private type `types::Priv` in public interface (error E0446) +error: type `types::Priv` is more private than the item `types::Alias` --> $DIR/private-in-public-warn.rs:15:5 | LL | pub type Alias = Priv; - | ^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^ type alias `types::Alias` is reachable at visibility `pub(crate)` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:9:5 + | +LL | struct Priv; + | ^^^^^^^^^^^ note: the lint level is defined here --> $DIR/private-in-public-warn.rs:5:9 | -LL | #![deny(private_in_public)] - | ^^^^^^^^^^^^^^^^^ +LL | #![deny(private_interfaces, private_bounds)] + | ^^^^^^^^^^^^^^^^^^ -error: private type `types::Priv` in public interface (error E0446) - --> $DIR/private-in-public-warn.rs:18:12 +error: type `types::Priv` is more private than the item `E::V1::0` + --> $DIR/private-in-public-warn.rs:17:12 | LL | V1(Priv), - | ^^^^ + | ^^^^ field `E::V1::0` is reachable at visibility `pub(crate)` + | +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:9:5 | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +LL | struct Priv; + | ^^^^^^^^^^^ -error: private type `types::Priv` in public interface (error E0446) - --> $DIR/private-in-public-warn.rs:20:14 +error: type `types::Priv` is more private than the item `E::V2::field` + --> $DIR/private-in-public-warn.rs:18:14 | LL | V2 { field: Priv }, - | ^^^^^^^^^^^ + | ^^^^^^^^^^^ field `E::V2::field` is reachable at visibility `pub(crate)` + | +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:9:5 | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +LL | struct Priv; + | ^^^^^^^^^^^ -error: private type `types::Priv` in public interface (error E0446) - --> $DIR/private-in-public-warn.rs:24:9 +error: type `types::Priv` is more private than the item `Tr::C` + --> $DIR/private-in-public-warn.rs:21:9 | LL | const C: Priv = Priv; - | ^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^ associated constant `Tr::C` is reachable at visibility `pub(crate)` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:9:5 + | +LL | struct Priv; + | ^^^^^^^^^^^ error[E0446]: private type `types::Priv` in public interface - --> $DIR/private-in-public-warn.rs:26:9 + --> $DIR/private-in-public-warn.rs:22:9 | LL | struct Priv; | ----------- `types::Priv` declared as private @@ -48,53 +60,68 @@ LL | struct Priv; LL | type Alias = Priv; | ^^^^^^^^^^ can't leak private type -error: private type `types::Priv` in public interface (error E0446) - --> $DIR/private-in-public-warn.rs:27:9 +error: type `types::Priv` is more private than the item `Tr::f1` + --> $DIR/private-in-public-warn.rs:23:9 | LL | fn f1(arg: Priv) {} - | ^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ associated function `Tr::f1` is reachable at visibility `pub(crate)` + | +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:9:5 | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +LL | struct Priv; + | ^^^^^^^^^^^ -error: private type `types::Priv` in public interface (error E0446) - --> $DIR/private-in-public-warn.rs:29:9 +error: type `types::Priv` is more private than the item `Tr::f2` + --> $DIR/private-in-public-warn.rs:24:9 | LL | fn f2() -> Priv { panic!() } - | ^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^ associated function `Tr::f2` is reachable at visibility `pub(crate)` + | +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:9:5 | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +LL | struct Priv; + | ^^^^^^^^^^^ -error: private type `types::Priv` in public interface (error E0446) - --> $DIR/private-in-public-warn.rs:33:9 +error: type `types::Priv` is more private than the item `types::ES` + --> $DIR/private-in-public-warn.rs:27:9 | LL | pub static ES: Priv; - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^ static `types::ES` is reachable at visibility `pub(crate)` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:9:5 + | +LL | struct Priv; + | ^^^^^^^^^^^ -error: private type `types::Priv` in public interface (error E0446) - --> $DIR/private-in-public-warn.rs:35:9 +error: type `types::Priv` is more private than the item `types::ef1` + --> $DIR/private-in-public-warn.rs:28:9 | LL | pub fn ef1(arg: Priv); - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^ function `types::ef1` is reachable at visibility `pub(crate)` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:9:5 + | +LL | struct Priv; + | ^^^^^^^^^^^ -error: private type `types::Priv` in public interface (error E0446) - --> $DIR/private-in-public-warn.rs:37:9 +error: type `types::Priv` is more private than the item `types::ef2` + --> $DIR/private-in-public-warn.rs:29:9 | LL | pub fn ef2() -> Priv; - | ^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^ function `types::ef2` is reachable at visibility `pub(crate)` + | +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:9:5 | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +LL | struct Priv; + | ^^^^^^^^^^^ error[E0446]: private type `types::Priv` in public interface - --> $DIR/private-in-public-warn.rs:41:9 + --> $DIR/private-in-public-warn.rs:32:9 | LL | struct Priv; | ----------- `types::Priv` declared as private @@ -102,134 +129,181 @@ LL | struct Priv; LL | type Alias = Priv; | ^^^^^^^^^^ can't leak private type -error: private trait `traits::PrivTr` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:50:5 +error: trait `traits::PrivTr` is more private than the item `traits::Alias` + --> $DIR/private-in-public-warn.rs:41:5 | LL | pub type Alias<T: PrivTr> = T; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^ type alias `traits::Alias` is reachable at visibility `pub(crate)` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +note: but trait `traits::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:37:5 + | +LL | trait PrivTr {} + | ^^^^^^^^^^^^ +note: the lint level is defined here + --> $DIR/private-in-public-warn.rs:5:29 + | +LL | #![deny(private_interfaces, private_bounds)] + | ^^^^^^^^^^^^^^ -error: private trait `traits::PrivTr` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:53:5 +error: trait `traits::PrivTr` is more private than the item `traits::Tr1` + --> $DIR/private-in-public-warn.rs:43:5 | LL | pub trait Tr1: PrivTr {} - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^ trait `traits::Tr1` is reachable at visibility `pub(crate)` + | +note: but trait `traits::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:37:5 | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +LL | trait PrivTr {} + | ^^^^^^^^^^^^ -error: private trait `traits::PrivTr` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:55:5 +error: trait `traits::PrivTr` is more private than the item `traits::Tr2` + --> $DIR/private-in-public-warn.rs:44:5 | LL | pub trait Tr2<T: PrivTr> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^ trait `traits::Tr2` is reachable at visibility `pub(crate)` + | +note: but trait `traits::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:37:5 | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +LL | trait PrivTr {} + | ^^^^^^^^^^^^ -error: private trait `traits::PrivTr` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:58:9 +error: trait `traits::PrivTr` is more private than the item `traits::Tr3::Alias` + --> $DIR/private-in-public-warn.rs:46:9 | LL | type Alias: PrivTr; - | ^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^ associated type `traits::Tr3::Alias` is reachable at visibility `pub(crate)` + | +note: but trait `traits::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:37:5 | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +LL | trait PrivTr {} + | ^^^^^^^^^^^^ -error: private trait `traits::PrivTr` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:61:9 +error: trait `traits::PrivTr` is more private than the item `traits::Tr3::f` + --> $DIR/private-in-public-warn.rs:48:9 | LL | fn f<T: PrivTr>(arg: T) {} - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^ associated function `traits::Tr3::f` is reachable at visibility `pub(crate)` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +note: but trait `traits::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:37:5 + | +LL | trait PrivTr {} + | ^^^^^^^^^^^^ -error: private trait `traits::PrivTr` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:64:5 +error: trait `traits::PrivTr` is more private than the item `traits::Pub<T>` + --> $DIR/private-in-public-warn.rs:50:5 | LL | impl<T: PrivTr> Pub<T> {} - | ^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^ implementation `traits::Pub<T>` is reachable at visibility `pub(crate)` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +note: but trait `traits::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:37:5 + | +LL | trait PrivTr {} + | ^^^^^^^^^^^^ -error: private trait `traits_where::PrivTr` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:74:5 +error: trait `traits_where::PrivTr` is more private than the item `traits_where::Alias` + --> $DIR/private-in-public-warn.rs:59:5 | LL | pub type Alias<T> where T: PrivTr = T; - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ type alias `traits_where::Alias` is reachable at visibility `pub(crate)` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:55:5 + | +LL | trait PrivTr {} + | ^^^^^^^^^^^^ -error: private trait `traits_where::PrivTr` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:78:5 +error: trait `traits_where::PrivTr` is more private than the item `traits_where::Tr2` + --> $DIR/private-in-public-warn.rs:62:5 | LL | pub trait Tr2<T> where T: PrivTr {} - | ^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ trait `traits_where::Tr2` is reachable at visibility `pub(crate)` + | +note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:55:5 | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +LL | trait PrivTr {} + | ^^^^^^^^^^^^ -error: private trait `traits_where::PrivTr` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:82:9 +error: trait `traits_where::PrivTr` is more private than the item `traits_where::Tr3::f` + --> $DIR/private-in-public-warn.rs:65:9 | LL | fn f<T>(arg: T) where T: PrivTr {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated function `traits_where::Tr3::f` is reachable at visibility `pub(crate)` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:55:5 + | +LL | trait PrivTr {} + | ^^^^^^^^^^^^ -error: private trait `traits_where::PrivTr` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:86:5 +error: trait `traits_where::PrivTr` is more private than the item `traits_where::Pub<T>` + --> $DIR/private-in-public-warn.rs:68:5 | LL | impl<T> Pub<T> where T: PrivTr {} - | ^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation `traits_where::Pub<T>` is reachable at visibility `pub(crate)` + | +note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:55:5 | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +LL | trait PrivTr {} + | ^^^^^^^^^^^^ -error: private trait `generics::PrivTr<generics::Pub>` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:98:5 +error: trait `generics::PrivTr<generics::Pub>` is more private than the item `generics::Tr1` + --> $DIR/private-in-public-warn.rs:79:5 | LL | pub trait Tr1: PrivTr<Pub> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `generics::Tr1` is reachable at visibility `pub(crate)` + | +note: but trait `generics::PrivTr<generics::Pub>` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:76:5 | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +LL | trait PrivTr<T> {} + | ^^^^^^^^^^^^^^^ -error: private type `generics::Priv` in public interface (error E0446) - --> $DIR/private-in-public-warn.rs:101:5 +error: type `generics::Priv` is more private than the item `generics::Tr2` + --> $DIR/private-in-public-warn.rs:81:5 | LL | pub trait Tr2: PubTr<Priv> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `generics::Tr2` is reachable at visibility `pub(crate)` + | +note: but type `generics::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:74:5 | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +LL | struct Priv<T = u8>(T); + | ^^^^^^^^^^^^^^^^^^^ -error: private type `generics::Priv` in public interface (error E0446) - --> $DIR/private-in-public-warn.rs:103:5 +error: type `generics::Priv` is more private than the item `generics::Tr3` + --> $DIR/private-in-public-warn.rs:82:5 | LL | pub trait Tr3: PubTr<[Priv; 1]> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `generics::Tr3` is reachable at visibility `pub(crate)` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +note: but type `generics::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:74:5 + | +LL | struct Priv<T = u8>(T); + | ^^^^^^^^^^^^^^^^^^^ -error: private type `generics::Priv` in public interface (error E0446) - --> $DIR/private-in-public-warn.rs:105:5 +error: type `generics::Priv` is more private than the item `Tr4` + --> $DIR/private-in-public-warn.rs:83:5 | LL | pub trait Tr4: PubTr<Pub<Priv>> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `Tr4` is reachable at visibility `pub(crate)` + | +note: but type `generics::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:74:5 | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +LL | struct Priv<T = u8>(T); + | ^^^^^^^^^^^^^^^^^^^ error[E0446]: private type `impls::Priv` in public interface - --> $DIR/private-in-public-warn.rs:132:9 + --> $DIR/private-in-public-warn.rs:109:9 | LL | struct Priv; | ----------- `impls::Priv` declared as private @@ -237,17 +311,20 @@ LL | struct Priv; LL | type Alias = Priv; | ^^^^^^^^^^ can't leak private type -error: private type `aliases_pub::Priv` in public interface (error E0446) - --> $DIR/private-in-public-warn.rs:203:9 +error: type `aliases_pub::Priv` is more private than the item `aliases_pub::<impl Pub2>::f` + --> $DIR/private-in-public-warn.rs:180:9 | LL | pub fn f(arg: Priv) {} - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^ associated function `aliases_pub::<impl Pub2>::f` is reachable at visibility `pub(crate)` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +note: but type `aliases_pub::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:153:5 + | +LL | struct Priv; + | ^^^^^^^^^^^ error[E0446]: private type `aliases_pub::Priv` in public interface - --> $DIR/private-in-public-warn.rs:207:9 + --> $DIR/private-in-public-warn.rs:183:9 | LL | struct Priv; | ----------- `aliases_pub::Priv` declared as private @@ -256,7 +333,7 @@ LL | type Check = Priv; | ^^^^^^^^^^ can't leak private type error[E0446]: private type `aliases_pub::Priv` in public interface - --> $DIR/private-in-public-warn.rs:210:9 + --> $DIR/private-in-public-warn.rs:186:9 | LL | struct Priv; | ----------- `aliases_pub::Priv` declared as private @@ -265,7 +342,7 @@ LL | type Check = Priv; | ^^^^^^^^^^ can't leak private type error[E0446]: private type `aliases_pub::Priv` in public interface - --> $DIR/private-in-public-warn.rs:213:9 + --> $DIR/private-in-public-warn.rs:189:9 | LL | struct Priv; | ----------- `aliases_pub::Priv` declared as private @@ -274,7 +351,7 @@ LL | type Check = Priv; | ^^^^^^^^^^ can't leak private type error[E0446]: private type `aliases_pub::Priv` in public interface - --> $DIR/private-in-public-warn.rs:216:9 + --> $DIR/private-in-public-warn.rs:192:9 | LL | struct Priv; | ----------- `aliases_pub::Priv` declared as private @@ -282,35 +359,44 @@ LL | struct Priv; LL | type Check = Priv; | ^^^^^^^^^^ can't leak private type -error: private trait `PrivTr1` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:246:5 +error: trait `PrivTr1` is more private than the item `aliases_priv::Tr1` + --> $DIR/private-in-public-warn.rs:222:5 | LL | pub trait Tr1: PrivUseAliasTr {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `aliases_priv::Tr1` is reachable at visibility `pub(crate)` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +note: but trait `PrivTr1` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:208:5 + | +LL | trait PrivTr1<T = u8> { + | ^^^^^^^^^^^^^^^^^^^^^ -error: private trait `PrivTr1<Priv2>` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:249:5 +error: trait `PrivTr1<Priv2>` is more private than the item `aliases_priv::Tr2` + --> $DIR/private-in-public-warn.rs:224:5 | LL | pub trait Tr2: PrivUseAliasTr<PrivAlias> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `aliases_priv::Tr2` is reachable at visibility `pub(crate)` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +note: but trait `PrivTr1<Priv2>` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:208:5 + | +LL | trait PrivTr1<T = u8> { + | ^^^^^^^^^^^^^^^^^^^^^ -error: private type `Priv2` in public interface (error E0446) - --> $DIR/private-in-public-warn.rs:249:5 +error: type `Priv2` is more private than the item `aliases_priv::Tr2` + --> $DIR/private-in-public-warn.rs:224:5 | LL | pub trait Tr2: PrivUseAliasTr<PrivAlias> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `aliases_priv::Tr2` is reachable at visibility `pub(crate)` + | +note: but type `Priv2` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:206:5 | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +LL | struct Priv2; + | ^^^^^^^^^^^^ warning: bounds on generic parameters are not enforced in type aliases - --> $DIR/private-in-public-warn.rs:50:23 + --> $DIR/private-in-public-warn.rs:41:23 | LL | pub type Alias<T: PrivTr> = T; | ^^^^^^ @@ -323,7 +409,7 @@ LL + pub type Alias<T> = T; | warning: where clauses are not enforced in type aliases - --> $DIR/private-in-public-warn.rs:74:29 + --> $DIR/private-in-public-warn.rs:59:29 | LL | pub type Alias<T> where T: PrivTr = T; | ^^^^^^^^^ diff --git a/tests/ui/privacy/private-in-public.rs b/tests/ui/privacy/private-in-public.rs index dbd1c483f..7b8e0fbe6 100644 --- a/tests/ui/privacy/private-in-public.rs +++ b/tests/ui/privacy/private-in-public.rs @@ -1,3 +1,5 @@ +// check-pass + // Private types and traits are not allowed in public interfaces. // This test also ensures that the checks are performed even inside private modules. @@ -10,16 +12,16 @@ mod types { type Alias; } - pub const C: Priv = Priv; //~ ERROR private type `types::Priv` in public interface - pub static S: Priv = Priv; //~ ERROR private type `types::Priv` in public interface - pub fn f1(arg: Priv) {} //~ ERROR private type `types::Priv` in public interface - pub fn f2() -> Priv { panic!() } //~ ERROR private type `types::Priv` in public interface - pub struct S1(pub Priv); //~ ERROR private type `types::Priv` in public interface - pub struct S2 { pub field: Priv } //~ ERROR private type `types::Priv` in public interface + pub const C: Priv = Priv; //~ WARNING type `types::Priv` is more private than the item `C` + pub static S: Priv = Priv; //~ WARNING type `types::Priv` is more private than the item `S` + pub fn f1(arg: Priv) {} //~ WARNING `types::Priv` is more private than the item `types::f1` + pub fn f2() -> Priv { panic!() } //~ WARNING type `types::Priv` is more private than the item `types::f2` + pub struct S1(pub Priv); //~ WARNING type `types::Priv` is more private than the item `types::S1::0` + pub struct S2 { pub field: Priv } //~ WARNING `types::Priv` is more private than the item `S2::field` impl Pub { - pub const C: Priv = Priv; //~ ERROR private type `types::Priv` in public interface - pub fn f1(arg: Priv) {} //~ ERROR private type `types::Priv` in public interface - pub fn f2() -> Priv { panic!() } //~ ERROR private type `types::Priv` in public interface + pub const C: Priv = Priv; //~ WARNING type `types::Priv` is more private than the item `types::Pub::C` + pub fn f1(arg: Priv) {} //~ WARNING type `types::Priv` is more private than the item `types::Pub::f1` + pub fn f2() -> Priv { panic!() } //~ WARNING type `types::Priv` is more private than the item `types::Pub::f2` } } @@ -28,11 +30,11 @@ mod traits { pub struct Pub<T>(T); pub trait PubTr {} - pub enum E<T: PrivTr> { V(T) } //~ ERROR private trait `traits::PrivTr` in public interface - pub fn f<T: PrivTr>(arg: T) {} //~ ERROR private trait `traits::PrivTr` in public interface - pub struct S1<T: PrivTr>(T); //~ ERROR private trait `traits::PrivTr` in public interface - impl<T: PrivTr> Pub<T> { //~ ERROR private trait `traits::PrivTr` in public interface - pub fn f<U: PrivTr>(arg: U) {} //~ ERROR private trait `traits::PrivTr` in public interface + pub enum E<T: PrivTr> { V(T) } //~ WARNING trait `traits::PrivTr` is more private than the item `traits::E` + pub fn f<T: PrivTr>(arg: T) {} //~ WARNING trait `traits::PrivTr` is more private than the item `traits::f` + pub struct S1<T: PrivTr>(T); //~ WARNING trait `traits::PrivTr` is more private than the item `traits::S1` + impl<T: PrivTr> Pub<T> { //~ WARNING trait `traits::PrivTr` is more private than the item `traits::Pub<T>` + pub fn f<U: PrivTr>(arg: U) {} //~ WARNING trait `traits::PrivTr` is more private than the item `traits::Pub::<T>::f` } } @@ -42,15 +44,15 @@ mod traits_where { pub trait PubTr {} pub enum E<T> where T: PrivTr { V(T) } - //~^ ERROR private trait `traits_where::PrivTr` in public interface + //~^ WARNING trait `traits_where::PrivTr` is more private than the item `traits_where::E` pub fn f<T>(arg: T) where T: PrivTr {} - //~^ ERROR private trait `traits_where::PrivTr` in public interface + //~^ WARNING trait `traits_where::PrivTr` is more private than the item `traits_where::f` pub struct S1<T>(T) where T: PrivTr; - //~^ ERROR private trait `traits_where::PrivTr` in public interface + //~^ WARNING trait `traits_where::PrivTr` is more private than the item `traits_where::S1` impl<T> Pub<T> where T: PrivTr { - //~^ ERROR private trait `traits_where::PrivTr` in public interface + //~^ WARNING trait `traits_where::PrivTr` is more private than the item `traits_where::Pub<T>` pub fn f<U>(arg: U) where U: PrivTr {} - //~^ ERROR private trait `traits_where::PrivTr` in public interface + //~^ WARNING trait `traits_where::PrivTr` is more private than the item `traits_where::Pub::<T>::f` } } @@ -60,10 +62,10 @@ mod generics { trait PrivTr<T> {} pub trait PubTr<T> {} - pub fn f1(arg: [Priv; 1]) {} //~ ERROR private type `generics::Priv` in public interface - pub fn f2(arg: Pub<Priv>) {} //~ ERROR private type `generics::Priv` in public interface + pub fn f1(arg: [Priv; 1]) {} //~ WARNING type `generics::Priv` is more private than the item `generics::f1` + pub fn f2(arg: Pub<Priv>) {} //~ WARNING type `generics::Priv` is more private than the item `generics::f2` pub fn f3(arg: Priv<Pub>) {} - //~^ ERROR private type `generics::Priv<generics::Pub>` in public interface + //~^ WARNING type `generics::Priv<generics::Pub>` is more private than the item `generics::f3` } mod impls { @@ -77,7 +79,7 @@ mod impls { } impl Pub { - pub fn f(arg: Priv) {} //~ ERROR private type `impls::Priv` in public interface + pub fn f(arg: Priv) {} //~ WARNING type `impls::Priv` is more private than the item `impls::Pub::f` } } @@ -102,11 +104,12 @@ mod aliases_pub { // This should be OK, but associated type aliases are not substituted yet pub fn f3(arg: <Priv as PrivTr>::Assoc) {} - //~^ ERROR private trait `aliases_pub::PrivTr` in public interface - //~| ERROR private type `aliases_pub::Priv` in public interface + //~^ WARNING type `aliases_pub::Priv` is more private than the item `aliases_pub::f3` + //~| WARNING associated type `aliases_pub::PrivTr::Assoc` is more private than the item `aliases_pub::f3` + //~^^^ WARNING trait `aliases_pub::PrivTr` is more private than the item `aliases_pub::f3` impl PrivUseAlias { - pub fn f(arg: Priv) {} //~ ERROR private type `aliases_pub::Priv` in public interface + pub fn f(arg: Priv) {} } } @@ -128,11 +131,12 @@ mod aliases_priv { } impl PrivTr for Priv {} - pub fn f1(arg: PrivUseAlias) {} //~ ERROR private type `Priv1` in public interface - pub fn f2(arg: PrivAlias) {} //~ ERROR private type `Priv2` in public interface + pub fn f1(arg: PrivUseAlias) {} //~ WARNING type `Priv1` is more private than the item `aliases_priv::f1` + pub fn f2(arg: PrivAlias) {} //~ WARNING type `Priv2` is more private than the item `aliases_priv::f2` pub fn f3(arg: <Priv as PrivTr>::Assoc) {} - //~^ ERROR private trait `aliases_priv::PrivTr` in public interface - //~| ERROR private type `aliases_priv::Priv` in public interface + //~^ WARNING type `aliases_priv::Priv` is more private than the item `aliases_priv::f3` + //~| WARNING associated type `aliases_priv::PrivTr::Assoc` is more private than the item `aliases_priv::f3` + //~^^^ WARNING trait `aliases_priv::PrivTr` is more private than the item `aliases_priv::f3` } mod aliases_params { @@ -141,8 +145,8 @@ mod aliases_params { type Result<T> = ::std::result::Result<T, Priv>; pub fn f2(arg: PrivAliasGeneric) {} - //~^ ERROR private type `aliases_params::Priv` in public interface - pub fn f3(arg: Result<u8>) {} //~ ERROR private type `aliases_params::Priv` in public interface + //~^ WARNING type `aliases_params::Priv` is more private than the item `aliases_params::f2` + pub fn f3(arg: Result<u8>) {} //~ WARNING type `aliases_params::Priv` is more private than the item `aliases_params::f3` } fn main() {} diff --git a/tests/ui/privacy/private-in-public.stderr b/tests/ui/privacy/private-in-public.stderr index 887eebf53..ff3061337 100644 --- a/tests/ui/privacy/private-in-public.stderr +++ b/tests/ui/privacy/private-in-public.stderr @@ -1,292 +1,400 @@ -error[E0446]: private type `types::Priv` in public interface - --> $DIR/private-in-public.rs:13:5 +warning: type `types::Priv` is more private than the item `C` + --> $DIR/private-in-public.rs:15:5 | -LL | struct Priv; - | ----------- `types::Priv` declared as private -... LL | pub const C: Priv = Priv; - | ^^^^^^^^^^^^^^^^^ can't leak private type - -error[E0446]: private type `types::Priv` in public interface - --> $DIR/private-in-public.rs:14:5 + | ^^^^^^^^^^^^^^^^^ constant `C` is reachable at visibility `pub(crate)` | -LL | struct Priv; - | ----------- `types::Priv` declared as private -... -LL | pub static S: Priv = Priv; - | ^^^^^^^^^^^^^^^^^^ can't leak private type - -error[E0446]: private type `types::Priv` in public interface - --> $DIR/private-in-public.rs:15:5 +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:9:5 | LL | struct Priv; - | ----------- `types::Priv` declared as private -... -LL | pub fn f1(arg: Priv) {} - | ^^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^ + = note: `#[warn(private_interfaces)]` on by default -error[E0446]: private type `types::Priv` in public interface +warning: type `types::Priv` is more private than the item `S` --> $DIR/private-in-public.rs:16:5 | +LL | pub static S: Priv = Priv; + | ^^^^^^^^^^^^^^^^^^ static `S` is reachable at visibility `pub(crate)` + | +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:9:5 + | LL | struct Priv; - | ----------- `types::Priv` declared as private -... -LL | pub fn f2() -> Priv { panic!() } - | ^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^ -error[E0446]: private type `types::Priv` in public interface - --> $DIR/private-in-public.rs:17:19 +warning: type `types::Priv` is more private than the item `types::f1` + --> $DIR/private-in-public.rs:17:5 + | +LL | pub fn f1(arg: Priv) {} + | ^^^^^^^^^^^^^^^^^^^^ function `types::f1` is reachable at visibility `pub(crate)` + | +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:9:5 | LL | struct Priv; - | ----------- `types::Priv` declared as private -... -LL | pub struct S1(pub Priv); - | ^^^^^^^^ can't leak private type + | ^^^^^^^^^^^ -error[E0446]: private type `types::Priv` in public interface - --> $DIR/private-in-public.rs:18:21 +warning: type `types::Priv` is more private than the item `types::f2` + --> $DIR/private-in-public.rs:18:5 + | +LL | pub fn f2() -> Priv { panic!() } + | ^^^^^^^^^^^^^^^^^^^ function `types::f2` is reachable at visibility `pub(crate)` + | +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:9:5 | LL | struct Priv; - | ----------- `types::Priv` declared as private -... -LL | pub struct S2 { pub field: Priv } - | ^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^ -error[E0446]: private type `types::Priv` in public interface - --> $DIR/private-in-public.rs:20:9 +warning: type `types::Priv` is more private than the item `types::S1::0` + --> $DIR/private-in-public.rs:19:19 + | +LL | pub struct S1(pub Priv); + | ^^^^^^^^ field `types::S1::0` is reachable at visibility `pub(crate)` + | +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:9:5 | LL | struct Priv; - | ----------- `types::Priv` declared as private -... -LL | pub const C: Priv = Priv; - | ^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^ -error[E0446]: private type `types::Priv` in public interface - --> $DIR/private-in-public.rs:21:9 +warning: type `types::Priv` is more private than the item `S2::field` + --> $DIR/private-in-public.rs:20:21 + | +LL | pub struct S2 { pub field: Priv } + | ^^^^^^^^^^^^^^^ field `S2::field` is reachable at visibility `pub(crate)` + | +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:9:5 | LL | struct Priv; - | ----------- `types::Priv` declared as private -... -LL | pub fn f1(arg: Priv) {} - | ^^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^ -error[E0446]: private type `types::Priv` in public interface +warning: type `types::Priv` is more private than the item `types::Pub::C` --> $DIR/private-in-public.rs:22:9 | +LL | pub const C: Priv = Priv; + | ^^^^^^^^^^^^^^^^^ associated constant `types::Pub::C` is reachable at visibility `pub(crate)` + | +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:9:5 + | LL | struct Priv; - | ----------- `types::Priv` declared as private -... -LL | pub fn f2() -> Priv { panic!() } - | ^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^ -error[E0445]: private trait `traits::PrivTr` in public interface - --> $DIR/private-in-public.rs:31:5 +warning: type `types::Priv` is more private than the item `types::Pub::f1` + --> $DIR/private-in-public.rs:23:9 | -LL | trait PrivTr {} - | ------------ `traits::PrivTr` declared as private -... -LL | pub enum E<T: PrivTr> { V(T) } - | ^^^^^^^^^^^^^^^^^^^^^ can't leak private trait +LL | pub fn f1(arg: Priv) {} + | ^^^^^^^^^^^^^^^^^^^^ associated function `types::Pub::f1` is reachable at visibility `pub(crate)` + | +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:9:5 + | +LL | struct Priv; + | ^^^^^^^^^^^ -error[E0445]: private trait `traits::PrivTr` in public interface - --> $DIR/private-in-public.rs:32:5 +warning: type `types::Priv` is more private than the item `types::Pub::f2` + --> $DIR/private-in-public.rs:24:9 | -LL | trait PrivTr {} - | ------------ `traits::PrivTr` declared as private -... -LL | pub fn f<T: PrivTr>(arg: T) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait +LL | pub fn f2() -> Priv { panic!() } + | ^^^^^^^^^^^^^^^^^^^ associated function `types::Pub::f2` is reachable at visibility `pub(crate)` + | +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:9:5 + | +LL | struct Priv; + | ^^^^^^^^^^^ -error[E0445]: private trait `traits::PrivTr` in public interface +warning: trait `traits::PrivTr` is more private than the item `traits::E` --> $DIR/private-in-public.rs:33:5 | +LL | pub enum E<T: PrivTr> { V(T) } + | ^^^^^^^^^^^^^^^^^^^^^ enum `traits::E` is reachable at visibility `pub(crate)` + | +note: but trait `traits::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:29:5 + | LL | trait PrivTr {} - | ------------ `traits::PrivTr` declared as private -... -LL | pub struct S1<T: PrivTr>(T); - | ^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait + | ^^^^^^^^^^^^ + = note: `#[warn(private_bounds)]` on by default -error[E0445]: private trait `traits::PrivTr` in public interface +warning: trait `traits::PrivTr` is more private than the item `traits::f` --> $DIR/private-in-public.rs:34:5 | +LL | pub fn f<T: PrivTr>(arg: T) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `traits::f` is reachable at visibility `pub(crate)` + | +note: but trait `traits::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:29:5 + | LL | trait PrivTr {} - | ------------ `traits::PrivTr` declared as private -... -LL | impl<T: PrivTr> Pub<T> { - | ^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait + | ^^^^^^^^^^^^ + +warning: trait `traits::PrivTr` is more private than the item `traits::S1` + --> $DIR/private-in-public.rs:35:5 + | +LL | pub struct S1<T: PrivTr>(T); + | ^^^^^^^^^^^^^^^^^^^^^^^^ struct `traits::S1` is reachable at visibility `pub(crate)` + | +note: but trait `traits::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:29:5 + | +LL | trait PrivTr {} + | ^^^^^^^^^^^^ -error[E0445]: private trait `traits::PrivTr` in public interface - --> $DIR/private-in-public.rs:35:9 +warning: trait `traits::PrivTr` is more private than the item `traits::Pub<T>` + --> $DIR/private-in-public.rs:36:5 + | +LL | impl<T: PrivTr> Pub<T> { + | ^^^^^^^^^^^^^^^^^^^^^^ implementation `traits::Pub<T>` is reachable at visibility `pub(crate)` + | +note: but trait `traits::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:29:5 | LL | trait PrivTr {} - | ------------ `traits::PrivTr` declared as private -... -LL | pub fn f<U: PrivTr>(arg: U) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait + | ^^^^^^^^^^^^ -error[E0445]: private trait `traits_where::PrivTr` in public interface - --> $DIR/private-in-public.rs:44:5 +warning: trait `traits::PrivTr` is more private than the item `traits::Pub::<T>::f` + --> $DIR/private-in-public.rs:37:9 + | +LL | pub fn f<U: PrivTr>(arg: U) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated function `traits::Pub::<T>::f` is reachable at visibility `pub(crate)` + | +note: but trait `traits::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:29:5 | LL | trait PrivTr {} - | ------------ `traits_where::PrivTr` declared as private -... -LL | pub enum E<T> where T: PrivTr { V(T) } - | ^^^^^^^^^^^^^ can't leak private trait + | ^^^^^^^^^^^^ -error[E0445]: private trait `traits_where::PrivTr` in public interface +warning: trait `traits_where::PrivTr` is more private than the item `traits_where::E` --> $DIR/private-in-public.rs:46:5 | +LL | pub enum E<T> where T: PrivTr { V(T) } + | ^^^^^^^^^^^^^ enum `traits_where::E` is reachable at visibility `pub(crate)` + | +note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:42:5 + | LL | trait PrivTr {} - | ------------ `traits_where::PrivTr` declared as private -... -LL | pub fn f<T>(arg: T) where T: PrivTr {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait + | ^^^^^^^^^^^^ -error[E0445]: private trait `traits_where::PrivTr` in public interface +warning: trait `traits_where::PrivTr` is more private than the item `traits_where::f` --> $DIR/private-in-public.rs:48:5 | +LL | pub fn f<T>(arg: T) where T: PrivTr {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `traits_where::f` is reachable at visibility `pub(crate)` + | +note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:42:5 + | LL | trait PrivTr {} - | ------------ `traits_where::PrivTr` declared as private -... -LL | pub struct S1<T>(T) where T: PrivTr; - | ^^^^^^^^^^^^^^^^ can't leak private trait + | ^^^^^^^^^^^^ -error[E0445]: private trait `traits_where::PrivTr` in public interface +warning: trait `traits_where::PrivTr` is more private than the item `traits_where::S1` --> $DIR/private-in-public.rs:50:5 | +LL | pub struct S1<T>(T) where T: PrivTr; + | ^^^^^^^^^^^^^^^^ struct `traits_where::S1` is reachable at visibility `pub(crate)` + | +note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:42:5 + | LL | trait PrivTr {} - | ------------ `traits_where::PrivTr` declared as private -... -LL | impl<T> Pub<T> where T: PrivTr { - | ^^^^^^^^^^^^^^ can't leak private trait + | ^^^^^^^^^^^^ -error[E0445]: private trait `traits_where::PrivTr` in public interface - --> $DIR/private-in-public.rs:52:9 +warning: trait `traits_where::PrivTr` is more private than the item `traits_where::Pub<T>` + --> $DIR/private-in-public.rs:52:5 + | +LL | impl<T> Pub<T> where T: PrivTr { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation `traits_where::Pub<T>` is reachable at visibility `pub(crate)` + | +note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:42:5 | LL | trait PrivTr {} - | ------------ `traits_where::PrivTr` declared as private -... + | ^^^^^^^^^^^^ + +warning: trait `traits_where::PrivTr` is more private than the item `traits_where::Pub::<T>::f` + --> $DIR/private-in-public.rs:54:9 + | LL | pub fn f<U>(arg: U) where U: PrivTr {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated function `traits_where::Pub::<T>::f` is reachable at visibility `pub(crate)` + | +note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:42:5 + | +LL | trait PrivTr {} + | ^^^^^^^^^^^^ -error[E0446]: private type `generics::Priv` in public interface - --> $DIR/private-in-public.rs:63:5 +warning: type `generics::Priv` is more private than the item `generics::f1` + --> $DIR/private-in-public.rs:65:5 | -LL | struct Priv<T = u8>(T); - | ------------------- `generics::Priv` declared as private -... LL | pub fn f1(arg: [Priv; 1]) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type - -error[E0446]: private type `generics::Priv` in public interface - --> $DIR/private-in-public.rs:64:5 + | ^^^^^^^^^^^^^^^^^^^^^^^^^ function `generics::f1` is reachable at visibility `pub(crate)` + | +note: but type `generics::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:60:5 | LL | struct Priv<T = u8>(T); - | ------------------- `generics::Priv` declared as private -... -LL | pub fn f2(arg: Pub<Priv>) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^^^^^^^^^ -error[E0446]: private type `generics::Priv<generics::Pub>` in public interface - --> $DIR/private-in-public.rs:65:5 +warning: type `generics::Priv` is more private than the item `generics::f2` + --> $DIR/private-in-public.rs:66:5 + | +LL | pub fn f2(arg: Pub<Priv>) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^ function `generics::f2` is reachable at visibility `pub(crate)` + | +note: but type `generics::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:60:5 | LL | struct Priv<T = u8>(T); - | ------------------- `generics::Priv<generics::Pub>` declared as private -... + | ^^^^^^^^^^^^^^^^^^^ + +warning: type `generics::Priv<generics::Pub>` is more private than the item `generics::f3` + --> $DIR/private-in-public.rs:67:5 + | LL | pub fn f3(arg: Priv<Pub>) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^^^^^^^^^^^^^^^ function `generics::f3` is reachable at visibility `pub(crate)` + | +note: but type `generics::Priv<generics::Pub>` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:60:5 + | +LL | struct Priv<T = u8>(T); + | ^^^^^^^^^^^^^^^^^^^ -error[E0446]: private type `impls::Priv` in public interface - --> $DIR/private-in-public.rs:80:9 +warning: type `impls::Priv` is more private than the item `impls::Pub::f` + --> $DIR/private-in-public.rs:82:9 | -LL | struct Priv; - | ----------- `impls::Priv` declared as private -... LL | pub fn f(arg: Priv) {} - | ^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^^^^^^^^^ associated function `impls::Pub::f` is reachable at visibility `pub(crate)` + | +note: but type `impls::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:72:5 + | +LL | struct Priv; + | ^^^^^^^^^^^ -error[E0445]: private trait `aliases_pub::PrivTr` in public interface - --> $DIR/private-in-public.rs:104:5 +warning: associated type `aliases_pub::PrivTr::Assoc` is more private than the item `aliases_pub::f3` + --> $DIR/private-in-public.rs:106:5 | -LL | trait PrivTr { - | ------------ `aliases_pub::PrivTr` declared as private -... LL | pub fn f3(arg: <Priv as PrivTr>::Assoc) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `aliases_pub::f3` is reachable at visibility `pub(crate)` + | +note: but associated type `aliases_pub::PrivTr::Assoc` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:101:9 + | +LL | type Assoc = m::Pub3; + | ^^^^^^^^^^ -error[E0446]: private type `aliases_pub::Priv` in public interface - --> $DIR/private-in-public.rs:104:5 +warning: trait `aliases_pub::PrivTr` is more private than the item `aliases_pub::f3` + --> $DIR/private-in-public.rs:106:5 | -LL | struct Priv; - | ----------- `aliases_pub::Priv` declared as private -... LL | pub fn f3(arg: <Priv as PrivTr>::Assoc) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `aliases_pub::f3` is reachable at visibility `pub(crate)` + | +note: but trait `aliases_pub::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:100:5 + | +LL | trait PrivTr { + | ^^^^^^^^^^^^ -error[E0446]: private type `aliases_pub::Priv` in public interface - --> $DIR/private-in-public.rs:109:9 +warning: type `aliases_pub::Priv` is more private than the item `aliases_pub::f3` + --> $DIR/private-in-public.rs:106:5 + | +LL | pub fn f3(arg: <Priv as PrivTr>::Assoc) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `aliases_pub::f3` is reachable at visibility `pub(crate)` + | +note: but type `aliases_pub::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:87:5 | LL | struct Priv; - | ----------- `aliases_pub::Priv` declared as private -... -LL | pub fn f(arg: Priv) {} - | ^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^ -error[E0446]: private type `Priv1` in public interface - --> $DIR/private-in-public.rs:131:5 +warning: type `Priv1` is more private than the item `aliases_priv::f1` + --> $DIR/private-in-public.rs:134:5 | -LL | struct Priv1; - | ------------ `Priv1` declared as private -... LL | pub fn f1(arg: PrivUseAlias) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `aliases_priv::f1` is reachable at visibility `pub(crate)` + | +note: but type `Priv1` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:119:5 + | +LL | struct Priv1; + | ^^^^^^^^^^^^ -error[E0446]: private type `Priv2` in public interface - --> $DIR/private-in-public.rs:132:5 +warning: type `Priv2` is more private than the item `aliases_priv::f2` + --> $DIR/private-in-public.rs:135:5 | -LL | struct Priv2; - | ------------ `Priv2` declared as private -... LL | pub fn f2(arg: PrivAlias) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^^^^^^^^^^^^^^^ function `aliases_priv::f2` is reachable at visibility `pub(crate)` + | +note: but type `Priv2` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:120:5 + | +LL | struct Priv2; + | ^^^^^^^^^^^^ -error[E0445]: private trait `aliases_priv::PrivTr` in public interface - --> $DIR/private-in-public.rs:133:5 +warning: associated type `aliases_priv::PrivTr::Assoc` is more private than the item `aliases_priv::f3` + --> $DIR/private-in-public.rs:136:5 | -LL | trait PrivTr { - | ------------ `aliases_priv::PrivTr` declared as private -... LL | pub fn f3(arg: <Priv as PrivTr>::Assoc) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `aliases_priv::f3` is reachable at visibility `pub(crate)` + | +note: but associated type `aliases_priv::PrivTr::Assoc` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:130:9 + | +LL | type Assoc = Priv3; + | ^^^^^^^^^^ -error[E0446]: private type `aliases_priv::Priv` in public interface - --> $DIR/private-in-public.rs:133:5 +warning: trait `aliases_priv::PrivTr` is more private than the item `aliases_priv::f3` + --> $DIR/private-in-public.rs:136:5 | -LL | struct Priv; - | ----------- `aliases_priv::Priv` declared as private -... LL | pub fn f3(arg: <Priv as PrivTr>::Assoc) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `aliases_priv::f3` is reachable at visibility `pub(crate)` + | +note: but trait `aliases_priv::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:129:5 + | +LL | trait PrivTr { + | ^^^^^^^^^^^^ -error[E0446]: private type `aliases_params::Priv` in public interface - --> $DIR/private-in-public.rs:143:5 +warning: type `aliases_priv::Priv` is more private than the item `aliases_priv::f3` + --> $DIR/private-in-public.rs:136:5 + | +LL | pub fn f3(arg: <Priv as PrivTr>::Assoc) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `aliases_priv::f3` is reachable at visibility `pub(crate)` + | +note: but type `aliases_priv::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:117:5 | LL | struct Priv; - | ----------- `aliases_params::Priv` declared as private -... -LL | pub fn f2(arg: PrivAliasGeneric) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^ -error[E0446]: private type `aliases_params::Priv` in public interface - --> $DIR/private-in-public.rs:145:5 +warning: type `aliases_params::Priv` is more private than the item `aliases_params::f2` + --> $DIR/private-in-public.rs:147:5 + | +LL | pub fn f2(arg: PrivAliasGeneric) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `aliases_params::f2` is reachable at visibility `pub(crate)` + | +note: but type `aliases_params::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:143:5 | LL | struct Priv; - | ----------- `aliases_params::Priv` declared as private -... + | ^^^^^^^^^^^ + +warning: type `aliases_params::Priv` is more private than the item `aliases_params::f3` + --> $DIR/private-in-public.rs:149:5 + | LL | pub fn f3(arg: Result<u8>) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ function `aliases_params::f3` is reachable at visibility `pub(crate)` + | +note: but type `aliases_params::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:143:5 + | +LL | struct Priv; + | ^^^^^^^^^^^ -error: aborting due to 32 previous errors +warning: 33 warnings emitted -Some errors have detailed explanations: E0445, E0446. -For more information about an error, try `rustc --explain E0445`. diff --git a/tests/ui/privacy/private-inferred-type-1.rs b/tests/ui/privacy/private-inferred-type-1.rs index d633189e3..b3eba53dd 100644 --- a/tests/ui/privacy/private-inferred-type-1.rs +++ b/tests/ui/privacy/private-inferred-type-1.rs @@ -5,14 +5,24 @@ trait TyParam { fn ty_param_secret(&self); } +trait Ref { + fn ref_secret(self); +} + mod m { struct Priv; impl ::Arr0 for [Priv; 0] { fn arr0_secret(&self) {} } impl ::TyParam for Option<Priv> { fn ty_param_secret(&self) {} } + impl<'a> ::Ref for &'a Priv { fn ref_secret(self) {} } } +fn anyref<'a, T>() -> &'a T { panic!() } + fn main() { [].arr0_secret(); //~ ERROR type `Priv` is private None.ty_param_secret(); //~ ERROR type `Priv` is private + Ref::ref_secret(anyref()); + //~^ ERROR type `Priv` is private + //~| ERROR type `Priv` is private } diff --git a/tests/ui/privacy/private-inferred-type-1.stderr b/tests/ui/privacy/private-inferred-type-1.stderr index 245789f43..47c11d6ec 100644 --- a/tests/ui/privacy/private-inferred-type-1.stderr +++ b/tests/ui/privacy/private-inferred-type-1.stderr @@ -1,14 +1,26 @@ error: type `Priv` is private - --> $DIR/private-inferred-type-1.rs:16:5 + --> $DIR/private-inferred-type-1.rs:23:5 | LL | [].arr0_secret(); | ^^^^^^^^^^^^^^^^ private type error: type `Priv` is private - --> $DIR/private-inferred-type-1.rs:17:5 + --> $DIR/private-inferred-type-1.rs:24:5 | LL | None.ty_param_secret(); | ^^^^^^^^^^^^^^^^^^^^^^ private type -error: aborting due to 2 previous errors +error: type `Priv` is private + --> $DIR/private-inferred-type-1.rs:25:5 + | +LL | Ref::ref_secret(anyref()); + | ^^^^^^^^^^^^^^^ private type + +error: type `Priv` is private + --> $DIR/private-inferred-type-1.rs:25:21 + | +LL | Ref::ref_secret(anyref()); + | ^^^^^^^^ private type + +error: aborting due to 4 previous errors diff --git a/tests/ui/privacy/private-inferred-type-2.rs b/tests/ui/privacy/private-inferred-type-2.rs index 15b263b38..1c4c52bea 100644 --- a/tests/ui/privacy/private-inferred-type-2.rs +++ b/tests/ui/privacy/private-inferred-type-2.rs @@ -1,4 +1,5 @@ // aux-build:private-inferred-type.rs +#![allow(private_interfaces)] extern crate private_inferred_type as ext; diff --git a/tests/ui/privacy/private-inferred-type-2.stderr b/tests/ui/privacy/private-inferred-type-2.stderr index 3a0fc03b4..8a905f5d8 100644 --- a/tests/ui/privacy/private-inferred-type-2.stderr +++ b/tests/ui/privacy/private-inferred-type-2.stderr @@ -1,17 +1,17 @@ error: type `Priv` is private - --> $DIR/private-inferred-type-2.rs:16:5 + --> $DIR/private-inferred-type-2.rs:17:5 | LL | m::Pub::get_priv; | ^^^^^^^^^^^^^^^^ private type error: type `Priv` is private - --> $DIR/private-inferred-type-2.rs:17:5 + --> $DIR/private-inferred-type-2.rs:18:5 | LL | m::Pub::static_method; | ^^^^^^^^^^^^^^^^^^^^^ private type error: type `ext::Priv` is private - --> $DIR/private-inferred-type-2.rs:18:5 + --> $DIR/private-inferred-type-2.rs:19:5 | LL | ext::Pub::static_method; | ^^^^^^^^^^^^^^^^^^^^^^^ private type diff --git a/tests/ui/privacy/private-inferred-type.rs b/tests/ui/privacy/private-inferred-type.rs index e8743dd96..8c07226fe 100644 --- a/tests/ui/privacy/private-inferred-type.rs +++ b/tests/ui/privacy/private-inferred-type.rs @@ -1,5 +1,5 @@ #![feature(decl_macro)] -#![allow(private_in_public)] +#![allow(private_interfaces)] mod m { fn priv_fn() {} diff --git a/tests/ui/privacy/private-item-simple.stderr b/tests/ui/privacy/private-item-simple.stderr index e3d90150e..330d892e9 100644 --- a/tests/ui/privacy/private-item-simple.stderr +++ b/tests/ui/privacy/private-item-simple.stderr @@ -10,6 +10,6 @@ note: the function `f` is defined here LL | fn f() {} | ^^^^^^ -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0603`. diff --git a/tests/ui/privacy/private-method-cross-crate.stderr b/tests/ui/privacy/private-method-cross-crate.stderr index e644440c8..9c524e2bd 100644 --- a/tests/ui/privacy/private-method-cross-crate.stderr +++ b/tests/ui/privacy/private-method-cross-crate.stderr @@ -9,6 +9,6 @@ LL | nyan.nap(); LL | fn nap(&self) {} | ------------- private method defined here -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0624`. diff --git a/tests/ui/privacy/private-method-inherited.stderr b/tests/ui/privacy/private-method-inherited.stderr index 0104a1b27..dd36afe8b 100644 --- a/tests/ui/privacy/private-method-inherited.stderr +++ b/tests/ui/privacy/private-method-inherited.stderr @@ -7,6 +7,6 @@ LL | fn f(self) {} LL | x.f(); | ^ private method -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0624`. diff --git a/tests/ui/privacy/private-method.stderr b/tests/ui/privacy/private-method.stderr index 42fec7622..076a149e1 100644 --- a/tests/ui/privacy/private-method.stderr +++ b/tests/ui/privacy/private-method.stderr @@ -7,6 +7,6 @@ LL | fn nap(&self) {} LL | nyan.nap(); | ^^^ private method -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0624`. diff --git a/tests/ui/privacy/private-struct-field-cross-crate.stderr b/tests/ui/privacy/private-struct-field-cross-crate.stderr index 40cf3448d..ed4c83f15 100644 --- a/tests/ui/privacy/private-struct-field-cross-crate.stderr +++ b/tests/ui/privacy/private-struct-field-cross-crate.stderr @@ -4,6 +4,6 @@ error[E0616]: field `meows` of struct `cat` is private LL | assert_eq!(nyan.meows, 52); | ^^^^^ private field -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0616`. diff --git a/tests/ui/privacy/private-struct-field-ctor.stderr b/tests/ui/privacy/private-struct-field-ctor.stderr index 9dc9db0ea..2a3553723 100644 --- a/tests/ui/privacy/private-struct-field-ctor.stderr +++ b/tests/ui/privacy/private-struct-field-ctor.stderr @@ -4,6 +4,6 @@ error[E0451]: field `x` of struct `Foo` is private LL | let s = a::Foo { x: 1 }; | ^^^^ private field -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0451`. diff --git a/tests/ui/privacy/private-struct-field-pattern.stderr b/tests/ui/privacy/private-struct-field-pattern.stderr index 630553036..de24d1e09 100644 --- a/tests/ui/privacy/private-struct-field-pattern.stderr +++ b/tests/ui/privacy/private-struct-field-pattern.stderr @@ -4,6 +4,6 @@ error[E0451]: field `x` of struct `Foo` is private LL | Foo { x: _ } => {} | ^^^^ private field -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0451`. diff --git a/tests/ui/privacy/private-struct-field.stderr b/tests/ui/privacy/private-struct-field.stderr index facf4e82f..cc5a966bc 100644 --- a/tests/ui/privacy/private-struct-field.stderr +++ b/tests/ui/privacy/private-struct-field.stderr @@ -4,6 +4,6 @@ error[E0616]: field `meows` of struct `Cat` is private LL | assert_eq!(nyan.meows, 52); | ^^^^^ private field -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0616`. diff --git a/tests/ui/privacy/private-type-in-interface.rs b/tests/ui/privacy/private-type-in-interface.rs index 7fbdbaf5f..39e0bf23c 100644 --- a/tests/ui/privacy/private-type-in-interface.rs +++ b/tests/ui/privacy/private-type-in-interface.rs @@ -1,6 +1,7 @@ // aux-build:private-inferred-type.rs #![allow(warnings)] +#![allow(private_interfaces)] extern crate private_inferred_type as ext; diff --git a/tests/ui/privacy/private-type-in-interface.stderr b/tests/ui/privacy/private-type-in-interface.stderr index 4e87caa34..03225d84f 100644 --- a/tests/ui/privacy/private-type-in-interface.stderr +++ b/tests/ui/privacy/private-type-in-interface.stderr @@ -1,53 +1,53 @@ error: type `Priv` is private - --> $DIR/private-type-in-interface.rs:15:9 + --> $DIR/private-type-in-interface.rs:16:9 | LL | fn f(_: m::Alias) {} | ^^^^^^^^ private type error: type `Priv` is private - --> $DIR/private-type-in-interface.rs:15:6 + --> $DIR/private-type-in-interface.rs:16:6 | LL | fn f(_: m::Alias) {} | ^ private type error: type `ext::Priv` is private - --> $DIR/private-type-in-interface.rs:17:13 + --> $DIR/private-type-in-interface.rs:18:13 | LL | fn f_ext(_: ext::Alias) {} | ^^^^^^^^^^ private type error: type `ext::Priv` is private - --> $DIR/private-type-in-interface.rs:17:10 + --> $DIR/private-type-in-interface.rs:18:10 | LL | fn f_ext(_: ext::Alias) {} | ^ private type error: type `Priv` is private - --> $DIR/private-type-in-interface.rs:21:6 + --> $DIR/private-type-in-interface.rs:22:6 | LL | impl m::Alias {} | ^^^^^^^^ private type error: type `ext::Priv` is private - --> $DIR/private-type-in-interface.rs:22:14 + --> $DIR/private-type-in-interface.rs:23:14 | LL | impl Tr1 for ext::Alias {} | ^^^^^^^^^^ private type error: type `Priv` is private - --> $DIR/private-type-in-interface.rs:23:10 + --> $DIR/private-type-in-interface.rs:24:10 | LL | type A = <m::Alias as m::Trait>::X; | ^^^^^^^^^^^^^^^^^^^^^^^^^ private type error: type `Priv` is private - --> $DIR/private-type-in-interface.rs:27:11 + --> $DIR/private-type-in-interface.rs:28:11 | LL | fn g() -> impl Tr2<m::Alias> { 0 } | ^^^^^^^^^^^^^^^^^^ private type error: type `ext::Priv` is private - --> $DIR/private-type-in-interface.rs:28:15 + --> $DIR/private-type-in-interface.rs:29:15 | LL | fn g_ext() -> impl Tr2<ext::Alias> { 0 } | ^^^^^^^^^^^^^^^^^^^^ private type diff --git a/tests/ui/privacy/private-variant-reexport.rs b/tests/ui/privacy/private-variant-reexport.rs index 688284460..b59243af6 100644 --- a/tests/ui/privacy/private-variant-reexport.rs +++ b/tests/ui/privacy/private-variant-reexport.rs @@ -12,7 +12,9 @@ mod m3 { #[deny(unused_imports)] mod m4 { - pub use ::E::*; //~ ERROR glob import doesn't reexport anything + pub use ::E::*; + //~^ ERROR glob import doesn't reexport anything + //~| ERROR unused import: `::E::*` } enum E { V } diff --git a/tests/ui/privacy/private-variant-reexport.stderr b/tests/ui/privacy/private-variant-reexport.stderr index 78771ee30..d73bd1a8c 100644 --- a/tests/ui/privacy/private-variant-reexport.stderr +++ b/tests/ui/privacy/private-variant-reexport.stderr @@ -30,19 +30,31 @@ LL | pub use ::E::V::{self}; | = note: consider declaring type or module `V` with `pub` -error: glob import doesn't reexport anything because no candidate is public enough +error: glob import doesn't reexport anything with visibility `pub` because no imported item is public enough --> $DIR/private-variant-reexport.rs:15:13 | LL | pub use ::E::*; | ^^^^^^ | +note: the most public imported item is `pub(crate)` + --> $DIR/private-variant-reexport.rs:15:13 + | +LL | pub use ::E::*; + | ^^^^^^ + = help: reduce the glob import's visibility or increase visibility of imported items note: the lint level is defined here --> $DIR/private-variant-reexport.rs:13:8 | LL | #[deny(unused_imports)] | ^^^^^^^^^^^^^^ -error: aborting due to 4 previous errors +error: unused import: `::E::*` + --> $DIR/private-variant-reexport.rs:15:13 + | +LL | pub use ::E::*; + | ^^^^^^ + +error: aborting due to 5 previous errors Some errors have detailed explanations: E0364, E0365. For more information about an error, try `rustc --explain E0364`. diff --git a/tests/ui/privacy/restricted/private-in-public.rs b/tests/ui/privacy/restricted/private-in-public.rs index 1e3dbdf73..80a7e6ad0 100644 --- a/tests/ui/privacy/restricted/private-in-public.rs +++ b/tests/ui/privacy/restricted/private-in-public.rs @@ -1,10 +1,11 @@ +// check-pass mod foo { struct Priv; mod bar { use foo::Priv; pub(super) fn f(_: Priv) {} - pub(crate) fn g(_: Priv) {} //~ ERROR E0446 - pub(crate) fn h(_: Priv) {} //~ ERROR E0446 + pub(crate) fn g(_: Priv) {} + pub(crate) fn h(_: Priv) {} } } diff --git a/tests/ui/privacy/restricted/private-in-public.stderr b/tests/ui/privacy/restricted/private-in-public.stderr deleted file mode 100644 index 65d996f0f..000000000 --- a/tests/ui/privacy/restricted/private-in-public.stderr +++ /dev/null @@ -1,21 +0,0 @@ -error[E0446]: private type `Priv` in public interface - --> $DIR/private-in-public.rs:6:9 - | -LL | struct Priv; - | ----------- `Priv` declared as private -... -LL | pub(crate) fn g(_: Priv) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type - -error[E0446]: private type `Priv` in public interface - --> $DIR/private-in-public.rs:7:9 - | -LL | struct Priv; - | ----------- `Priv` declared as private -... -LL | pub(crate) fn h(_: Priv) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0446`. diff --git a/tests/ui/privacy/restricted/struct-literal-field.stderr b/tests/ui/privacy/restricted/struct-literal-field.stderr index eee964f02..dcdadf1da 100644 --- a/tests/ui/privacy/restricted/struct-literal-field.stderr +++ b/tests/ui/privacy/restricted/struct-literal-field.stderr @@ -4,6 +4,6 @@ error[E0451]: field `x` of struct `S` is private LL | S { x: 0 }; | ^^^^ private field -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0451`. diff --git a/tests/ui/privacy/sealed-traits/private-trait-non-local.rs b/tests/ui/privacy/sealed-traits/private-trait-non-local.rs new file mode 100644 index 000000000..426f21cc7 --- /dev/null +++ b/tests/ui/privacy/sealed-traits/private-trait-non-local.rs @@ -0,0 +1,4 @@ +extern crate core; +use core::slice::index::private_slice_index::Sealed; //~ ERROR module `index` is private +fn main() { +} diff --git a/tests/ui/privacy/sealed-traits/private-trait-non-local.stderr b/tests/ui/privacy/sealed-traits/private-trait-non-local.stderr new file mode 100644 index 000000000..e6b76322f --- /dev/null +++ b/tests/ui/privacy/sealed-traits/private-trait-non-local.stderr @@ -0,0 +1,12 @@ +error[E0603]: module `index` is private + --> $DIR/private-trait-non-local.rs:2:18 + | +LL | use core::slice::index::private_slice_index::Sealed; + | ^^^^^ private module ------ trait `Sealed` is not publicly re-exported + | +note: the module `index` is defined here + --> $SRC_DIR/core/src/slice/mod.rs:LL:COL + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0603`. diff --git a/tests/ui/privacy/sealed-traits/private-trait.rs b/tests/ui/privacy/sealed-traits/private-trait.rs new file mode 100644 index 000000000..bbcbaabfa --- /dev/null +++ b/tests/ui/privacy/sealed-traits/private-trait.rs @@ -0,0 +1,10 @@ +pub mod a { + mod b { + pub trait Hidden {} + } +} + +struct S; +impl a::b::Hidden for S {} //~ ERROR module `b` is private + +fn main() {} diff --git a/tests/ui/privacy/sealed-traits/private-trait.stderr b/tests/ui/privacy/sealed-traits/private-trait.stderr new file mode 100644 index 000000000..e8d88906f --- /dev/null +++ b/tests/ui/privacy/sealed-traits/private-trait.stderr @@ -0,0 +1,17 @@ +error[E0603]: module `b` is private + --> $DIR/private-trait.rs:8:9 + | +LL | impl a::b::Hidden for S {} + | ^ ------ trait `Hidden` is not publicly re-exported + | | + | private module + | +note: the module `b` is defined here + --> $DIR/private-trait.rs:2:5 + | +LL | mod b { + | ^^^^^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0603`. diff --git a/tests/ui/privacy/sealed-traits/re-exported-trait.fixed b/tests/ui/privacy/sealed-traits/re-exported-trait.fixed new file mode 100644 index 000000000..79b6a6516 --- /dev/null +++ b/tests/ui/privacy/sealed-traits/re-exported-trait.fixed @@ -0,0 +1,13 @@ +// run-rustfix + +pub mod a { + pub use self::b::Trait; + mod b { + pub trait Trait {} + } +} + +struct S; +impl a::Trait for S {} //~ ERROR module `b` is private + +fn main() {} diff --git a/tests/ui/privacy/sealed-traits/re-exported-trait.rs b/tests/ui/privacy/sealed-traits/re-exported-trait.rs new file mode 100644 index 000000000..5f96dfdcb --- /dev/null +++ b/tests/ui/privacy/sealed-traits/re-exported-trait.rs @@ -0,0 +1,13 @@ +// run-rustfix + +pub mod a { + pub use self::b::Trait; + mod b { + pub trait Trait {} + } +} + +struct S; +impl a::b::Trait for S {} //~ ERROR module `b` is private + +fn main() {} diff --git a/tests/ui/privacy/sealed-traits/re-exported-trait.stderr b/tests/ui/privacy/sealed-traits/re-exported-trait.stderr new file mode 100644 index 000000000..9f2291e68 --- /dev/null +++ b/tests/ui/privacy/sealed-traits/re-exported-trait.stderr @@ -0,0 +1,19 @@ +error[E0603]: module `b` is private + --> $DIR/re-exported-trait.rs:11:9 + | +LL | impl a::b::Trait for S {} + | ^ private module + | +note: the module `b` is defined here + --> $DIR/re-exported-trait.rs:5:5 + | +LL | mod b { + | ^^^^^ +help: consider importing this trait through its public re-export instead + | +LL | impl a::Trait for S {} + | ~~~~~~~~ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0603`. diff --git a/tests/ui/privacy/sealed-traits/sealed-trait-local.rs b/tests/ui/privacy/sealed-traits/sealed-trait-local.rs new file mode 100644 index 000000000..9ae01259a --- /dev/null +++ b/tests/ui/privacy/sealed-traits/sealed-trait-local.rs @@ -0,0 +1,55 @@ +// provide custom privacy error for sealed traits +pub mod a { + pub trait Sealed: self::b::Hidden { + fn foo() {} + } + + struct X; + impl Sealed for X {} + impl self::b::Hidden for X {} + + mod b { + pub trait Hidden {} + } +} + +pub mod c { + pub trait Sealed: self::d::Hidden { + fn foo() {} + } + + struct X; + impl Sealed for X {} + impl self::d::Hidden for X {} + + struct Y; + impl Sealed for Y {} + impl self::d::Hidden for Y {} + + mod d { + pub trait Hidden {} + } +} + +pub mod e { + pub trait Sealed: self::f::Hidden { + fn foo() {} + } + + struct X; + impl self::f::Hidden for X {} + + struct Y; + impl self::f::Hidden for Y {} + impl<T: self::f::Hidden> Sealed for T {} + + mod f { + pub trait Hidden {} + } +} + +struct S; +impl a::Sealed for S {} //~ ERROR the trait bound +impl c::Sealed for S {} //~ ERROR the trait bound +impl e::Sealed for S {} //~ ERROR the trait bound +fn main() {} diff --git a/tests/ui/privacy/sealed-traits/sealed-trait-local.stderr b/tests/ui/privacy/sealed-traits/sealed-trait-local.stderr new file mode 100644 index 000000000..a7f77a1c0 --- /dev/null +++ b/tests/ui/privacy/sealed-traits/sealed-trait-local.stderr @@ -0,0 +1,50 @@ +error[E0277]: the trait bound `S: b::Hidden` is not satisfied + --> $DIR/sealed-trait-local.rs:52:20 + | +LL | impl a::Sealed for S {} + | ^ the trait `b::Hidden` is not implemented for `S` + | +note: required by a bound in `a::Sealed` + --> $DIR/sealed-trait-local.rs:3:23 + | +LL | pub trait Sealed: self::b::Hidden { + | ^^^^^^^^^^^^^^^ required by this bound in `Sealed` + = note: `Sealed` is a "sealed trait", because to implement it you also need to implement `a::b::Hidden`, which is not accessible; this is usually done to force you to use one of the provided types that already implement it + = help: the following type implements the trait: + a::X + +error[E0277]: the trait bound `S: d::Hidden` is not satisfied + --> $DIR/sealed-trait-local.rs:53:20 + | +LL | impl c::Sealed for S {} + | ^ the trait `d::Hidden` is not implemented for `S` + | +note: required by a bound in `c::Sealed` + --> $DIR/sealed-trait-local.rs:17:23 + | +LL | pub trait Sealed: self::d::Hidden { + | ^^^^^^^^^^^^^^^ required by this bound in `Sealed` + = note: `Sealed` is a "sealed trait", because to implement it you also need to implement `c::d::Hidden`, which is not accessible; this is usually done to force you to use one of the provided types that already implement it + = help: the following types implement the trait: + c::X + c::Y + +error[E0277]: the trait bound `S: f::Hidden` is not satisfied + --> $DIR/sealed-trait-local.rs:54:20 + | +LL | impl e::Sealed for S {} + | ^ the trait `f::Hidden` is not implemented for `S` + | +note: required by a bound in `e::Sealed` + --> $DIR/sealed-trait-local.rs:35:23 + | +LL | pub trait Sealed: self::f::Hidden { + | ^^^^^^^^^^^^^^^ required by this bound in `Sealed` + = note: `Sealed` is a "sealed trait", because to implement it you also need to implement `e::f::Hidden`, which is not accessible; this is usually done to force you to use one of the provided types that already implement it + = help: the following types implement the trait: + e::X + e::Y + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/privacy/suggest-box-new.rs b/tests/ui/privacy/suggest-box-new.rs new file mode 100644 index 000000000..7125285fc --- /dev/null +++ b/tests/ui/privacy/suggest-box-new.rs @@ -0,0 +1,19 @@ +#![allow(dead_code)] +struct U <T> { + wtf: Option<Box<U<T>>>, + x: T, +} +fn main() { + U { + wtf: Some(Box(U { //~ ERROR cannot initialize a tuple struct which contains private fields + wtf: None, + x: (), + })), + x: () + }; + let _ = std::collections::HashMap(); + //~^ ERROR expected function, tuple struct or tuple variant, found struct `std::collections::HashMap` + let _ = std::collections::HashMap {}; + //~^ ERROR cannot construct `HashMap<_, _, _>` with struct literal syntax due to private fields + let _ = Box {}; //~ ERROR cannot construct `Box<_, _>` with struct literal syntax due to private fields +} diff --git a/tests/ui/privacy/suggest-box-new.stderr b/tests/ui/privacy/suggest-box-new.stderr new file mode 100644 index 000000000..8b01e8c3c --- /dev/null +++ b/tests/ui/privacy/suggest-box-new.stderr @@ -0,0 +1,100 @@ +error[E0423]: expected function, tuple struct or tuple variant, found struct `std::collections::HashMap` + --> $DIR/suggest-box-new.rs:14:13 + | +LL | let _ = std::collections::HashMap(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + --> $SRC_DIR/std/src/collections/hash/map.rs:LL:COL + | + = note: `std::collections::HashMap` defined here + | +help: you might have meant to use an associated function to build this type + | +LL | let _ = std::collections::HashMap::new(); + | ~~~~~~~ +LL | let _ = std::collections::HashMap::with_capacity(_); + | ~~~~~~~~~~~~~~~~~~ +LL | let _ = std::collections::HashMap::with_hasher(_); + | ~~~~~~~~~~~~~~~~ +LL | let _ = std::collections::HashMap::with_capacity_and_hasher(_, _); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +help: consider using the `Default` trait + | +LL | let _ = <std::collections::HashMap as std::default::Default>::default(); + | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error[E0423]: cannot initialize a tuple struct which contains private fields + --> $DIR/suggest-box-new.rs:8:19 + | +LL | wtf: Some(Box(U { + | ^^^ + | +note: constructor is not visible here due to private fields + --> $SRC_DIR/alloc/src/boxed.rs:LL:COL + | + = note: private field + | + = note: private field +help: you might have meant to use an associated function to build this type + | +LL | wtf: Some(Box::new(_)), + | ~~~~~~~~ +LL | wtf: Some(Box::new_uninit()), + | ~~~~~~~~~~~~~~ +LL | wtf: Some(Box::new_zeroed()), + | ~~~~~~~~~~~~~~ +LL | wtf: Some(Box::new_in(_, _)), + | ~~~~~~~~~~~~~~ + and 10 other candidates +help: consider using the `Default` trait + | +LL | wtf: Some(<Box as std::default::Default>::default()), + | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: cannot construct `HashMap<_, _, _>` with struct literal syntax due to private fields + --> $DIR/suggest-box-new.rs:16:13 + | +LL | let _ = std::collections::HashMap {}; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: private field `base` that was not provided +help: you might have meant to use an associated function to build this type + | +LL | let _ = std::collections::HashMap::new(); + | ~~~~~~~ +LL | let _ = std::collections::HashMap::with_capacity(_); + | ~~~~~~~~~~~~~~~~~~ +LL | let _ = std::collections::HashMap::with_hasher(_); + | ~~~~~~~~~~~~~~~~ +LL | let _ = std::collections::HashMap::with_capacity_and_hasher(_, _); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +help: consider using the `Default` trait + | +LL | let _ = <std::collections::HashMap as std::default::Default>::default(); + | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: cannot construct `Box<_, _>` with struct literal syntax due to private fields + --> $DIR/suggest-box-new.rs:18:13 + | +LL | let _ = Box {}; + | ^^^ + | + = note: private fields `0` and `1` that were not provided +help: you might have meant to use an associated function to build this type + | +LL | let _ = Box::new(_); + | ~~~~~~~~ +LL | let _ = Box::new_uninit(); + | ~~~~~~~~~~~~~~ +LL | let _ = Box::new_zeroed(); + | ~~~~~~~~~~~~~~ +LL | let _ = Box::new_in(_, _); + | ~~~~~~~~~~~~~~ + and 10 other candidates +help: consider using the `Default` trait + | +LL | let _ = <Box as std::default::Default>::default(); + | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0423`. diff --git a/tests/ui/privacy/union-field-privacy-2.stderr b/tests/ui/privacy/union-field-privacy-2.stderr index bf6a2b625..7b6b84bfd 100644 --- a/tests/ui/privacy/union-field-privacy-2.stderr +++ b/tests/ui/privacy/union-field-privacy-2.stderr @@ -4,6 +4,6 @@ error[E0616]: field `c` of union `U` is private LL | let c = u.c; | ^ private field -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0616`. diff --git a/tests/ui/privacy/unnameable_types.rs b/tests/ui/privacy/unnameable_types.rs new file mode 100644 index 000000000..c6c5561c3 --- /dev/null +++ b/tests/ui/privacy/unnameable_types.rs @@ -0,0 +1,29 @@ +#![feature(type_privacy_lints)] +#![deny(unnameable_types)] + +mod m { + pub struct PubStruct(pub i32); //~ ERROR struct `PubStruct` is reachable but cannot be named + + pub enum PubE { //~ ERROR enum `PubE` is reachable but cannot be named + V(i32), + } + + pub trait PubTr { //~ ERROR trait `PubTr` is reachable but cannot be named + const C : i32 = 0; + type Alias; + fn f() {} + } + + impl PubTr for PubStruct { + type Alias = i32; + fn f() {} + } +} + +pub trait Unnameable<T> {} + +impl Unnameable<m::PubStruct> for i32 {} +impl Unnameable<m::PubE> for i32 {} +impl<T> Unnameable<T> for u32 where T: m::PubTr {} + +fn main() {} diff --git a/tests/ui/privacy/unnameable_types.stderr b/tests/ui/privacy/unnameable_types.stderr new file mode 100644 index 000000000..d68a11c97 --- /dev/null +++ b/tests/ui/privacy/unnameable_types.stderr @@ -0,0 +1,26 @@ +error: struct `PubStruct` is reachable but cannot be named + --> $DIR/unnameable_types.rs:5:5 + | +LL | pub struct PubStruct(pub i32); + | ^^^^^^^^^^^^^^^^^^^^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)` + | +note: the lint level is defined here + --> $DIR/unnameable_types.rs:2:9 + | +LL | #![deny(unnameable_types)] + | ^^^^^^^^^^^^^^^^ + +error: enum `PubE` is reachable but cannot be named + --> $DIR/unnameable_types.rs:7:5 + | +LL | pub enum PubE { + | ^^^^^^^^^^^^^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)` + +error: trait `PubTr` is reachable but cannot be named + --> $DIR/unnameable_types.rs:11:5 + | +LL | pub trait PubTr { + | ^^^^^^^^^^^^^^^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)` + +error: aborting due to 3 previous errors + diff --git a/tests/ui/privacy/unresolved-trait-impl-item.rs b/tests/ui/privacy/unresolved-trait-impl-item.rs new file mode 100644 index 000000000..fea7c462a --- /dev/null +++ b/tests/ui/privacy/unresolved-trait-impl-item.rs @@ -0,0 +1,15 @@ +// edition:2018 + +trait MyTrait { + async fn resolved(&self); + const RESOLVED_WRONG: u8 = 0; +} + +impl MyTrait for i32 { + async fn resolved(&self) {} + + async fn unresolved(&self) {} //~ ERROR method `unresolved` is not a member of trait `MyTrait` + async fn RESOLVED_WRONG() {} //~ ERROR doesn't match its trait `MyTrait` +} + +fn main() {} diff --git a/tests/ui/privacy/unresolved-trait-impl-item.stderr b/tests/ui/privacy/unresolved-trait-impl-item.stderr new file mode 100644 index 000000000..588e47c26 --- /dev/null +++ b/tests/ui/privacy/unresolved-trait-impl-item.stderr @@ -0,0 +1,22 @@ +error[E0407]: method `unresolved` is not a member of trait `MyTrait` + --> $DIR/unresolved-trait-impl-item.rs:11:5 + | +LL | async fn unresolved(&self) {} + | ^^^^^^^^^----------^^^^^^^^^^ + | | | + | | help: there is an associated function with a similar name: `resolved` + | not a member of trait `MyTrait` + +error[E0324]: item `RESOLVED_WRONG` is an associated method, which doesn't match its trait `MyTrait` + --> $DIR/unresolved-trait-impl-item.rs:12:5 + | +LL | const RESOLVED_WRONG: u8 = 0; + | ----------------------------- item in trait +... +LL | async fn RESOLVED_WRONG() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ does not match trait + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0324, E0407. +For more information about an error, try `rustc --explain E0324`. diff --git a/tests/ui/privacy/where-priv-type.rs b/tests/ui/privacy/where-priv-type.rs index 66ee9c4bb..cd9cce7ec 100644 --- a/tests/ui/privacy/where-priv-type.rs +++ b/tests/ui/privacy/where-priv-type.rs @@ -5,7 +5,6 @@ #![feature(generic_const_exprs)] #![allow(incomplete_features)] - struct PrivTy; trait PrivTr {} pub struct PubTy; @@ -17,37 +16,33 @@ impl PubTrWithAssocTy for PrivTy { type AssocTy = PrivTy; } pub struct S -//~^ WARNING private type `PrivTy` in public interface -//~| WARNING hard error +//~^ WARNING type `PrivTy` is more private than the item `S` where PrivTy: {} pub enum E -//~^ WARNING private type `PrivTy` in public interface -//~| WARNING hard error +//~^ WARNING type `PrivTy` is more private than the item `E` where PrivTy: {} pub fn f() -//~^ WARNING private type `PrivTy` in public interface -//~| WARNING hard error +//~^ WARNING type `PrivTy` is more private than the item `f` where PrivTy: {} impl S -//~^ ERROR private type `PrivTy` in public interface +//~^ WARNING type `PrivTy` is more private than the item `S` where PrivTy: { pub fn f() - //~^ WARNING private type `PrivTy` in public interface - //~| WARNING hard error + //~^ WARNING type `PrivTy` is more private than the item `S::f` where PrivTy: {} diff --git a/tests/ui/privacy/where-priv-type.stderr b/tests/ui/privacy/where-priv-type.stderr index c5fb2cdb0..126330b14 100644 --- a/tests/ui/privacy/where-priv-type.stderr +++ b/tests/ui/privacy/where-priv-type.stderr @@ -1,59 +1,75 @@ -warning: private type `PrivTy` in public interface (error E0446) - --> $DIR/where-priv-type.rs:19:1 +warning: type `PrivTy` is more private than the item `S` + --> $DIR/where-priv-type.rs:18:1 | LL | pub struct S - | ^^^^^^^^^^^^ + | ^^^^^^^^^^^^ struct `S` is reachable at visibility `pub` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> - = note: `#[warn(private_in_public)]` on by default +note: but type `PrivTy` is only usable at visibility `pub(crate)` + --> $DIR/where-priv-type.rs:8:1 + | +LL | struct PrivTy; + | ^^^^^^^^^^^^^ + = note: `#[warn(private_bounds)]` on by default -warning: private type `PrivTy` in public interface (error E0446) - --> $DIR/where-priv-type.rs:27:1 +warning: type `PrivTy` is more private than the item `E` + --> $DIR/where-priv-type.rs:25:1 | LL | pub enum E - | ^^^^^^^^^^ + | ^^^^^^^^^^ enum `E` is reachable at visibility `pub` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +note: but type `PrivTy` is only usable at visibility `pub(crate)` + --> $DIR/where-priv-type.rs:8:1 + | +LL | struct PrivTy; + | ^^^^^^^^^^^^^ -warning: private type `PrivTy` in public interface (error E0446) - --> $DIR/where-priv-type.rs:35:1 +warning: type `PrivTy` is more private than the item `f` + --> $DIR/where-priv-type.rs:32:1 | LL | / pub fn f() LL | | -LL | | LL | | where LL | | PrivTy: - | |___________^ + | |___________^ function `f` is reachable at visibility `pub` + | +note: but type `PrivTy` is only usable at visibility `pub(crate)` + --> $DIR/where-priv-type.rs:8:1 | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +LL | struct PrivTy; + | ^^^^^^^^^^^^^ -error[E0446]: private type `PrivTy` in public interface - --> $DIR/where-priv-type.rs:43:1 +warning: type `PrivTy` is more private than the item `S` + --> $DIR/where-priv-type.rs:39:1 + | +LL | / impl S +LL | | +LL | | where +LL | | PrivTy: + | |___________^ implementation `S` is reachable at visibility `pub` + | +note: but type `PrivTy` is only usable at visibility `pub(crate)` + --> $DIR/where-priv-type.rs:8:1 | LL | struct PrivTy; - | ------------- `PrivTy` declared as private -... -LL | impl S - | ^^^^^^ can't leak private type + | ^^^^^^^^^^^^^ -warning: private type `PrivTy` in public interface (error E0446) - --> $DIR/where-priv-type.rs:48:5 +warning: type `PrivTy` is more private than the item `S::f` + --> $DIR/where-priv-type.rs:44:5 | LL | / pub fn f() LL | | -LL | | LL | | where LL | | PrivTy: - | |_______________^ + | |_______________^ associated function `S::f` is reachable at visibility `pub` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +note: but type `PrivTy` is only usable at visibility `pub(crate)` + --> $DIR/where-priv-type.rs:8:1 + | +LL | struct PrivTy; + | ^^^^^^^^^^^^^ error[E0446]: private type `fn(u8) -> u8 {my_const_fn}` in public interface - --> $DIR/where-priv-type.rs:80:5 + --> $DIR/where-priv-type.rs:75:5 | LL | type AssocTy = Const<{ my_const_fn(U) }>; | ^^^^^^^^^^^^ can't leak private type @@ -61,6 +77,6 @@ LL | type AssocTy = Const<{ my_const_fn(U) }>; LL | const fn my_const_fn(val: u8) -> u8 { | ----------------------------------- `fn(u8) -> u8 {my_const_fn}` declared as private -error: aborting due to 2 previous errors; 4 warnings emitted +error: aborting due to 1 previous error; 5 warnings emitted For more information about this error, try `rustc --explain E0446`. diff --git a/tests/ui/privacy/where-pub-type-impls-priv-trait.rs b/tests/ui/privacy/where-pub-type-impls-priv-trait.rs index 87c211df1..d5e797b52 100644 --- a/tests/ui/privacy/where-pub-type-impls-priv-trait.rs +++ b/tests/ui/privacy/where-pub-type-impls-priv-trait.rs @@ -1,10 +1,11 @@ +// check-pass + // priv-in-pub lint tests where the private trait bounds a public type #![crate_type = "lib"] #![feature(generic_const_exprs)] #![allow(incomplete_features)] - struct PrivTy; trait PrivTr {} pub struct PubTy; @@ -17,33 +18,33 @@ impl PubTrWithAssocTy for PrivTy { type AssocTy = PrivTy; } pub struct S -//~^ ERROR private trait `PrivTr` in public interface +//~^ WARNING trait `PrivTr` is more private than the item `S` where PubTy: PrivTr {} pub enum E -//~^ ERROR private trait `PrivTr` in public interface +//~^ WARNING trait `PrivTr` is more private than the item `E` where PubTy: PrivTr {} pub fn f() -//~^ ERROR private trait `PrivTr` in public interface +//~^ WARNING trait `PrivTr` is more private than the item `f` where PubTy: PrivTr {} impl S -//~^ ERROR private trait `PrivTr` in public interface +//~^ WARNING trait `PrivTr` is more private than the item `S` where PubTy: PrivTr { pub fn f() - //~^ ERROR private trait `PrivTr` in public interface + //~^ WARNING trait `PrivTr` is more private than the item `S::f` where PubTy: PrivTr {} diff --git a/tests/ui/privacy/where-pub-type-impls-priv-trait.stderr b/tests/ui/privacy/where-pub-type-impls-priv-trait.stderr index a433cebbb..ee79ce3f5 100644 --- a/tests/ui/privacy/where-pub-type-impls-priv-trait.stderr +++ b/tests/ui/privacy/where-pub-type-impls-priv-trait.stderr @@ -1,54 +1,72 @@ -error[E0445]: private trait `PrivTr` in public interface - --> $DIR/where-pub-type-impls-priv-trait.rs:19:1 +warning: trait `PrivTr` is more private than the item `S` + --> $DIR/where-pub-type-impls-priv-trait.rs:20:1 | -LL | trait PrivTr {} - | ------------ `PrivTr` declared as private -... LL | pub struct S - | ^^^^^^^^^^^^ can't leak private trait - -error[E0445]: private trait `PrivTr` in public interface - --> $DIR/where-pub-type-impls-priv-trait.rs:26:1 + | ^^^^^^^^^^^^ struct `S` is reachable at visibility `pub` + | +note: but trait `PrivTr` is only usable at visibility `pub(crate)` + --> $DIR/where-pub-type-impls-priv-trait.rs:10:1 | LL | trait PrivTr {} - | ------------ `PrivTr` declared as private -... + | ^^^^^^^^^^^^ + = note: `#[warn(private_bounds)]` on by default + +warning: trait `PrivTr` is more private than the item `E` + --> $DIR/where-pub-type-impls-priv-trait.rs:27:1 + | LL | pub enum E - | ^^^^^^^^^^ can't leak private trait + | ^^^^^^^^^^ enum `E` is reachable at visibility `pub` + | +note: but trait `PrivTr` is only usable at visibility `pub(crate)` + --> $DIR/where-pub-type-impls-priv-trait.rs:10:1 + | +LL | trait PrivTr {} + | ^^^^^^^^^^^^ -error[E0445]: private trait `PrivTr` in public interface - --> $DIR/where-pub-type-impls-priv-trait.rs:33:1 +warning: trait `PrivTr` is more private than the item `f` + --> $DIR/where-pub-type-impls-priv-trait.rs:34:1 | -LL | trait PrivTr {} - | ------------ `PrivTr` declared as private -... LL | / pub fn f() LL | | LL | | where LL | | PubTy: PrivTr - | |_________________^ can't leak private trait + | |_________________^ function `f` is reachable at visibility `pub` + | +note: but trait `PrivTr` is only usable at visibility `pub(crate)` + --> $DIR/where-pub-type-impls-priv-trait.rs:10:1 + | +LL | trait PrivTr {} + | ^^^^^^^^^^^^ -error[E0445]: private trait `PrivTr` in public interface - --> $DIR/where-pub-type-impls-priv-trait.rs:40:1 +warning: trait `PrivTr` is more private than the item `S` + --> $DIR/where-pub-type-impls-priv-trait.rs:41:1 + | +LL | / impl S +LL | | +LL | | where +LL | | PubTy: PrivTr + | |_________________^ implementation `S` is reachable at visibility `pub` + | +note: but trait `PrivTr` is only usable at visibility `pub(crate)` + --> $DIR/where-pub-type-impls-priv-trait.rs:10:1 | LL | trait PrivTr {} - | ------------ `PrivTr` declared as private -... -LL | impl S - | ^^^^^^ can't leak private trait + | ^^^^^^^^^^^^ -error[E0445]: private trait `PrivTr` in public interface - --> $DIR/where-pub-type-impls-priv-trait.rs:45:5 +warning: trait `PrivTr` is more private than the item `S::f` + --> $DIR/where-pub-type-impls-priv-trait.rs:46:5 | -LL | trait PrivTr {} - | ------------ `PrivTr` declared as private -... LL | / pub fn f() LL | | LL | | where LL | | PubTy: PrivTr - | |_____________________^ can't leak private trait + | |_____________________^ associated function `S::f` is reachable at visibility `pub` + | +note: but trait `PrivTr` is only usable at visibility `pub(crate)` + --> $DIR/where-pub-type-impls-priv-trait.rs:10:1 + | +LL | trait PrivTr {} + | ^^^^^^^^^^^^ -error: aborting due to 5 previous errors +warning: 5 warnings emitted -For more information about this error, try `rustc --explain E0445`. |