-
Notifications
You must be signed in to change notification settings - Fork 156
fix W::bits signature #477
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
Conversation
r? @ryankurte (rust_highfive has picked a reviewer for you, use r? to override) |
This code doesn't fix problem in my view, as REG:Writer and W are different types. svd2rust/src/generate/register.rs Line 84 in 1a2bf65
|
I don't see any way (without traits) to implement generic If we don't found better solution, I think it is better just delete generic svd2rust/src/generate/register.rs Line 168 in 29129c0
with: self.bits = bits
|
I'd agree that it is a bit surprising at first that this works. I submitted the PR and went off to bed, but then had one of those moments lying in bed and thinking about it when I felt a sinking feeling that the fix would break everything. I got back up and did a bunch more testing to verify that nothing breaks. The key insight is that there's a deref coercion happening. Since A collection of resources I assembled while verifying that this was correct:
|
(As an aside, all this chicanery would be avoided with #478). |
See what problem I see: reg.write(|w| { w
.bits(10) // <-- DerefMut here
.field1().set_bit() // <-- error! generic W<REG> doesn't have `field1`
}); |
Ah, that's a fair point. Though it would be a fairly marginal use-case, wouldn't it? Setting the bits for the whole register explicitly and then overriding just one field? Is that example from real code somewhere? |
Oh, thanks @burrbull for bringing up the specialized version of svd2rust/src/generate/register.rs Lines 167 to 170 in 29129c0
In all the hubbub I had forgotten about it. That would certainly explain why in any normal code #475 didn't manifest as a bug, since the compiler will pick the impl directly on the specific type before even trying to deref. So #475 will only manifest in code written to be generic over To close the loop, your example at #477 (comment) will be fine, since |
I already saw something like this. On the other hand this should work: reg.write(|w| {
w.bits(10); // <-- DerefMut here, but drop ref
w.field1().set_bit()
}); Can you test this? |
Do you mean just that you've seen that pattern before or that it exhibited a bug? My current thinking is that there's no bug in that pattern, since the I've not been able to trigger #475 on master or any suspected bug from this PR in any testing (and it does seem like it would have to be both or neither, not one or the other). If you have an example of somewhere that has an issue, please point me to it. |
Ping @burrbull. I don't believe there's a bug in any code except my own. Happy to look at any counter-example that you might come up with. Are there any other outstanding issues with this PR? Thanks! |
@burrbull, have you been able to identify any issues with this change? To reiterate, I'm pretty confident that the only one affected by the bug is me. @ryankurte it looks like you're still the @rust-highfive reviewer here, would you by chance be able to take a look at this PR? Thanks! |
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.
thanks for the fix! i am not 100% across the related issue but, looks okay to me.
bors r+
Thanks for the reviews! |
Fixes #475.