Uh oh!
There was an error while loading. Please reload this page.
rustdoc: inject #[macro_use] extern crate in doctests for macros - #33511
rustdoc: inject #[macro_use] extern crate in doctests for macros#33511birkenfeld wants to merge 1 commit into
#[macro_use] extern crate in doctests for macros#33511Conversation
rust-highfive
commented
May 9, 2016
(rust_highfive has picked a reviewer for you, use r? to override) |
alexcrichton
commented
May 9, 2016
Thanks! Could you elaborate a bit on why the added test wouldn't work? What did the error message look like? Also, perhaps macros could always be imported? I could imagine a doctest for a normal function may also want to use the crate's macros as it's part of the API |
birkenfeld
commented
May 9, 2016
The external crate isn't found. This is not specific to the macro issue, but apparently there was no need for such a test yet (all test cases that use
That can be done as well; this was the more backwards compatible option (although I admit that the breakage is pretty hard to imagine). Should the "does it contain the crate name" check be removed too then? |
alexcrichton
commented
May 9, 2016
Oh this is actually a case where the test harness isn't quite up to the task. Right now it only runs I'd leave in the crate name check for now, although in retrospect we probably should have just always added it. I suspect though that the addition of |
I think Either way, please also update the docs here which explain how test code gets wrapped in |
birkenfeld
commented
May 9, 2016
@durka good point, done. |
There was a problem hiding this comment.
#[macro_use] is also mentioned in the paragraph below, and in the section "Documenting macros" -- both obsolete with this PR I believe.
There was a problem hiding this comment.
You seem to be ignoring this advice in this very file with the second commit...
There was a problem hiding this comment.
That wasn't supposed to be part of this PR anyway.
steveklabnik
commented
May 9, 2016
Yeah, I would be a fan of doing this. |
alexcrichton
commented
May 10, 2016
All looks good to me, thanks @birkenfeld! |
durka
commented
May 10, 2016
Was there a resolution on whether macros should be imported when documenting a non-macro item? |
durka
commented
May 10, 2016
(If not, and this stays r+ed, I'll open a followup PR after this is merged so we can discuss there.) |
alexcrichton
commented
May 10, 2016
@durka for backwards compatibility we may not be able to do that, although in retrospect we should always have injected |
durka
commented
May 10, 2016
I don't see how adding |
alexcrichton
commented
May 10, 2016
These tests are pretty fragile as they're syntactically creating a program, and if we didn't previously inject |
If we're really worried about backcompat here and the justification for this PR as implemented is only that it won't affect a large number of tests... I think we shouldn't change it at all, unfortunately. I'm not convinced that complicating the test runner is worth it. Yes, it works great in simple cases. But as soon as you get a weird resolve error and you have to comb through the docs trying to understand how it mangles the doctests, it backfires. If you're testing a non-macro item and you want to use crate macros, now you need to add the manual |
alexcrichton
commented
May 10, 2016
@bors: r- Ok, let's see what others think. cc @rust-lang/tools |
durka
commented
May 10, 2016
Sorry for being difficult :( I remember being really frustrated when first learning how to document macros. This makes it easier, but harder to discover the fix when it breaks (which I believe it will, in crates that mix macro and non-macro items). So I'm torn. |
bors
commented
May 19, 2016
☔ The latest upstream changes (presumably #33742) made this pull request unmergeable. Please resolve the merge conflicts. |
steveklabnik
commented
Jun 6, 2016
alexcrichton
commented
Jun 7, 2016
@durka ok, thinking more on this, I don't think I really see a reason to not land this. The way doc-blocks are tested is already voodoo, so that's not really the issue at hand here. Do you have a concrete use case where this goes awry? I think that this is fully backwards-compatible otherwise. |
I'm fine with it landing. Just two things:
|
alexcrichton
commented
Jun 8, 2016
Yeah this perhaps could happen, but there's no way that would actually work out well in practice (the macro/crate would be unusable anyway), so I doubt that's actually happening anywhere. I couldn't actually think of any backcompat hazard, which is why I think it's ok to land this. |
durka
commented
Jun 8, 2016
But then why don't we put |
alexcrichton
commented
Jun 9, 2016
As I commented before
There's also nothing to get around here, all this patch does is inject |
durka
commented
Jun 9, 2016
The case where you still need to "get around" the voodoo is if you are not doctesting a macro but you do want to invoke a macro. |
durka
commented
Jun 9, 2016
Again I'm sorry to be a stick in the mud here but I don't want this to get any harder to figure out than it already is. Just now coaching a user on IRC who was frustrated with doctests to the point of not wanting to mark them as code. |
alexcrichton
commented
Jun 20, 2016
@birkenfeld do you want to rebase this and perhaps exclude the check for |
alexcrichton
commented
Jul 19, 2016
Closing due to inactivity, but feel free to resubmit with a rebase! |
Fixes: #29286
Note: I tried to add a test to
src/test/rustdoc, but the way in which these tests are called doesn't seem to allowextern crate testname;to work at all...