mirror of
https://github.com/rust-lang/rust.git
synced 2025-12-03 05:49:42 +00:00
When a tuple-struct is re-exported that has inaccessible fields at the `use` scope, the type's constructor cannot be accessed through that re-export. We now account for this case and extend the resulting resolution error. We also check if the constructor would be accessible directly, not through the re-export, and if so, we suggest using the full path instead. ``` error[E0423]: cannot initialize a tuple struct which contains private fields --> $DIR/ctor-not-accessible-due-to-inaccessible-field-in-reexport.rs:12:33 | LL | let crate::Foo(x) = crate::Foo(42); | ^^^^^^^^^^ | note: the type is accessed through this re-export, but the type's constructor is not visible in this import's scope due to private fields --> $DIR/ctor-not-accessible-due-to-inaccessible-field-in-reexport.rs:3:9 | LL | pub use my_mod::Foo; | ^^^^^^^^^^^ help: the type can be constructed directly, because its fields are available from the current scope | LL | let crate::Foo(x) = crate::my_mod::Foo(42); | ~~~~~~~~~~~~~~~~~~ ``` Fix #133343.
21 lines
930 B
Rust
21 lines
930 B
Rust
#![allow(dead_code, unused_variables)]
|
|
//@ run-rustfix
|
|
pub use my_mod::Foo;
|
|
//~^ NOTE the type is accessed through this re-export, but the type's constructor is not visible in this import's scope due to private fields
|
|
//~| NOTE the type is accessed through this re-export, but the type's constructor is not visible in this import's scope due to private fields
|
|
|
|
mod my_mod {
|
|
pub struct Foo(u32);
|
|
|
|
mod my_sub_mod {
|
|
fn my_func() {
|
|
let crate::Foo(x) = crate::Foo(42);
|
|
//~^ ERROR cannot initialize a tuple struct which contains private fields
|
|
//~| HELP the type can be constructed directly, because its fields are available from the current scope
|
|
//~| ERROR cannot match against a tuple struct which contains private fields
|
|
//~| HELP the type can be constructed directly, because its fields are available from the current scope
|
|
}
|
|
}
|
|
}
|
|
fn main() {}
|