-
Notifications
You must be signed in to change notification settings - Fork 13.3k
make clean::Item::span
return Option
instead of dummy span
#100299
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#![feature(no_core, auto_traits, lang_items)] | ||
#![no_core] | ||
|
||
#[lang = "sized"] | ||
trait Sized {} | ||
|
||
pub auto trait Bar {} | ||
|
||
/// has span | ||
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=='has span')].span.begin" "[10, 0]" | ||
// @is - "$.index[*][?(@.docs=='has span')].span.end" "[12, 1]" | ||
pub struct Foo; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 emptyTokenStream
, 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.cc @camelid @jyn514 thoughts?
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