From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- .../ui/xcrate/auxiliary/static_priv_by_default.rs | 51 +++++++++ src/test/ui/xcrate/auxiliary/xcrate_unit_struct.rs | 28 +++++ src/test/ui/xcrate/xcrate-private-by-default.rs | 45 ++++++++ .../ui/xcrate/xcrate-private-by-default.stderr | 123 +++++++++++++++++++++ src/test/ui/xcrate/xcrate-unit-struct-2.rs | 30 +++++ src/test/ui/xcrate/xcrate-unit-struct.rs | 12 ++ src/test/ui/xcrate/xcrate-unit-struct.stderr | 14 +++ 7 files changed, 303 insertions(+) create mode 100644 src/test/ui/xcrate/auxiliary/static_priv_by_default.rs create mode 100644 src/test/ui/xcrate/auxiliary/xcrate_unit_struct.rs create mode 100644 src/test/ui/xcrate/xcrate-private-by-default.rs create mode 100644 src/test/ui/xcrate/xcrate-private-by-default.stderr create mode 100644 src/test/ui/xcrate/xcrate-unit-struct-2.rs create mode 100644 src/test/ui/xcrate/xcrate-unit-struct.rs create mode 100644 src/test/ui/xcrate/xcrate-unit-struct.stderr (limited to 'src/test/ui/xcrate') diff --git a/src/test/ui/xcrate/auxiliary/static_priv_by_default.rs b/src/test/ui/xcrate/auxiliary/static_priv_by_default.rs new file mode 100644 index 000000000..39f912066 --- /dev/null +++ b/src/test/ui/xcrate/auxiliary/static_priv_by_default.rs @@ -0,0 +1,51 @@ +#![crate_type = "lib"] + +static private: isize = 0; +pub static public: isize = 0; + +pub struct A(()); + +impl A { + fn foo() {} +} + +mod foo { + pub static a: isize = 0; + pub fn b() {} + pub struct c; + pub enum d {} + pub type e = isize; + + pub struct A(()); + + impl A { + fn foo() {} + } + + // these are public so the parent can re-export them. + pub static reexported_a: isize = 0; + pub fn reexported_b() {} + pub struct reexported_c; + pub enum reexported_d {} + pub type reexported_e = isize; +} + +pub mod bar { + pub use foo::reexported_a as e; + pub use foo::reexported_b as f; + pub use foo::reexported_c as g; + pub use foo::reexported_d as h; + pub use foo::reexported_e as i; +} + +pub static a: isize = 0; +pub fn b() {} +pub struct c; +pub enum d {} +pub type e = isize; + +static j: isize = 0; +fn k() {} +struct l; +enum m {} +type n = isize; diff --git a/src/test/ui/xcrate/auxiliary/xcrate_unit_struct.rs b/src/test/ui/xcrate/auxiliary/xcrate_unit_struct.rs new file mode 100644 index 000000000..69ed498e7 --- /dev/null +++ b/src/test/ui/xcrate/auxiliary/xcrate_unit_struct.rs @@ -0,0 +1,28 @@ +#![crate_type = "lib"] + +// used by the rpass test + +#[derive(Copy, Clone)] +pub struct Struct; + +#[derive(Copy, Clone)] +pub enum Unit { + UnitVariant, + Argument(Struct) +} + +#[derive(Copy, Clone)] +pub struct TupleStruct(pub usize, pub &'static str); + +// used by the cfail test + +#[derive(Copy, Clone)] +pub struct StructWithFields { + foo: isize, +} + +#[derive(Copy, Clone)] +pub enum EnumWithVariants { + EnumVariant, + EnumVariantArg(isize) +} diff --git a/src/test/ui/xcrate/xcrate-private-by-default.rs b/src/test/ui/xcrate/xcrate-private-by-default.rs new file mode 100644 index 000000000..299cff54f --- /dev/null +++ b/src/test/ui/xcrate/xcrate-private-by-default.rs @@ -0,0 +1,45 @@ +// aux-build:static_priv_by_default.rs + +extern crate static_priv_by_default; + +fn foo() {} + +fn main() { + // Actual public items should be public + static_priv_by_default::a; + static_priv_by_default::b; + static_priv_by_default::c; + foo::(); + foo::(); + + // publicly re-exported items should be available + static_priv_by_default::bar::e; + static_priv_by_default::bar::f; + static_priv_by_default::bar::g; + foo::(); + foo::(); + + // private items at the top should be inaccessible + static_priv_by_default::j; + //~^ ERROR: static `j` is private + static_priv_by_default::k; + //~^ ERROR: function `k` is private + static_priv_by_default::l; + //~^ ERROR: struct `l` is private + foo::(); + //~^ ERROR: enum `m` is private + foo::(); + //~^ ERROR: type alias `n` is private + + // public items in a private mod should be inaccessible + static_priv_by_default::foo::a; + //~^ ERROR: module `foo` is private + static_priv_by_default::foo::b; + //~^ ERROR: module `foo` is private + static_priv_by_default::foo::c; + //~^ ERROR: module `foo` is private + foo::(); + //~^ ERROR: module `foo` is private + foo::(); + //~^ ERROR: module `foo` is private +} diff --git a/src/test/ui/xcrate/xcrate-private-by-default.stderr b/src/test/ui/xcrate/xcrate-private-by-default.stderr new file mode 100644 index 000000000..0bdd4002f --- /dev/null +++ b/src/test/ui/xcrate/xcrate-private-by-default.stderr @@ -0,0 +1,123 @@ +error[E0603]: static `j` is private + --> $DIR/xcrate-private-by-default.rs:23:29 + | +LL | static_priv_by_default::j; + | ^ private static + | +note: the static `j` is defined here + --> $DIR/auxiliary/static_priv_by_default.rs:47:1 + | +LL | static j: isize = 0; + | ^^^^^^^^^^^^^^^ + +error[E0603]: function `k` is private + --> $DIR/xcrate-private-by-default.rs:25:29 + | +LL | static_priv_by_default::k; + | ^ private function + | +note: the function `k` is defined here + --> $DIR/auxiliary/static_priv_by_default.rs:48:1 + | +LL | fn k() {} + | ^^^^^^ + +error[E0603]: unit struct `l` is private + --> $DIR/xcrate-private-by-default.rs:27:29 + | +LL | static_priv_by_default::l; + | ^ private unit struct + | +note: the unit struct `l` is defined here + --> $DIR/auxiliary/static_priv_by_default.rs:49:1 + | +LL | struct l; + | ^^^^^^^^ + +error[E0603]: enum `m` is private + --> $DIR/xcrate-private-by-default.rs:29:35 + | +LL | foo::(); + | ^ private enum + | +note: the enum `m` is defined here + --> $DIR/auxiliary/static_priv_by_default.rs:50:1 + | +LL | enum m {} + | ^^^^^^ + +error[E0603]: type alias `n` is private + --> $DIR/xcrate-private-by-default.rs:31:35 + | +LL | foo::(); + | ^ private type alias + | +note: the type alias `n` is defined here + --> $DIR/auxiliary/static_priv_by_default.rs:51:1 + | +LL | type n = isize; + | ^^^^^^ + +error[E0603]: module `foo` is private + --> $DIR/xcrate-private-by-default.rs:35:29 + | +LL | static_priv_by_default::foo::a; + | ^^^ private module + | +note: the module `foo` is defined here + --> $DIR/auxiliary/static_priv_by_default.rs:12:1 + | +LL | mod foo { + | ^^^^^^^ + +error[E0603]: module `foo` is private + --> $DIR/xcrate-private-by-default.rs:37:29 + | +LL | static_priv_by_default::foo::b; + | ^^^ private module + | +note: the module `foo` is defined here + --> $DIR/auxiliary/static_priv_by_default.rs:12:1 + | +LL | mod foo { + | ^^^^^^^ + +error[E0603]: module `foo` is private + --> $DIR/xcrate-private-by-default.rs:39:29 + | +LL | static_priv_by_default::foo::c; + | ^^^ private module + | +note: the module `foo` is defined here + --> $DIR/auxiliary/static_priv_by_default.rs:12:1 + | +LL | mod foo { + | ^^^^^^^ + +error[E0603]: module `foo` is private + --> $DIR/xcrate-private-by-default.rs:41:35 + | +LL | foo::(); + | ^^^ private module + | +note: the module `foo` is defined here + --> $DIR/auxiliary/static_priv_by_default.rs:12:1 + | +LL | mod foo { + | ^^^^^^^ + +error[E0603]: module `foo` is private + --> $DIR/xcrate-private-by-default.rs:43:35 + | +LL | foo::(); + | ^^^ private module + | +note: the module `foo` is defined here + --> $DIR/auxiliary/static_priv_by_default.rs:12:1 + | +LL | mod foo { + | ^^^^^^^ + +error: aborting due to 10 previous errors + +For more information about this error, try `rustc --explain E0603`. diff --git a/src/test/ui/xcrate/xcrate-unit-struct-2.rs b/src/test/ui/xcrate/xcrate-unit-struct-2.rs new file mode 100644 index 000000000..7aa3eb0d6 --- /dev/null +++ b/src/test/ui/xcrate/xcrate-unit-struct-2.rs @@ -0,0 +1,30 @@ +// run-pass +// aux-build:xcrate_unit_struct.rs +// pretty-expanded FIXME #23616 +#![allow(non_upper_case_globals)] + +extern crate xcrate_unit_struct; + +const s1: xcrate_unit_struct::Struct = xcrate_unit_struct::Struct; +static s2: xcrate_unit_struct::Unit = xcrate_unit_struct::Unit::UnitVariant; +static s3: xcrate_unit_struct::Unit = + xcrate_unit_struct::Unit::Argument(xcrate_unit_struct::Struct); +static s4: xcrate_unit_struct::Unit = xcrate_unit_struct::Unit::Argument(s1); +static s5: xcrate_unit_struct::TupleStruct = xcrate_unit_struct::TupleStruct(20, "foo"); + +fn f1(_: xcrate_unit_struct::Struct) {} +fn f2(_: xcrate_unit_struct::Unit) {} +fn f3(_: xcrate_unit_struct::TupleStruct) {} + +pub fn main() { + f1(xcrate_unit_struct::Struct); + f2(xcrate_unit_struct::Unit::UnitVariant); + f2(xcrate_unit_struct::Unit::Argument(xcrate_unit_struct::Struct)); + f3(xcrate_unit_struct::TupleStruct(10, "bar")); + + f1(s1); + f2(s2); + f2(s3); + f2(s4); + f3(s5); +} diff --git a/src/test/ui/xcrate/xcrate-unit-struct.rs b/src/test/ui/xcrate/xcrate-unit-struct.rs new file mode 100644 index 000000000..c99cf77ce --- /dev/null +++ b/src/test/ui/xcrate/xcrate-unit-struct.rs @@ -0,0 +1,12 @@ +// aux-build:xcrate_unit_struct.rs + +// Make sure that when we have cross-crate unit structs we don't accidentally +// make values out of cross-crate structs that aren't unit. + +extern crate xcrate_unit_struct; + +fn main() { + let _ = xcrate_unit_struct::StructWithFields; + //~^ ERROR expected value, found struct `xcrate_unit_struct::StructWithFields` + let _ = xcrate_unit_struct::Struct; +} diff --git a/src/test/ui/xcrate/xcrate-unit-struct.stderr b/src/test/ui/xcrate/xcrate-unit-struct.stderr new file mode 100644 index 000000000..cee314568 --- /dev/null +++ b/src/test/ui/xcrate/xcrate-unit-struct.stderr @@ -0,0 +1,14 @@ +error[E0423]: expected value, found struct `xcrate_unit_struct::StructWithFields` + --> $DIR/xcrate-unit-struct.rs:9:13 + | +LL | let _ = xcrate_unit_struct::StructWithFields; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use struct literal syntax instead: `xcrate_unit_struct::StructWithFields { foo: val }` + | + ::: $DIR/auxiliary/xcrate_unit_struct.rs:20:1 + | +LL | pub struct StructWithFields { + | --------------------------- `xcrate_unit_struct::StructWithFields` defined here + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0423`. -- cgit v1.2.3