-
Notifications
You must be signed in to change notification settings - Fork 123
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
Fix transparency check on shared attribute formatting on enums (#377) #395
Open
tyranron
wants to merge
4
commits into
master
Choose a base branch
from
fix-shared-transparency-check
base: master
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.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like we should disallow this instead. i.e. if you use a display attribute on a variant without having
_variant
in the display attribute on the enum.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe it should just use the display tag on the enum as the default. And if a variant has one set then the one from the variant overrides the one from the enum, unless there is a
_variant
inside the one on the enum.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JelteF I would rather fix this in a separate PR, because it's somewhat orthogonal to the issue being fixed here.
We negotiated about the top-level attribute acting as the default one back in #142. There could be some unobvious subtleties about such behavior. Need to re-read all the thread.
I propose we better forbid this for now (in a separate PR), and negotiate the exact defaulting behavior in #142 (by re-opening it) or in new issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JelteF ping.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The behaviour that we currently have on the master branch is that the top-level attribute acts as the default when no
_variant
is present. This seems at least somewhat reasonable behaviour and multiple posts in #142 suggest this behaviour too, and I didn't see strong arguments against it. Changing this behaviour now to be an error, or to do something differently would be a backward compatibility issue now that we're 1.0.0.The behaviour proposed in this PR we definitely don't want IMHO. It's super confusing that the
#[display]
attributes on the variants are completely ignored.I think we should make a PR that add the tests from this PR and makes sure we don't change the current behaviour. And also we should update the documentation to note that this is what happens.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JelteF
It seems not to be like that. At least we have the test showing the opposite overwriting behavior. And it had been introduced in #377 by your commit before I altered the desugaring. Maybe I miss something, but "acts as the default when no
_variant
is present" was never a thing.This PR has nothing to do with such behavior. It doesn't alter any behavior, only makes transparency check for shared attribute formatting more clever, fixing some cases overlooked in #377.
I'm not against it. It just seems to be a theme for a separate PR.
Considering that we've just released, it's unlikely that people have widely adopted it. I agree that it's super confusing one. So, yanking 1.0.0 and releasing 1.0.1 with treating this case more correctly is reasonable a good way to go here, as for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR definitely does change behaviour: i.e. if you remove your code changes the new test that you added with
#[display("{_0}")]
returns the "acts as the default" result.After looking closer I do realize that that seems mostly by accident though. In all other cases it seems to do the "overwrite" approach, which imho is the worst possible behaviour.
So yeah let's make this test a hard error for now and release 1.0.1 quickly: https://github.com/JelteF/derive_more/blob/v1.0.0/tests/display.rs#L1404-L1427
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JelteF
I still don't see it or do misunderstand it. Given the test from the PR:
👍
But as I've proposed above, let me do it as a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JelteF considering the #405 discussion, we may introduce here a breaking behavior to set up things right.
I do still propose to merge this PR "as is", because it doesn't alter any interaction between top-level and variant-level
#[display()]
attributes, but only makes the transparency check more clever to not consider cases it shouldn't to.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like you made a mistake in testing, because the example you shared very clearly fails on 1.0.0 (because 1.0.0 has the "acts as the default" behaviour in that specific case). Try running this
cargo-script
and see how it errors:To make it pass you need to change it to this: