Skip to content
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

Merged
merged 5 commits into from
Jan 4, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
incorporated hints from lfairy
  • Loading branch information
llogiq committed Dec 27, 2016
commit f08e132761c379bd466c19c797d0b8d132363cef
33 changes: 21 additions & 12 deletions anti_patterns/deny-warnings.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Description

A well-intentioned crate author wants to ensure their code builds without
warnings. So they annotate their crate root with
warnings. So they annotate their crate root with the following:

## Example

Expand All @@ -22,28 +22,33 @@ It is short and will stop the build if anything is amiss.
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
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added.

in how things are done, thus lints are written that `warn` for a certain grace
period before being turned to `deny`. Sometimes APIs get deprecated, so their
use will emit a warning where before there was none.
period before being turned to `deny`.

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.
For example, it was discovered that a type could have two `impl`s with the same
method. This was deemed a bad idea, but in order to make the transition smooth,
the `overlapping-inherent-impls` lint was introduced to give a warning to those
stumbling on this fact, before it becomes a hard error in a future release.

Also 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.

Furthermore, crates that supply additional lints (e.g. [rust-clippy]) can no
longer be used unless the annotation is removed.

## Alternatives

luckily, there are two ways of tackling this problem: First, we can decouple
the build setting from the code, and second, we can name the lints we want to
deny explicitly.
There are two ways of tackling this problem: First, we can decouple the build
setting from the code, and second, we can name the lints we want to deny
explicitly.

The following command line will build with all warnings set to `deny`:

```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)
Travis, but remember that this may break the build when something changes)
without requiring a change to the code.

Alternatively, we can specify the lints that we want to `deny` in the code.
Expand Down Expand Up @@ -79,7 +84,8 @@ Here is a list of warning lints that is (hopefully) safe to deny:
In addition, the following `allow`ed lints may be a good idea to `deny`:

```rust
#[deny(missing-docs,
#[deny(missing-debug-implementations,
missing-docs,
trivial-casts,
trivial-numeric-casts,
unused-extern-crates,
Expand All @@ -88,7 +94,10 @@ In addition, the following `allow`ed lints may be a good idea to `deny`:
unused-results)]
Copy link
Collaborator

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

```

Note that we explicitly did not set the [deprecate attribute]
Some may also want to add `missing-copy-implementations` to their list.

Note that we explicitly did not add the `deprecated` lint, as it is fairly
certain that there will be more deprecated APIs in the future.

Copy link
Collaborator

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.

Copy link
Collaborator

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.

Copy link
Collaborator

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.

Copy link
Contributor Author

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.

## See also

Expand Down