summaryrefslogtreecommitdiffstats
path: root/tests/ui/privacy/sealed-traits
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
commitdc0db358abe19481e475e10c32149b53370f1a1c (patch)
treeab8ce99c4b255ce46f99ef402c27916055b899ee /tests/ui/privacy/sealed-traits
parentReleasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff)
downloadrustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz
rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
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.rs19
-rw-r--r--tests/ui/privacy/sealed-traits/sealed-trait-local.stderr16
9 files changed, 123 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..294999798
--- /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 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..c7ec72ff1
--- /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 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..b630565d0
--- /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 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..778ddf0f8
--- /dev/null
+++ b/tests/ui/privacy/sealed-traits/sealed-trait-local.rs
@@ -0,0 +1,19 @@
+// 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 {}
+ }
+}
+
+struct S;
+impl a::Sealed for S {} //~ ERROR the trait bound `S: Hidden` is not satisfied
+
+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..d1052ce35
--- /dev/null
+++ b/tests/ui/privacy/sealed-traits/sealed-trait-local.stderr
@@ -0,0 +1,16 @@
+error[E0277]: the trait bound `S: Hidden` is not satisfied
+ --> $DIR/sealed-trait-local.rs:17:20
+ |
+LL | impl a::Sealed for S {}
+ | ^ the trait `Hidden` is not implemented for `S`
+ |
+note: required by a bound in `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 implelement `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
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.