diff options
Diffstat (limited to 'tests/ui/privacy')
5 files changed, 83 insertions, 0 deletions
diff --git a/tests/ui/privacy/inaccessible-fields-pattern-matching-76077.fixed b/tests/ui/privacy/inaccessible-fields-pattern-matching-76077.fixed new file mode 100644 index 00000000000..7d648543a20 --- /dev/null +++ b/tests/ui/privacy/inaccessible-fields-pattern-matching-76077.fixed @@ -0,0 +1,19 @@ +// https://github.com/rust-lang/rust/issues/76077 +//@ run-rustfix +#![allow(dead_code, unused_variables)] + +pub mod foo { + #[derive(Default)] + pub struct Foo { invisible: bool, } + + #[derive(Default)] + pub struct Bar { pub visible: bool, invisible: bool, } +} + +fn main() { + let foo::Foo { .. } = foo::Foo::default(); + //~^ ERROR pattern requires `..` due to inaccessible fields + + let foo::Bar { visible, .. } = foo::Bar::default(); + //~^ ERROR pattern requires `..` due to inaccessible fields +} diff --git a/tests/ui/privacy/inaccessible-fields-pattern-matching-76077.rs b/tests/ui/privacy/inaccessible-fields-pattern-matching-76077.rs new file mode 100644 index 00000000000..f3b51187ae3 --- /dev/null +++ b/tests/ui/privacy/inaccessible-fields-pattern-matching-76077.rs @@ -0,0 +1,19 @@ +// https://github.com/rust-lang/rust/issues/76077 +//@ run-rustfix +#![allow(dead_code, unused_variables)] + +pub mod foo { + #[derive(Default)] + pub struct Foo { invisible: bool, } + + #[derive(Default)] + pub struct Bar { pub visible: bool, invisible: bool, } +} + +fn main() { + let foo::Foo {} = foo::Foo::default(); + //~^ ERROR pattern requires `..` due to inaccessible fields + + let foo::Bar { visible } = foo::Bar::default(); + //~^ ERROR pattern requires `..` due to inaccessible fields +} diff --git a/tests/ui/privacy/inaccessible-fields-pattern-matching-76077.stderr b/tests/ui/privacy/inaccessible-fields-pattern-matching-76077.stderr new file mode 100644 index 00000000000..070fa1a53a5 --- /dev/null +++ b/tests/ui/privacy/inaccessible-fields-pattern-matching-76077.stderr @@ -0,0 +1,24 @@ +error: pattern requires `..` due to inaccessible fields + --> $DIR/inaccessible-fields-pattern-matching-76077.rs:14:9 + | +LL | let foo::Foo {} = foo::Foo::default(); + | ^^^^^^^^^^^ + | +help: ignore the inaccessible and unused fields + | +LL | let foo::Foo { .. } = foo::Foo::default(); + | ++ + +error: pattern requires `..` due to inaccessible fields + --> $DIR/inaccessible-fields-pattern-matching-76077.rs:17:9 + | +LL | let foo::Bar { visible } = foo::Bar::default(); + | ^^^^^^^^^^^^^^^^^^^^ + | +help: ignore the inaccessible and unused fields + | +LL | let foo::Bar { visible, .. } = foo::Bar::default(); + | ++++ + +error: aborting due to 2 previous errors + diff --git a/tests/ui/privacy/private-field-struct-construction-76077.rs b/tests/ui/privacy/private-field-struct-construction-76077.rs new file mode 100644 index 00000000000..7fc3473e8de --- /dev/null +++ b/tests/ui/privacy/private-field-struct-construction-76077.rs @@ -0,0 +1,11 @@ +// https://github.com/rust-lang/rust/issues/76077 +pub mod foo { + pub struct Foo { + you_cant_use_this_field: bool, + } +} + +fn main() { + foo::Foo {}; + //~^ ERROR cannot construct `Foo` with struct literal syntax due to private fields +} diff --git a/tests/ui/privacy/private-field-struct-construction-76077.stderr b/tests/ui/privacy/private-field-struct-construction-76077.stderr new file mode 100644 index 00000000000..5131db72fe3 --- /dev/null +++ b/tests/ui/privacy/private-field-struct-construction-76077.stderr @@ -0,0 +1,10 @@ +error: cannot construct `Foo` with struct literal syntax due to private fields + --> $DIR/private-field-struct-construction-76077.rs:9:5 + | +LL | foo::Foo {}; + | ^^^^^^^^ + | + = note: private field `you_cant_use_this_field` that was not provided + +error: aborting due to 1 previous error + |
