You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Re-exporting types allows maintainers to move or rename types without breaking downstream users. Usually pub use is used for this purpose, but some uses of pub type work too and are used by some maintainers.
Unfortunately, pub type does not allow unit and tuple structs to be constructed using their usual unit/tuple syntax (see examples below). Even though the curly-braces syntax is also allowed for unit/tuple structs and would still work with pub type, it's practically guaranteed to not be used since it isn't idiomatic in these cases. That makes this a major breaking change.
This requires new schema that would allow the lint to track whether each importable path points to:
the type definition itself,
a pub use, which still allows the unit and tuple constructor syntax,
a pub type type alias, which is the only case that could have this major breaking change.
Only externally-constructible structs are affected. Structs with private fields or with the #[non_exhaustive] attribute are not affected. (Pattern-matching a tuple that constructible from the given crate is only allowed with the curly-braces syntax. Foo(x, ..) is not allowed outside of Foo's defining crate if it is not externally-constructible, so tuple patterns aren't the cause of additional breakage. Tuple structs with both public and private fields are therefore not broken by a pub type re-export.)
error[E0423]: expected function, tuple struct or tuple variant, found type alias `Foo`
--> src/lib.rs:8:5
|
8 | Foo(1)
| ^^^
|
= note: can't use a type alias as a constructor
The text was updated successfully, but these errors were encountered:
It's possible that with sufficient effort, users might be able to make this kind of change without triggering a semver-major change. Based on an idea shared on r/rust, the crate author making this change may be able to add a const (for a unit struct) or a fn (for a tuple struct) with the same name as the pub type and have it act as the constructor that was lost in the pub type.
For example, one may be able to replace pub struct Foo(pub u8) with something like:
Re-exporting types allows maintainers to move or rename types without breaking downstream users. Usually
pub use
is used for this purpose, but some uses ofpub type
work too and are used by some maintainers.Unfortunately,
pub type
does not allow unit and tuple structs to be constructed using their usual unit/tuple syntax (see examples below). Even though the curly-braces syntax is also allowed for unit/tuple structs and would still work withpub type
, it's practically guaranteed to not be used since it isn't idiomatic in these cases. That makes this a major breaking change.This requires new schema that would allow the lint to track whether each importable path points to:
pub use
, which still allows the unit and tuple constructor syntax,pub type
type alias, which is the only case that could have this major breaking change.Only externally-constructible structs are affected. Structs with private fields or with the
#[non_exhaustive]
attribute are not affected. (Pattern-matching a tuple that constructible from the given crate is only allowed with the curly-braces syntax.Foo(x, ..)
is not allowed outside ofFoo
's defining crate if it is not externally-constructible, so tuple patterns aren't the cause of additional breakage. Tuple structs with both public and private fields are therefore not broken by apub type
re-export.)Unit struct example: playground link
produces:
Tuple struct example: playground link
produces:
The text was updated successfully, but these errors were encountered: