summaryrefslogtreecommitdiffstats
path: root/src/test/ui/privacy
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/ui/privacy')
-rw-r--r--src/test/ui/privacy/auxiliary/issue-75907.rs17
-rw-r--r--src/test/ui/privacy/effective_visibilities.rs13
-rw-r--r--src/test/ui/privacy/effective_visibilities.stderr58
-rw-r--r--src/test/ui/privacy/effective_visibilities_glob.rs21
-rw-r--r--src/test/ui/privacy/effective_visibilities_glob.stderr26
-rw-r--r--src/test/ui/privacy/effective_visibilities_invariants.rs12
-rw-r--r--src/test/ui/privacy/effective_visibilities_invariants.stderr32
-rw-r--r--src/test/ui/privacy/issue-75906.rs13
-rw-r--r--src/test/ui/privacy/issue-75906.stderr15
-rw-r--r--src/test/ui/privacy/issue-75907.rs18
-rw-r--r--src/test/ui/privacy/issue-75907.stderr29
-rw-r--r--src/test/ui/privacy/issue-75907_b.rs14
-rw-r--r--src/test/ui/privacy/issue-75907_b.stderr31
13 files changed, 267 insertions, 32 deletions
diff --git a/src/test/ui/privacy/auxiliary/issue-75907.rs b/src/test/ui/privacy/auxiliary/issue-75907.rs
new file mode 100644
index 000000000..389c9c351
--- /dev/null
+++ b/src/test/ui/privacy/auxiliary/issue-75907.rs
@@ -0,0 +1,17 @@
+pub struct Bar(pub u8, u8, u8);
+
+pub fn make_bar() -> Bar {
+ Bar(1, 12, 10)
+}
+
+mod inner {
+ pub struct Foo(u8, pub u8, u8);
+
+ impl Foo {
+ pub fn new() -> Foo {
+ Foo(1, 12, 10)
+ }
+ }
+}
+
+pub use inner::Foo;
diff --git a/src/test/ui/privacy/effective_visibilities.rs b/src/test/ui/privacy/effective_visibilities.rs
index 1d806a1d1..ff20e20d3 100644
--- a/src/test/ui/privacy/effective_visibilities.rs
+++ b/src/test/ui/privacy/effective_visibilities.rs
@@ -6,7 +6,7 @@ mod outer { //~ ERROR Direct: pub(crate), Reexported: pub(crate), Reachable: pub
pub mod inner1 { //~ ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
#[rustc_effective_visibility]
- extern "C" {} //~ ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ extern "C" {} //~ ERROR not in the table
#[rustc_effective_visibility]
pub trait PubTrait { //~ ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
@@ -17,12 +17,13 @@ mod outer { //~ ERROR Direct: pub(crate), Reexported: pub(crate), Reachable: pub
}
#[rustc_effective_visibility]
- struct PrivStruct; //~ ERROR not in the table
+ struct PrivStruct; //~ ERROR Direct: pub(self), Reexported: pub(self), Reachable: pub(self), ReachableThroughImplTrait: pub(self)
+ //~| ERROR Direct: pub(self), Reexported: pub(self), Reachable: pub(self), ReachableThroughImplTrait: pub(self)
#[rustc_effective_visibility]
pub union PubUnion { //~ ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
#[rustc_effective_visibility]
- a: u8, //~ ERROR not in the table
+ a: u8, //~ ERROR Direct: pub(self), Reexported: pub(self), Reachable: pub(self), ReachableThroughImplTrait: pub(self)
#[rustc_effective_visibility]
pub b: u8, //~ ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
}
@@ -31,6 +32,7 @@ mod outer { //~ ERROR Direct: pub(crate), Reexported: pub(crate), Reachable: pub
pub enum Enum { //~ ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
#[rustc_effective_visibility]
A( //~ ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ //~| ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
#[rustc_effective_visibility]
PubUnion, //~ ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
),
@@ -38,13 +40,13 @@ mod outer { //~ ERROR Direct: pub(crate), Reexported: pub(crate), Reachable: pub
}
#[rustc_effective_visibility]
- macro_rules! none_macro { //~ Direct: pub(crate), Reexported: pub(crate), Reachable: pub(crate), ReachableThroughImplTrait: pub(crate)
+ macro_rules! none_macro { //~ ERROR not in the table
() => {};
}
#[macro_export]
#[rustc_effective_visibility]
- macro_rules! public_macro { //~ Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ macro_rules! public_macro { //~ ERROR Direct: pub(self), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
() => {};
}
@@ -70,6 +72,5 @@ mod half_public_import {
#[rustc_effective_visibility]
pub use half_public_import::HalfPublicImport; //~ ERROR Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
- //~^ ERROR Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
fn main() {}
diff --git a/src/test/ui/privacy/effective_visibilities.stderr b/src/test/ui/privacy/effective_visibilities.stderr
index 1c6201600..046b6095f 100644
--- a/src/test/ui/privacy/effective_visibilities.stderr
+++ b/src/test/ui/privacy/effective_visibilities.stderr
@@ -10,7 +10,7 @@ error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImpl
LL | pub mod inner1 {
| ^^^^^^^^^^^^^^
-error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+error: not in the table
--> $DIR/effective_visibilities.rs:9:9
|
LL | extern "C" {}
@@ -22,98 +22,104 @@ error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImpl
LL | pub trait PubTrait {
| ^^^^^^^^^^^^^^^^^^
-error: not in the table
+error: Direct: pub(self), Reexported: pub(self), Reachable: pub(self), ReachableThroughImplTrait: pub(self)
+ --> $DIR/effective_visibilities.rs:20:9
+ |
+LL | struct PrivStruct;
+ | ^^^^^^^^^^^^^^^^^
+
+error: Direct: pub(self), Reexported: pub(self), Reachable: pub(self), ReachableThroughImplTrait: pub(self)
--> $DIR/effective_visibilities.rs:20:9
|
LL | struct PrivStruct;
| ^^^^^^^^^^^^^^^^^
error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
- --> $DIR/effective_visibilities.rs:23:9
+ --> $DIR/effective_visibilities.rs:24:9
|
LL | pub union PubUnion {
| ^^^^^^^^^^^^^^^^^^
-error: not in the table
- --> $DIR/effective_visibilities.rs:25:13
+error: Direct: pub(self), Reexported: pub(self), Reachable: pub(self), ReachableThroughImplTrait: pub(self)
+ --> $DIR/effective_visibilities.rs:26:13
|
LL | a: u8,
| ^^^^^
error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
- --> $DIR/effective_visibilities.rs:27:13
+ --> $DIR/effective_visibilities.rs:28:13
|
LL | pub b: u8,
| ^^^^^^^^^
error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
- --> $DIR/effective_visibilities.rs:31:9
+ --> $DIR/effective_visibilities.rs:32:9
|
LL | pub enum Enum {
| ^^^^^^^^^^^^^
error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
- --> $DIR/effective_visibilities.rs:33:13
+ --> $DIR/effective_visibilities.rs:34:13
+ |
+LL | A(
+ | ^
+
+error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ --> $DIR/effective_visibilities.rs:34:13
|
LL | A(
| ^
error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
- --> $DIR/effective_visibilities.rs:35:17
+ --> $DIR/effective_visibilities.rs:37:17
|
LL | PubUnion,
| ^^^^^^^^
-error: Direct: pub(crate), Reexported: pub(crate), Reachable: pub(crate), ReachableThroughImplTrait: pub(crate)
- --> $DIR/effective_visibilities.rs:41:5
+error: not in the table
+ --> $DIR/effective_visibilities.rs:43:5
|
LL | macro_rules! none_macro {
| ^^^^^^^^^^^^^^^^^^^^^^^
-error: Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
- --> $DIR/effective_visibilities.rs:47:5
+error: Direct: pub(self), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ --> $DIR/effective_visibilities.rs:49:5
|
LL | macro_rules! public_macro {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: Direct: pub(crate), Reexported: pub(crate), Reachable: pub, ReachableThroughImplTrait: pub
- --> $DIR/effective_visibilities.rs:52:5
+ --> $DIR/effective_visibilities.rs:54:5
|
LL | pub struct ReachableStruct {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Direct: pub(crate), Reexported: pub(crate), Reachable: pub, ReachableThroughImplTrait: pub
- --> $DIR/effective_visibilities.rs:54:9
+ --> $DIR/effective_visibilities.rs:56:9
|
LL | pub a: u8,
| ^^^^^^^^^
error: Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
- --> $DIR/effective_visibilities.rs:59:9
+ --> $DIR/effective_visibilities.rs:61:9
|
LL | pub use outer::inner1;
| ^^^^^^^^^^^^^
error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
- --> $DIR/effective_visibilities.rs:65:5
+ --> $DIR/effective_visibilities.rs:67:5
|
LL | pub type HalfPublicImport = u8;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: Direct: pub(crate), Reexported: pub(crate), Reachable: pub(crate), ReachableThroughImplTrait: pub(crate)
- --> $DIR/effective_visibilities.rs:68:5
+ --> $DIR/effective_visibilities.rs:70:5
|
LL | pub(crate) const HalfPublicImport: u8 = 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
- --> $DIR/effective_visibilities.rs:72:9
- |
-LL | pub use half_public_import::HalfPublicImport;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-error: Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
- --> $DIR/effective_visibilities.rs:72:9
+ --> $DIR/effective_visibilities.rs:74:9
|
LL | pub use half_public_import::HalfPublicImport;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -130,5 +136,5 @@ error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImpl
LL | type B;
| ^^^^^^
-error: aborting due to 22 previous errors
+error: aborting due to 23 previous errors
diff --git a/src/test/ui/privacy/effective_visibilities_glob.rs b/src/test/ui/privacy/effective_visibilities_glob.rs
new file mode 100644
index 000000000..eb9dcd6cd
--- /dev/null
+++ b/src/test/ui/privacy/effective_visibilities_glob.rs
@@ -0,0 +1,21 @@
+// Effective visibility tracking for imports is fine-grained, so `S2` is not fully exported
+// even if its parent import (`m::*`) is fully exported as a `use` item.
+
+#![feature(rustc_attrs)]
+
+mod m {
+ #[rustc_effective_visibility]
+ pub struct S1 {} //~ ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ #[rustc_effective_visibility]
+ pub struct S2 {} //~ ERROR Direct: pub(crate), Reexported: pub(crate), Reachable: pub(crate), ReachableThroughImplTrait: pub(crate)
+}
+
+mod glob {
+ #[rustc_effective_visibility]
+ pub use crate::m::*; //~ ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+}
+
+#[rustc_effective_visibility]
+pub use glob::S1; //~ ERROR Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+
+fn main() {}
diff --git a/src/test/ui/privacy/effective_visibilities_glob.stderr b/src/test/ui/privacy/effective_visibilities_glob.stderr
new file mode 100644
index 000000000..0496cd5df
--- /dev/null
+++ b/src/test/ui/privacy/effective_visibilities_glob.stderr
@@ -0,0 +1,26 @@
+error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ --> $DIR/effective_visibilities_glob.rs:8:5
+ |
+LL | pub struct S1 {}
+ | ^^^^^^^^^^^^^
+
+error: Direct: pub(crate), Reexported: pub(crate), Reachable: pub(crate), ReachableThroughImplTrait: pub(crate)
+ --> $DIR/effective_visibilities_glob.rs:10:5
+ |
+LL | pub struct S2 {}
+ | ^^^^^^^^^^^^^
+
+error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ --> $DIR/effective_visibilities_glob.rs:15:13
+ |
+LL | pub use crate::m::*;
+ | ^^^^^^^^
+
+error: Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ --> $DIR/effective_visibilities_glob.rs:19:9
+ |
+LL | pub use glob::S1;
+ | ^^^^^^^^
+
+error: aborting due to 4 previous errors
+
diff --git a/src/test/ui/privacy/effective_visibilities_invariants.rs b/src/test/ui/privacy/effective_visibilities_invariants.rs
new file mode 100644
index 000000000..af5a2bed6
--- /dev/null
+++ b/src/test/ui/privacy/effective_visibilities_invariants.rs
@@ -0,0 +1,12 @@
+// Invariant checking doesn't ICE in some cases with errors (issue #104249).
+
+#![feature(staged_api)] //~ ERROR module has missing stability attribute
+
+pub mod m {} //~ ERROR module has missing stability attribute
+
+pub mod m { //~ ERROR the name `m` is defined multiple times
+ mod inner {}
+ type Inner = u8;
+}
+
+fn main() {}
diff --git a/src/test/ui/privacy/effective_visibilities_invariants.stderr b/src/test/ui/privacy/effective_visibilities_invariants.stderr
new file mode 100644
index 000000000..fd205f405
--- /dev/null
+++ b/src/test/ui/privacy/effective_visibilities_invariants.stderr
@@ -0,0 +1,32 @@
+error[E0428]: the name `m` is defined multiple times
+ --> $DIR/effective_visibilities_invariants.rs:7:1
+ |
+LL | pub mod m {}
+ | --------- previous definition of the module `m` here
+LL |
+LL | pub mod m {
+ | ^^^^^^^^^ `m` redefined here
+ |
+ = note: `m` must be defined only once in the type namespace of this module
+
+error: module has missing stability attribute
+ --> $DIR/effective_visibilities_invariants.rs:3:1
+ |
+LL | / #![feature(staged_api)]
+LL | |
+LL | | pub mod m {}
+LL | |
+... |
+LL | |
+LL | | fn main() {}
+ | |____________^
+
+error: module has missing stability attribute
+ --> $DIR/effective_visibilities_invariants.rs:5:1
+ |
+LL | pub mod m {}
+ | ^^^^^^^^^^^^
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0428`.
diff --git a/src/test/ui/privacy/issue-75906.rs b/src/test/ui/privacy/issue-75906.rs
new file mode 100644
index 000000000..710039d79
--- /dev/null
+++ b/src/test/ui/privacy/issue-75906.rs
@@ -0,0 +1,13 @@
+mod m {
+ pub struct Foo { x: u8 }
+
+ pub struct Bar(u8);
+}
+
+use m::{Foo, Bar};
+
+fn main() {
+ let x = Foo { x: 12 };
+ let y = Bar(12);
+ //~^ ERROR cannot initialize a tuple struct which contains private fields [E0423]
+}
diff --git a/src/test/ui/privacy/issue-75906.stderr b/src/test/ui/privacy/issue-75906.stderr
new file mode 100644
index 000000000..4c6a68646
--- /dev/null
+++ b/src/test/ui/privacy/issue-75906.stderr
@@ -0,0 +1,15 @@
+error[E0423]: cannot initialize a tuple struct which contains private fields
+ --> $DIR/issue-75906.rs:11:13
+ |
+LL | let y = Bar(12);
+ | ^^^
+ |
+note: constructor is not visible here due to private fields
+ --> $DIR/issue-75906.rs:4:20
+ |
+LL | pub struct Bar(u8);
+ | ^^ private field
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0423`.
diff --git a/src/test/ui/privacy/issue-75907.rs b/src/test/ui/privacy/issue-75907.rs
new file mode 100644
index 000000000..6da99cf64
--- /dev/null
+++ b/src/test/ui/privacy/issue-75907.rs
@@ -0,0 +1,18 @@
+// Test for diagnostic improvement issue #75907
+
+mod foo {
+ pub(crate) struct Foo(u8);
+ pub(crate) struct Bar(pub u8, u8, Foo);
+
+ pub(crate) fn make_bar() -> Bar {
+ Bar(1, 12, Foo(10))
+ }
+}
+
+use foo::{make_bar, Bar, Foo};
+
+fn main() {
+ let Bar(x, y, Foo(z)) = make_bar();
+ //~^ ERROR cannot match against a tuple struct which contains private fields
+ //~| ERROR cannot match against a tuple struct which contains private fields
+}
diff --git a/src/test/ui/privacy/issue-75907.stderr b/src/test/ui/privacy/issue-75907.stderr
new file mode 100644
index 000000000..2f89e31a3
--- /dev/null
+++ b/src/test/ui/privacy/issue-75907.stderr
@@ -0,0 +1,29 @@
+error[E0532]: cannot match against a tuple struct which contains private fields
+ --> $DIR/issue-75907.rs:15:9
+ |
+LL | let Bar(x, y, Foo(z)) = make_bar();
+ | ^^^
+ |
+note: constructor is not visible here due to private fields
+ --> $DIR/issue-75907.rs:15:16
+ |
+LL | let Bar(x, y, Foo(z)) = make_bar();
+ | ^ ^^^^^^ private field
+ | |
+ | private field
+
+error[E0532]: cannot match against a tuple struct which contains private fields
+ --> $DIR/issue-75907.rs:15:19
+ |
+LL | let Bar(x, y, Foo(z)) = make_bar();
+ | ^^^
+ |
+note: constructor is not visible here due to private fields
+ --> $DIR/issue-75907.rs:15:23
+ |
+LL | let Bar(x, y, Foo(z)) = make_bar();
+ | ^ private field
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0532`.
diff --git a/src/test/ui/privacy/issue-75907_b.rs b/src/test/ui/privacy/issue-75907_b.rs
new file mode 100644
index 000000000..fdfc5907c
--- /dev/null
+++ b/src/test/ui/privacy/issue-75907_b.rs
@@ -0,0 +1,14 @@
+// Test for diagnostic improvement issue #75907, extern crate
+// aux-build:issue-75907.rs
+
+extern crate issue_75907 as a;
+
+use a::{make_bar, Bar, Foo};
+
+fn main() {
+ let Bar(x, y, z) = make_bar();
+ //~^ ERROR cannot match against a tuple struct which contains private fields
+
+ let Foo(x, y, z) = Foo::new();
+ //~^ ERROR cannot match against a tuple struct which contains private fields
+}
diff --git a/src/test/ui/privacy/issue-75907_b.stderr b/src/test/ui/privacy/issue-75907_b.stderr
new file mode 100644
index 000000000..b82d08473
--- /dev/null
+++ b/src/test/ui/privacy/issue-75907_b.stderr
@@ -0,0 +1,31 @@
+error[E0532]: cannot match against a tuple struct which contains private fields
+ --> $DIR/issue-75907_b.rs:9:9
+ |
+LL | let Bar(x, y, z) = make_bar();
+ | ^^^
+ |
+note: constructor is not visible here due to private fields
+ --> $DIR/issue-75907_b.rs:9:16
+ |
+LL | let Bar(x, y, z) = make_bar();
+ | ^ ^ private field
+ | |
+ | private field
+
+error[E0532]: cannot match against a tuple struct which contains private fields
+ --> $DIR/issue-75907_b.rs:12:9
+ |
+LL | let Foo(x, y, z) = Foo::new();
+ | ^^^
+ |
+note: constructor is not visible here due to private fields
+ --> $DIR/issue-75907_b.rs:12:13
+ |
+LL | let Foo(x, y, z) = Foo::new();
+ | ^ ^ private field
+ | |
+ | private field
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0532`.