Skip to content

Commit cb7becf

Browse files
committed
Tweaks
1 parent 24f5bf8 commit cb7becf

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

active/0000-enum-namespacing.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,14 @@ which contains 232 variants. It would be ridiculous to `pub use` all of them!
169169
With namespaced enums, this kind of reexport becomes a simple `pub use` of the
170170
enum itself.
171171

172-
Sometimes a developer wants to use many of an enum's variants, and doesn't want
173-
to require the use of the parent module (in flat enums) or the enum (in
174-
namespaced enums) as part of the name. This is especially common for private,
175-
internal enums within a crate. With flat enums, this requires each enum to be
176-
`use`d individually, which can get *extremely* verbose. For example, take
177-
[this](https://github.com/sfackler/rust-postgres/blob/557a159a8a4a8e33333b06ad2722b1322e95566c/src/lib.rs#L97-L136)
178-
from `rust-postgres`:
172+
Sometimes a developer wants to use many variants of an enum in an "unqualified"
173+
manner, without qualification by the containing module (with flat enums) or
174+
enum (with namespaced enums). This is especially common for private, internal
175+
enums within a crate. With flat enums, this is trivial within the module in
176+
which the enum is defined, but very painful anywhere else, as it requires each
177+
variant to be `use`d individually, which can get *extremely* verbose. For
178+
example, take this [from
179+
`rust-postgres`](https://github.com/sfackler/rust-postgres/blob/557a159a8a4a8e33333b06ad2722b1322e95566c/src/lib.rs#L97-L136):
179180
```rust
180181
use message::{AuthenticationCleartextPassword,
181182
AuthenticationGSS,
@@ -331,7 +332,7 @@ struct Bar;
331332

332333
fn broken(f: Foo) {
333334
match f {
334-
Bar => {} // ~ ERROR expected a `Foo` but found struct `Bar`
335+
Bar => {} // ~ ERROR expected a `Foo` but found type `Bar`
335336
Baz => {}
336337
}
337338
}
@@ -381,10 +382,12 @@ increased complexity comes an increased chance of bugs.
381382
# Alternatives
382383

383384
We can push to switch entirely to namespaced enums before 1.0. This will allow
384-
us to avoid the compatibility fallback, at the cost of adding a significant
385-
amount of work to the 1.0 docket. Given that there is a reasonable post-1.0
386-
path forward, the pain required to push it through before 1.0 does not seem
387-
worth it.
385+
us to avoid the compatibility fallback and minimize library cruft, at the cost
386+
of adding a significant amount of work to the 1.0 docket. If we decide to go
387+
down this route, we could use the same implementation strategy laid out here to
388+
avoid breaking the entire world at once - implement the fallback and lint at a
389+
default (or forced) `warn` level and then remove both after some period of
390+
time.
388391

389392
Earlier iterations of namespaced enum proposals suggested preserving flat enums
390393
and adding `enum mod` syntax for namespaced enums. However, variant namespacing

0 commit comments

Comments
 (0)