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

Warnings caused by examples in libstd should fail the doc tests #18199

Closed
crumblingstatue opened this Issue Oct 20, 2014 · 3 comments

Comments

Projects
None yet
4 participants
@crumblingstatue
Copy link
Contributor

crumblingstatue commented Oct 20, 2014

Recently, an incorrect example was discovered in the libstd documentation.

In this case, the compiler gives a warning for unused results on the I/O operations.
The example should have checked these results, uncovering a bug, which is the file being opened in read-only mode when it was intended to be written to.

If warnings would fail the doc tests, this issue would have been caught automatically.

In case an example wants to explicitly allow "questionable" constructs, it can use the allow(lint) attribute.

@sfackler

This comment has been minimized.

Copy link
Member

sfackler commented Oct 20, 2014

We definitely want to allow some warnings, like dead_code, but it seems like adding a default #[deny(unused_result)] would be a good idea.

@crumblingstatue

This comment has been minimized.

Copy link
Contributor Author

crumblingstatue commented Oct 21, 2014

How about allowing dead_code (and perhaps some other things that are commonly valid for examples), and denying everything else by default?

@steveklabnik

This comment has been minimized.

Copy link
Member

steveklabnik commented Oct 27, 2014

The reason warnings weren't happening is that they were actually suppressed.

@steveklabnik steveklabnik removed the A-docs label Nov 25, 2014

@alexcrichton alexcrichton self-assigned this Apr 7, 2015

alexcrichton added a commit to alexcrichton/rust that referenced this issue Apr 8, 2015

rustdoc: Allowing specifying attrs for doctests
This adds support in rustdoc to blanket apply crate attributes to all doc tests
for a crate at once. The syntax for doing this is:

    #![doc(test(attr(...)))]

Each meta item in `...` will be applied to each doctest as a crate attribute.

cc rust-lang#18199

alexcrichton added a commit to alexcrichton/rust that referenced this issue Apr 8, 2015

std: Deny most warnings in doctests
Allow a few specific ones but otherwise this helps ensure that our examples are
squeaky clean!

Closes rust-lang#18199

alexcrichton added a commit to alexcrichton/rust that referenced this issue Apr 8, 2015

rustdoc: Allowing specifying attrs for doctests
This adds support in rustdoc to blanket apply crate attributes to all doc tests
for a crate at once. The syntax for doing this is:

    #![doc(test(attr(...)))]

Each meta item in `...` will be applied to each doctest as a crate attribute.

cc rust-lang#18199
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.