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

rustdoc: fix doctests with non-feature crate attrs #38161

Merged
merged 1 commit into from
Feb 5, 2017

Conversation

durka
Copy link
Contributor

@durka durka commented Dec 4, 2016

Fixes #38129.

The book says that any top-level crate attributes at the beginning of a doctest are moved outside the generated fn main, but it was only checking for #![feature, not #![.

These attributes previously caused warnings but were then ignored, so in theory this could change the behavior of doctests in the wild.

@rust-highfive
Copy link
Collaborator

r? @steveklabnik

(rust_highfive has picked a reviewer for you, use r? to override)

@bluss bluss added the relnotes Marks issues that should be documented in the release notes of the next release. label Dec 4, 2016
@bluss
Copy link
Member

bluss commented Dec 4, 2016

This looks good to me, it's just a bugfix, or can it cause trouble?

@durka
Copy link
Contributor Author

durka commented Dec 4, 2016

@bluss since these attributes were "silently" ignored before, in theory a test like this

/// ```
/// #![no_std]
/// assert_eq!(1 + 1, 2);
/// ```
pub fn foo() {}

passed before but fails after this PR.

However it makes the code agree with what the book previously claimed.

@durka
Copy link
Contributor Author

durka commented Dec 4, 2016

Ha, I thought that was hypothetical but it was in the example for E0152. Fixing.

@durka
Copy link
Contributor Author

durka commented Dec 5, 2016

Ah crap, it also fails with multi-line attributes, i.e.

#![cfg_attr(unix,
            feature(foo)]

But code such as

#![feature(x,
           y)]

would have failed before as well.

Really, partition_source() needs to use the parser instead of a simple string substition.

@durka durka force-pushed the rustdoc-crate-attrs branch 2 times, most recently from aafc598 to 528c463 Compare December 5, 2016 06:24
@durka
Copy link
Contributor Author

durka commented Dec 5, 2016

I went for the easy solution: comment out the affected doctests and leave a FIXME.

@GuillaumeGomez
Copy link
Member

cc @alexcrichton

@alexcrichton
Copy link
Member

Hm it sounds like this is a breaking change? Could you elaborate on the precise breakage that's happening here and why you think it's acceptable to land anyway?

@durka
Copy link
Contributor Author

durka commented Dec 7, 2016

@alexcrichton

Well, I didn't really expect breakage until I found it in the docs of rust itself :)

It may be acceptable to land anyway because

  • The breakage happens because an attribute which the user intended to take effect was not taking effect (it prints a warning which is usually swallowed by the doctest runner).
  • It was definitely a bug before and this change brings the code in line with what the docs have always said.

Unfortunately I don't think we can do anything with doctests on crater. But we could try to do some clever grepping for doctests that would be affected.

Edit: and the alternative to breakage is to change the docs to say what the code does, and provide an example of how to put in a non-feature crate attribute that actually works.

@durka
Copy link
Contributor Author

durka commented Dec 9, 2016

Updated -- I learned from #38239 how to write the test without using run-make.

@alexcrichton
Copy link
Member

Hm I'm not personally comfortable with the breakage outlined, but others may have different opinions.

@steveklabnik
Copy link
Member

/cc @rust-lang/core wrt breakage

@aturon
Copy link
Member

aturon commented Dec 13, 2016

@alexcrichton

To be clear, AIUI, this PR is changing from silently ignoring attributes to actually using them (modulo parse problems). While this could in principle break a test, it seems like a very clear-cut bugfix to me, and personally I would want such tests to break. It's also trivial to fix the breakage: if you delete the attribute, it'll work precisely as it did before.

👍 from me.

@alexcrichton
Copy link
Member

@aturon in many cases though in the book it was intended for the attribute to show off example usage and shouldn't be removed. For example #![no_std] was accidentally not getting placed on the crate root but it's showing off the various no_std examples.

It's true though that there's always a way to write code which works across all versions here, so in that sense it could be fine to consider this a standard bugfix.

The rustdoc test generation at this point seems so janky though that any "bug fix" is inevitably going to break some examples...

@aturon
Copy link
Member

aturon commented Dec 21, 2016

@alexcrichton

in many cases though in the book it was intended for the attribute to show off example usage and shouldn't be removed. For example #![no_std] was accidentally not getting placed on the crate root but it's showing off the various no_std examples.

I'm having a hard time understanding what you're saying. Maybe I'm totally misunderstanding the change here, but I thought the attributes would appear in the docs (so would continue to "show off" the attribute) but would also start taking actual effect? In my mind, what we want is for the tested code and the code on the screen to be doing the same thing.

@bluss
Copy link
Member

bluss commented Dec 22, 2016

I'm for this as a bug fix. Similar to lint changes it can break your tests or CI, but not the crate itself.

@alexcrichton
Copy link
Member

@aturon to clarify you originally said:

It's also trivial to fix the breakage: if you delete the attribute, it'll work precisely as it did before.

I was mainly responding to that, I believe. The "fix" would defeat the purpose of the original documentation, so this wouldn't want to be something that we'd recommend to crate authors if they hit this breakage.

If we want to consider this a bug fix though and just swallow the breakage then that's ok with me. Authors can always tag examples with ignore to not actually compile anything.

@aturon
Copy link
Member

aturon commented Jan 4, 2017

@alexcrichton

I was mainly responding to that, I believe. The "fix" would defeat the purpose of the original documentation, so this wouldn't want to be something that we'd recommend to crate authors if they hit this breakage.

Got it. But yeah, I'm comfortable going forward here with the advice you mention.

@nikomatsakis
Copy link
Contributor

@brson can we use cargobomb to test for rustdoc tests? I believe so? It'd be nice to have data.

The typical policy for bugfixes like this is to attempt a warning period, though i'm not sure if that is feasible in this case. I feel also that this sounds like a bugfix, and as likely to fix things as to break them.

@steveklabnik
Copy link
Member

So, I am assigned this PR, but I don't know what to do with it. Who's making the call here?

@nikomatsakis
Copy link
Contributor

@steveklabnik seems like a tools team thing?

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Feb 4, 2017

📌 Commit ec356bb has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented Feb 5, 2017

⌛ Testing commit ec356bb with merge 4efb8ae...

bors added a commit that referenced this pull request Feb 5, 2017
rustdoc: fix doctests with non-feature crate attrs

Fixes #38129.

The book says that any top-level crate attributes at the beginning of a doctest are moved outside the generated `fn main`, but it was only checking for `#![feature`, not `#![`.

These attributes previously caused warnings but were then ignored, so in theory this could change the behavior of doctests in the wild.
@bors
Copy link
Contributor

bors commented Feb 5, 2017

💔 Test failed - status-travis

@alexcrichton
Copy link
Member

alexcrichton commented Feb 5, 2017 via email

@bors
Copy link
Contributor

bors commented Feb 5, 2017

⌛ Testing commit ec356bb with merge 696f5c1...

bors added a commit that referenced this pull request Feb 5, 2017
rustdoc: fix doctests with non-feature crate attrs

Fixes #38129.

The book says that any top-level crate attributes at the beginning of a doctest are moved outside the generated `fn main`, but it was only checking for `#![feature`, not `#![`.

These attributes previously caused warnings but were then ignored, so in theory this could change the behavior of doctests in the wild.
@bors
Copy link
Contributor

bors commented Feb 5, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing 696f5c1 to master...

@bors bors merged commit ec356bb into rust-lang:master Feb 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relnotes Marks issues that should be documented in the release notes of the next release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants