-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
make clean::Item::span
return Option
instead of dummy span
#100299
Conversation
Some changes occurred in src/librustdoc/clean/types.rs cc @camelid |
r? @notriddle (rust-highfive has picked a reviewer for you, use r? to override) |
This PR makes a half-spirited attempt to handle the other places where we were using Alternative approach to this would be to handle this fully in the rustdoc-json side, and not touch |
if span.is_dummy() { | ||
return None; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if there's any points at which we could get dummy spans from rustc itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure -- maybe from a really strange macro expansion?
My guess was that this was originally placed to deal with the auto-trait issue I am fixing here more systematically, but maybe it also addresses other sources of DUMMY_SP that I didn't consider... 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proc macros can generate items without spans, I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no such thing as "without span" I think? -- proc macros have a few choices of spans to associate with tokens, but I can't tell how you'd get a DUMMY_SP
out of a proc macro except during error recovery?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TokenStream doesn't actually require a span though, right? https://doc.rust-lang.org/proc_macro/struct.TokenStream.html#method.new
Only Ident requires a span. https://doc.rust-lang.org/proc_macro/enum.TokenTree.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jyn514 sure, but TokenTree
s have spans (and presumably need them to be created), and anyways you can't create a rustdoc item with an empty TokenStream
, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I guess so. I'm just really wary of changes here - if you're confident dummy spans are impossible I'd like to make that an assert instead of completely removing the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I can do that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, this failed in rollup because we tried to call rustdoc on an empty file in a cargo unit test.
Specifically, if the file contents are empty, then the span of the root module of the crate is gonna be a span that is exactly equal to DUMMY_SP
(because it goes from 0 to 0). So when we try to generate an href to the module sources, we trigger an assertion failure.
I think we should just remove this assertion I added. That is, if a DUMMY_SP
(or, in this case, a span that looks just like one) comes from rustc, we should be not doing anything special to it. I think this will generate a src link that points to the empty file, but I feel like that's the simpler and easier to understand behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really wish we had a way to collect metrics for rustdoc :(
but yeah removing the assertion makes sense to me, if someone reports a bug we can fix it
@rustbot author |
@rustbot modify labels: +A-rustdoc-json |
☔ The latest upstream changes (presumably #100426) made this pull request unmergeable. Please resolve the merge conflicts. |
96edb41
to
f5765ae
Compare
@bors r+ |
…triddle make `clean::Item::span` return `Option` instead of dummy span Fixes rust-lang#100283
…triddle make `clean::Item::span` return `Option` instead of dummy span Fixes rust-lang#100283
failed in #100449 (comment) @bors r- |
src/test/rustdoc-json/impls/auto.rs
Outdated
|
||
pub auto trait Bar {} | ||
|
||
// @has auto.json "$.index[*][?(@.kind=='impl')].span" null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test isn't that specific, as it only checks that their is an impl with an null span. A better one would check that the synthetic impl has a null span, and a real one has the correct span.
(Also, I need to document how the json testing infra works)
// @has auto.json "$.index[*][?(@.kind=='impl')].span" null | |
pub struct Foo; | |
/// hack | |
impl Foo { | |
pub fn baz(&self) {} | |
} | |
// Testing spans, so all tests below code | |
// @is auto.json "$.index[*][?(@.kind=='impl' && @.inner.synthetic==true)].span" null | |
// @is - "$.index[*][?(@.docs=='hack')].span.begin" "[12, 0]" | |
// @is - "$.index[*][?(@.docs=='hack')].span.end" "[14, 1]" |
f5765ae
to
8b1f0ad
Compare
Updated the JSON test. Thanks @aDotInTheVoid. @rustbot ready |
if span.is_dummy() { | ||
return None; | ||
} | ||
assert!(!span.inner().is_dummy()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still want to remove this assertion. @compiler-errors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whooops -- It's me, I am the dummy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
8b1f0ad
to
752b0e0
Compare
@bors r+ rollup |
…mpiler-errors Rollup of 8 pull requests Successful merges: - rust-lang#99646 (Only point out a single function parameter if we have a single arg incompatibility) - rust-lang#100299 (make `clean::Item::span` return `Option` instead of dummy span) - rust-lang#100335 (Rustdoc-Json: Add `Path` type for traits.) - rust-lang#100367 (Suggest the path separator when a dot is used on a trait) - rust-lang#100431 (Enum variant ctor inherits the stability of the enum variant) - rust-lang#100446 (Suggest removing a semicolon after impl/trait items) - rust-lang#100468 (Use an extensionless `x` script for non-Windows) - rust-lang#100479 (Argument type error improvements) Failed merges: - rust-lang#100483 (Point to generic or arg if it's the self type of unsatisfied projection predicate) r? `@ghost` `@rustbot` modify labels: rollup
Fixes #100283