-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
9424739
to
a65d7ad
Compare
This looks good to me, it's just a bugfix, or can it cause trouble? |
@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. |
Ha, I thought that was hypothetical but it was in the example for E0152. Fixing. |
a65d7ad
to
b0e0bf0
Compare
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, |
aafc598
to
528c463
Compare
I went for the easy solution: comment out the affected doctests and leave a FIXME. |
528c463
to
9e5ba49
Compare
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? |
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
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. |
9e5ba49
to
ec356bb
Compare
Updated -- I learned from #38239 how to write the test without using run-make. |
Hm I'm not personally comfortable with the breakage outlined, but others may have different opinions. |
/cc @rust-lang/core wrt breakage |
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. |
@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 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... |
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. |
I'm for this as a bug fix. Similar to lint changes it can break your tests or CI, but not the crate itself. |
@aturon to clarify you originally said:
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 |
Got it. But yeah, I'm comfortable going forward here with the advice you mention. |
@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. |
So, I am assigned this PR, but I don't know what to do with it. Who's making the call here? |
@steveklabnik seems like a tools team thing? |
@bors: r+ |
📌 Commit ec356bb has been approved by |
⌛ Testing commit ec356bb with merge 4efb8ae... |
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.
💔 Test failed - status-travis |
… On Sat, Feb 4, 2017 at 9:35 PM, bors ***@***.***> wrote:
💔 Test failed - status-travis
<https://travis-ci.org/rust-lang/rust/builds/198476782>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#38161 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAD95ERvQ3nvPpBaw3So7wEh1JPNMN2jks5rZV-KgaJpZM4LDqkM>
.
|
⌛ Testing commit ec356bb with merge 696f5c1... |
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.
☀️ Test successful - status-appveyor, status-travis |
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.