summaryrefslogtreecommitdiffstats
path: root/tests/ui/privacy/sealed-traits
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/privacy/sealed-traits')
-rw-r--r--tests/ui/privacy/sealed-traits/private-trait-non-local.rs4
-rw-r--r--tests/ui/privacy/sealed-traits/private-trait-non-local.stderr12
-rw-r--r--tests/ui/privacy/sealed-traits/private-trait.rs10
-rw-r--r--tests/ui/privacy/sealed-traits/private-trait.stderr17
-rw-r--r--tests/ui/privacy/sealed-traits/re-exported-trait.fixed13
-rw-r--r--tests/ui/privacy/sealed-traits/re-exported-trait.rs13
-rw-r--r--tests/ui/privacy/sealed-traits/re-exported-trait.stderr19
-rw-r--r--tests/ui/privacy/sealed-traits/sealed-trait-local.rs55
-rw-r--r--tests/ui/privacy/sealed-traits/sealed-trait-local.stderr50
9 files changed, 193 insertions, 0 deletions
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`.