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

make clean::Item::span return Option instead of dummy span #100299

Merged
merged 1 commit into from
Aug 14, 2022

Conversation

compiler-errors
Copy link
Member

Fixes #100283

@rustbot rustbot added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Aug 9, 2022
@rustbot
Copy link
Collaborator

rustbot commented Aug 9, 2022

Some changes occurred in src/librustdoc/clean/types.rs

cc @camelid

@rust-highfive
Copy link
Collaborator

r? @notriddle

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 9, 2022
@compiler-errors
Copy link
Member Author

compiler-errors commented Aug 9, 2022

This PR makes a half-spirited attempt to handle the other places where we were using clean::Span to now gracefully use Option<clean::Span>, but I'm open to feedback for any of those other usages.

Alternative approach to this would be to handle this fully in the rustdoc-json side, and not touch clean::Span

Comment on lines -308 to -310
if span.is_dummy() {
return None;
}
Copy link
Member

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?

Copy link
Member Author

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... 🤔

Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jyn514 sure, but TokenTrees have spans (and presumably need them to be created), and anyways you can't create a rustdoc item with an empty TokenStream, right?

Copy link
Member

@jyn514 jyn514 Aug 9, 2022

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.

Copy link
Member Author

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

Copy link
Member Author

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.

cc @camelid @jyn514 thoughts?

Copy link
Member

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

@compiler-errors
Copy link
Member Author

@rustbot author

@aDotInTheVoid
Copy link
Member

@rustbot modify labels: +A-rustdoc-json

@rustbot rustbot added the A-rustdoc-json Area: Rustdoc JSON backend label Aug 9, 2022
@bors
Copy link
Contributor

bors commented Aug 12, 2022

☔ The latest upstream changes (presumably #100426) made this pull request unmergeable. Please resolve the merge conflicts.

@notriddle
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Aug 12, 2022

📌 Commit f5765ae has been approved by notriddle

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 12, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Aug 12, 2022
…triddle

make `clean::Item::span` return `Option` instead of dummy span

Fixes rust-lang#100283
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Aug 12, 2022
…triddle

make `clean::Item::span` return `Option` instead of dummy span

Fixes rust-lang#100283
@Dylan-DPC
Copy link
Member

failed in #100449 (comment)

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 12, 2022

pub auto trait Bar {}

// @has auto.json "$.index[*][?(@.kind=='impl')].span" null
Copy link
Member

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)

Suggested change
// @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]"

@compiler-errors
Copy link
Member Author

Updated the JSON test. Thanks @aDotInTheVoid.

@rustbot ready

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Aug 13, 2022
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 13, 2022
if span.is_dummy() {
return None;
}
assert!(!span.inner().is_dummy());
Copy link
Contributor

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

Copy link
Member Author

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@notriddle
Copy link
Contributor

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Aug 13, 2022

📌 Commit 752b0e0 has been approved by notriddle

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 13, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 14, 2022
…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
@bors bors merged commit d496c4e into rust-lang:master Aug 14, 2022
@rustbot rustbot added this to the 1.65.0 milestone Aug 14, 2022
@compiler-errors compiler-errors deleted the issue-100283 branch August 11, 2023 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-json Area: Rustdoc JSON backend S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rustdoc-Json: Fake span given for auto trait impls
9 participants