-
Notifications
You must be signed in to change notification settings - Fork 61
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
Improve errors for misused attributes #109
Improve errors for misused attributes #109
Conversation
Yep, there’s “phases” of compilation where we can’t continue. My hope is basically to make those phases as few and large as possible, but there will always be some case where it just doesn’t work.
I don’t know that there’s an actual way to generate warnings, either…
I’m sorry that I forgot to mention this! Take a look at the compile-fail tests. These assert that the error messages continue to work, and I strongly agree that we should have tests for each of the new errors. I don’t know yet if “more errors in one file” or “more files” is a better approach. Probably more files, but I have a feeling that will be slower in CI at some point. For now, I’d suggest creating at least one new file for these errors. You’ll want to rebase on master to get the fixes to these tests (causing your CI failure)
This is where warnings would be nice. They could be warnings for the current semver release, and made into errors for the next breaking change. Since we are still pre-1.0, I don’t mind bumping the version early and often, so I’d probably move to 0.5 after this is merged if we can’t figure out warnings. If it was already 1.0, I’d be more torn about a major bump for such a thing, as it was code that wasn’t working the way people intended anyway. |
Ah, thanks! Hopefully I can add these tonight.
Would it help if I add commits for the update? It looks like it'd be Or, that could wait until we have more research on warning capabilities. |
Thank you, but that’s all right! I’m lazy and don’t keep the changelog up-to-date with each PR, only doing it when I do a release. It does provide a good opportunity to review the changes and make sure that nothing obvious is missing or untested.
Feel free to suggest some text that you’d like to see as a seed for what will end up here! |
02ae59f
to
da2d4ac
Compare
Thanks for all your guidance @shepmaster! I marked this as ready for review, since I think I've addressed your concerns, at least for an initial implementation. |
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.
There’s one place where I was lazy and didn’t put the “report this” text:
Lines 147 to 151 in da2d4ac
let default_visibility = attributes_from_syn(attrs)? | |
.into_iter() | |
.flat_map(SnafuAttribute::into_visibility) | |
.next() | |
.unwrap_or_else(private_visibility); |
Can you expand that code to also report the attributes?
To make sure I understand this - you mean changing from this functional style to a loop that checks all of the attributes from |
Yep. I don’t see an obvious way, but if you see something that’s a bit more functional-style, feel free to go for it! |
da2d4ac
to
2f16731
Compare
3f2637b
to
149b6cc
Compare
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 all seems great; thanks so much for putting up with all my pedantry!
Is there anything else you think we need to add or discuss before merging?
Your knowledge and guidance are invaluable to the community. I'm thankful to have been able to take advantage, while helping a project I love. It inspires me to find other ways to contribute. So, thank you!
I don't think so. I agree with you that the spans the new errors point to aren't ideal, but it would require a bit more wide-reaching changes that aren't strictly related, so I think it should be a separate issue. I do think this change sets it up for success with how it accepts/stores spans, but the right ones need to be made available. Do you agree that should be another issue? I can make it if so. |
c5d79ec
to
b4c4d72
Compare
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.
Sorry for the long radio silence — I was away for work. I re-read some of the error text and it seems like a few errors got mixed up; am I losing it?
compatibility-tests/compile-fail/tests/ui/attribute-duplication.stderr
Outdated
Show resolved
Hide resolved
compatibility-tests/compile-fail/tests/ui/attribute-duplication.stderr
Outdated
Show resolved
Hide resolved
compatibility-tests/compile-fail/tests/ui/attribute-duplication.stderr
Outdated
Show resolved
Hide resolved
compatibility-tests/compile-fail/tests/ui/attribute-duplication.stderr
Outdated
Show resolved
Hide resolved
compatibility-tests/compile-fail/tests/ui/attribute-duplication.stderr
Outdated
Show resolved
Hide resolved
b4c4d72
to
6cb4381
Compare
Nope! I didn't have the right context in a few spots. I've cleaned those up (easy to do by adding a context While doing this, I found a couple more cases of duplication I'm not catching yet, which I think I can fix fairly quickly with the same tools:
|
Thanks for the last push! Everything looks good to me now; are there any outstanding issues (other than trying to find better things to point to) we should address before merging and releasing? |
There are a couple more cases of duplication that I mentioned in #109 (comment) -- they're a little harder to fix than I initially expected, but if you're not worried about those, or you'd like them done in a separate change, then no blockers that I know of. I was assuming you'd like those now, because technically it'd be another breaking change. :) |
Oh, I assumed that they were part of your last force push. I'm in no hurry, I just don't want to forget about this PR (something I unfortunately have a tendency to do). Please feel free to poke me when you have a chance to cycle back to those last few. Feel free to ask questions if you think it's something I can help with! |
I'd like to clarify whether some combinations of attributes should be errors, to be sure I'm not going to change behavior.
Separate from those, I think there are a couple more cases to clean up regardless:
As for why it's more challenging than anticipated, aside from the above, it's the interplay between |
I could go either way on these.
This is interesting. I wonder if we should have made it such that Do you think that this would be confusing to end users?
Sounds reasonable. I think you'd use the |
That makes sense to me, I'll make sure this still works.
That makes sense and it's easy to do, I'll add that.
Ok, I'll make this an error.
That's a good idea. Any I think I could do this. (It'd be a third commit, of course.) |
Sure. If at any point you think that this PR is getting too big, I definitely don't mind merging and creating some new issues / PRs to iterate. |
I think the If you're not worried about that, then all that would remain for this PR is preventing |
We can merge this but not immediately release anything; bundling up the breaking changes. If we need to release a patch version, I can always fork from before these commits. |
Ok! I was being perhaps overly cautious. To recap, here's the remaining work that I think could fit in this PR:
These could be other PRs, and I'll make issues for them:
|
6cb4381
to
2750426
Compare
I've addressed the remaining work for this PR:
compile-fail tests were added for both. If you like the approach I took, I think this PR is ready for merging. With the restructuring, making |
Hmm. Rust 1.18 fails with a lifetime issue: https://github.com/shepmaster/snafu/pull/109/checks?check_run_id=176857626 I'm not sure offhand what changed between Rust 1.18 and 1.30 that allows this slice to be considered static: https://github.com/shepmaster/snafu/compare/6cb438122453631443eb361840d9499768a9d54a..27504266fd1b266e101b22de103881e84af0a01c#diff-89e1fad4d2637dae0904dce6aba08394R487 @shepmaster - assuming you're OK with this general approach, would you recommend |
I just learned about |
I think it might be this change: rust-lang/rust#38865 |
Nice!
Makes sense 😉
Yeah, it'd be the automatic promotion of literals to statics, as you linked.
You can do the promotion by hand: static FOO: &[&str] = &["source(false)", "source(from)"]; attributes: FOO,
There's actually a "rust-toolchain" file in that directory, so you can just do
That would probably be a good thing! |
Not at all; that's the point of CI - to catch the things that we forget. That's why I try to be pedantic about adding new tests so frequently. I don't want to have to think about exactly what to remember! It is useful to check in 1.18 locally only because it's comparatively so different to current Rust that a lot of little things sneak in while developing. My biggest mistake is around match ergonomics. |
2750426
to
b8e438b
Compare
Thanks, that worked! I just pushed that fix, and hopefully this is everything we need to get this first PR merged.
That's good to know! The other piece that was missing for me is understanding that Do you know if there's a way to run those locally without a lot of copy+paste? I couldn't find any resources for replicating Cirrus CI locally. I see they have an issue for making a CLI (cirruslabs/cirrus-ci-docs#108) but didn't see anything else. |
Nothing I'm aware of. However, it's been pretty standard practice in my other crates to actually have most of the CI-related junk as separate shell scripts so that they are at least easier to access outside of CI (and you get syntax highlighting, etc.) In this case, I wonder if we should just move those to the respective Cargo.toml files... |
Either of these sound like they would be pretty helpful. I can create an issue if you like?
Thanks again for the library, and for your great feedback here! I hope to keep contributing. |
Ah, you already did #128! Wow! |
Fixes #105.
The first commit directly addresses the discussion in #105 by adding errors for cases of attribute misuse that were known to be wrong but didn't yet have errors. Previously, the derive would just continue without the effect the user was trying to request.
The second commit addresses similar comments elsewhere in the file that suggested we warn if attributes are duplicated. This wasn't discussed in #105 but seemed closely related.
Testing done:
Existing unit/doc tests still pass, and I added compile-fail tests to exercise each of the new error cases.