-
Notifications
You must be signed in to change notification settings - Fork 375
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
Deny warnings #47
Deny warnings #47
Conversation
Oops, somehow messed up the history. |
## Drawbacks | ||
|
||
Until, say, the language changes, and as part of the transition, a lint is | ||
introduced that `warn`s, and Boom! The code no longer builds. Or someone tries |
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 would phrase this in terms of the Rust language's back compat guarantees - we guarantee (mostly) that we won't break your code with new releases, however, that guarantee does not cover warnings, and thus by using deny(warnings)
you are opting out of backwards compatibility for your crate.
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've changed this to reflect your suggestion.
|
||
## Alternatives | ||
|
||
Our plucky developer hero should have used |
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 would avoid this language, it sounds kinda patronising to 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.
You're right. I was a bit aggressive because I've had to deal with so many crates doing this, just creating an obstacle for me to test clippy on their code...it's all good now 😄
|
||
- Type `rustc -W help` for a list of lints on your system. Also type | ||
`rustc --help` for a general list of options | ||
- [clippy] is a collection of lints for better Rust code |
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 wonder if it is worth being explicit and calling it 'rust-clippy' rather than just clippy, since the latter is technically something else (and probably TM etc. MS).
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.
Done.
Our plucky developer hero should have used | ||
`RUSTFLAGS="-D warnings" cargo build"` to build their crate, removing | ||
the need for the annotation in their code. | ||
|
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 would add some discussion around the fact that usually in Rust, we recommend using in-crate attributes rather than command line flags (several reasons for this, starting with ensuring consistent build experiences without needing a build script on top of Cargo or whatever). However, the advice here is an exception to that rule and maybe explain why it makes sense (which I guess comes down to, deny(warnings) whould be a personal part of the build experience, not something you force onto your clients).
It is probably worth stating the alternative of denying specific warnings as attributes which does not have the behaviour you describe.
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.
It is probably worth stating the alternative of denying specific warnings as attributes which does not have the behaviour you describe.
Is this true in general? Even when only specific warnings are chosen, the meanings of the warnings themselves can change over time. That was part of the motivation for rust-lang/rfcs#1193, after all.
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 would guess it would be 99% true. Warnings very rarely change their meaning. Though they might expand slightly, it is usually to cover edge cases and is unlikely to cause breakage. I expect that any problems this causes is more than outweighed by the benefits of catching errors earlier in the development process and without needing a custom script to run the builds. ISTM that the hazard of the lint case is another lint silently appearing and this approach does not have that problem.
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.
All right. I think the list of lints is now complete and usable.
ce1eeb9
to
b06eacd
Compare
I now rewrote most of the text, added a few allow lints for good measure and fixed history. @nrc Thank you for the useful comments. I'm now much happier with this PR. |
Note to self: Perhaps I should link to the |
Ok, now I think this is ready to merge. Thoughts? |
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.
Merry Christmas!
Now that Christmas is over, I finally have the chance to properly review your PR. Hope these comments are helpful.
unused-extern-crates, | ||
unused-import-braces, | ||
unused-qualifications, | ||
unused-results)] |
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'd add missing-debug-implementations
(and maybe missing-copy-implementations
, though that's perhaps more controversial).
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.
done.
unused-results)] | ||
``` | ||
|
||
Note that we explicitly did not set the [deprecate attribute] |
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.
Nit: there should be a period at the end of this sentence
## Description | ||
|
||
A well-intentioned crate author wants to ensure their code builds without | ||
warnings. So they annotate their crate root with |
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.
Reading the rendered view, it's not obvious that the next example finishes this sentence. I'd rather have this written out in full instead.
## Drawbacks | ||
|
||
By disallowing the compiler to build with warnings, a crate author opts out of | ||
Rust's famed stability. Sometimes new features or old misfeatures need a change |
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 would like an example of such a change -- any lint from the future-incompatible
group would be okay.
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.
added.
period before being turned to `deny`. Sometimes APIs get deprecated, so their | ||
use will emit a warning where before there was none. | ||
|
||
ALl this conspires to potentially break the build whenever something changes – |
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.
Nit: "ALl" should be "All"
|
||
ALl this conspires to potentially break the build whenever something changes – | ||
not only for the original developer, but also for those who wish to use their | ||
code. |
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 isn't true: Cargo passes --cap-lints
to rustc, which disables lints while building dependencies. See rust-lang/rfcs#1193.
|
||
## Alternatives | ||
|
||
luckily, there are two ways of tackling this problem: First, we can decouple |
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 think the word "luckily" should be removed. These articles tend to have a sparse writing style, which discourages extra words like this.
```RUSTFLAGS="-D warnings" cargo build"``` | ||
|
||
This can be done by any individual developer (or be set in a CI tool like | ||
travis, but remember that this may break the build when something changes) |
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.
Nit: "Travis" should be capitalized
Looks good to me! I'll wait for any comments from @nrc before merging. |
@nrc ping? |
LGTM, thanks for the changes! |
This fixes #46