-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Open
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Hi. I was using a crate which had a struct with a number of associated items and I was trying to save typing in an error handling function. But:
12 | use rocket::http::Status::*;
| ^^^^^^ `Status` is a struct, not a module
I looked in the Reference and I wasn't able to find any discussion of this. In particular, I would expect it to be documented in the explanation of Use declarations under Items.
After considerably more digging, I found:
- associated constants can't be
use
d #24915, a closed issue where the resolution was that this is not expected to work - https://internals.rust-lang.org/t/importing-associated-constants/6610/5, a discussion about how to maybe implement this (although it seems unlikely that that approach could work for the glob import I was trying...)
It seems that this situation is likely to persist. Maybe the error message could be improved? Something like
hint: importing associated items is not supported; you must use a path from to the parent type each time
could help the user by letting them know they can't avoid the extra typing.
I will also file an issue against the Reference. Thanks for your attention.
Metadata
Metadata
Assignees
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.