Avoid name clashes with field names #15
Merged
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.
Hi. This is an alternative approach to #14, which I think fixes the problem definitively.
After 983a143 we still have name clashes if enum fields are things like
v_builder_
. That's a slightly odd field name, but I don't think it's reasonable to demand that a user of educe avoid it.In this branch, I:
Debug
Hash
Clone
and the comparison traits for enums983a143~
, and passes at the tip of the branchTo fix the enum impls I generally:
format_ident!
to generate derived names like_FIELD
.field_name_real
andfield_name_var
for the actual name, and the local variable name (pattern binding), respectively (rather than, sayfield_name
andfield_name2
).field_name2
because it needs two lots of field names in scope, used twoformat_ident!
calls to make two lots offield_name_var_...
2
suffix)I looked at the code for structs, and as far as I can see it doesn't bind the struct fields to local variable names, so it's not affected by issues analogous to #14. I also looked at the implementations of
Default
,Deref[Mut]
andInto
. These don't have any local variables, so although they use the struct field names directly as local variables, they avoid #14. I think it might be worth considering derived identifiers for these cases too, in case we should ever introduce local variables into the generated code for these - right now doing so would introduce the #14 bug again. But I'm not sure now is the right time to do that.Please let me know what you think.