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

Deny warnings #47

merged 5 commits into from
Jan 4, 2017

Conversation

llogiq
Copy link
Contributor

@llogiq llogiq commented Dec 21, 2016

This fixes #46

@llogiq
Copy link
Contributor Author

llogiq commented Dec 21, 2016

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

Copy link
Contributor Author

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
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 avoid this language, it sounds kinda patronising to me

Copy link
Contributor Author

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
Copy link
Collaborator

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

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.

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.

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.

@llogiq
Copy link
Contributor Author

llogiq commented Dec 22, 2016

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.

@llogiq
Copy link
Contributor Author

llogiq commented Dec 22, 2016

Note to self: Perhaps I should link to the #[deprecate] docs, too.

@llogiq
Copy link
Contributor Author

llogiq commented Dec 26, 2016

Ok, now I think this is ready to merge. Thoughts?

Copy link
Collaborator

@lambda-fairy lambda-fairy left a 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)]
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.

unused-results)]
```

Note that we explicitly did not set the [deprecate attribute]
Copy link
Collaborator

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
Copy link
Collaborator

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

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 –
Copy link
Collaborator

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.
Copy link
Collaborator

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
Copy link
Collaborator

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)
Copy link
Collaborator

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

@llogiq
Copy link
Contributor Author

llogiq commented Dec 28, 2016

Thanks @lfairy for the thorough read-through. This is becoming quite good now.

@nrc @lfairy r?

@lambda-fairy
Copy link
Collaborator

Looks good to me! I'll wait for any comments from @nrc before merging.

@llogiq
Copy link
Contributor Author

llogiq commented Jan 3, 2017

@nrc ping?

@nrc
Copy link
Collaborator

nrc commented Jan 4, 2017

LGTM, thanks for the changes!

@nrc nrc merged commit 1cca042 into rust-unofficial:master Jan 4, 2017
@llogiq llogiq deleted the deny_warnings branch January 4, 2017 01:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

anti pattern: #![deny(warnings)]
3 participants