-
Notifications
You must be signed in to change notification settings - Fork 0
Schneems/smaller strum #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
schneems
wants to merge
16
commits into
main
Choose a base branch
from
schneems/smaller-strum
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When default features are disabled this crate won't be available, so we need to conditionally "use" it.
Uses the trait bounds largely provided by `strum` to write generic logic for constructing `KnownAttribute`-s and for generating a `HashMap` based lookup for `ParseAttribute`.
The new (shared) logic also ensures that the same attribute isn't defined more than once by mistake with a nice error.
Added `::` to prevent someone from doing something like `use other as cache_diff`.
Also makes a nicer error
The current type pattern will guarantee that every attribute known to the system is parsable, but it cannot guarantee that it's ever pulled from the HashMap. There's a slim chance someone could add an attribute, but forget to look it up. It's not likely with our current test suite, but I'm exploring ways to bake in more safety on edge cases where I can't lean more on types. This code will check to ensure that all entries are removed from the attribute lookup, so if one is parsed but not used, they'll get a nice error message. Worth noting: I experimented with a "drop guard" style of check that would automatically perform this logic on drop, but that leaves me with only the ability to panic in the error scenario which doesn't give us nice formatted compile errors.
Error before this change: ``` test tests/pass/struct_with_generics.rs ... error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ error[E0107]: missing generics for struct `Example` --> tests/pass/struct_with_generics.rs:4:8 | 4 | struct Example<T> | ^^^^^^^ expected 1 generic argument | note: struct defined here, with 1 generic parameter: `T` --> tests/pass/struct_with_generics.rs:4:8 | 4 | struct Example<T> | ^^^^^^^ - help: add missing generic argument | 4 | struct Example<T><T> | +++ ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ ``` After this change: It's passing.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.