-
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
Make Res::SelfTy
a struct variant and update docs
#93938
Conversation
Some changes occurred in cc @camelid Some changes occurred in src/tools/clippy. cc @rust-lang/clippy |
src/librustdoc/clean/utils.rs
Outdated
Res::SelfTy { trait_: Some(trait_def_id), alias_to: _ } => (trait_def_id, ItemType::Trait), | ||
// This is an inherent impl; it doesn't have its own page. | ||
Res::SelfTy(None, Some((impl_def_id, _))) => return impl_def_id, | ||
Res::SelfTy(None, None) | ||
Res::SelfTy { trait_: None, alias_to: Some((impl_def_id, _)) } => return impl_def_id, | ||
Res::SelfTy { trait_: None, alias_to: 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 am not familiar with rustdoc so am not sure if this is actually a bug but these comments seem wrong 😅
the trait_: Some(trait)
case is not just for trait definitions and is also there in impl Trait for Foo
blocks
the trait_: None, alias_to: Some(..)
is not just for inherent impls and is also there in struct defs (struct Foo(Box<Self>)
)
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.
If you can, please go ahead and update these comments so they're correct :)
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 think it makes sense to add a fixme to potentially change this to
Res::SelfTy { trait_: Some(trait_def_id), alias_to: None } => (trait_def_id, ItemType::Trait),
i think the mention of impl Send for [u8]
might be caused by this https://doc.rust-lang.org/nightly/std/marker/trait.Send.html#impl-Send-80
but i don't want to add functionality changes to rustdoc in this PR
This comment has been minimized.
This comment has been minimized.
/// The trait this `Self` is a generic arg for. | ||
trait_: Option<DefId>, | ||
/// The item introducing the `Self` type alias. Can be used in the `type_of` query | ||
/// to get the underlying type. Additionally whether the `Self` type is disallowed | ||
/// from mentioning generics (i.e. when used in an anonymous constant). | ||
alias_to: Option<(DefId, bool)>, |
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.
Thanks for naming these fields and improving the docs! I had a lot of trouble understanding this when I wrote the current version of the docs.
Why is alias_to
an Option
, though? When would it be 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.
inside of a trait def alias_to
is None
trait Foo {
fn foo() -> Self;
// `Res::SelfTy { trait_: Some(Foo), alias_to: 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.
Ah, makes sense, thanks :)
Could you add a comment about 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.
Oops, just realized this was already merged 😅
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 a comment about this if you look at the examples above the SelfTy
variant
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.
Thanks! That covers it.
src/librustdoc/clean/utils.rs
Outdated
Res::SelfTy { trait_: Some(trait_def_id), alias_to: _ } => (trait_def_id, ItemType::Trait), | ||
// This is an inherent impl; it doesn't have its own page. | ||
Res::SelfTy(None, Some((impl_def_id, _))) => return impl_def_id, | ||
Res::SelfTy(None, None) | ||
Res::SelfTy { trait_: None, alias_to: Some((impl_def_id, _)) } => return impl_def_id, | ||
Res::SelfTy { trait_: None, alias_to: 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.
If you can, please go ahead and update these comments so they're correct :)
after adding a fixme to rustdoc, r=me |
@bors r=lcnr |
📌 Commit 48a79bc has been approved by |
☀️ Test successful - checks-actions |
Finished benchmarking commit (b321742): comparison url. Summary: This benchmark run did not return any relevant results. If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression |
Make `Res::SelfTy` a struct variant and update docs I found pattern matching on a `(Option<DefId>, Option<(DefId, bool)>)` to not be super readable, additionally the doc comments on the types in a tuple variant aren't visible anywhere at use sites as far as I can tell (using rust analyzer + vscode) The docs incorrectly assumed that the `DefId` in `Option<(DefId, bool)>` would only ever be for an impl item and I also found the code examples to be somewhat unclear about which `DefId` was being talked about. r? `@lcnr` since you reviewed the last PR changing these docs
I found pattern matching on a
(Option<DefId>, Option<(DefId, bool)>)
to not be super readable, additionally the doc comments on the types in a tuple variant aren't visible anywhere at use sites as far as I can tell (using rust analyzer + vscode)The docs incorrectly assumed that the
DefId
inOption<(DefId, bool)>
would only ever be for an impl item and I also found the code examples to be somewhat unclear about whichDefId
was being talked about.r? @lcnr since you reviewed the last PR changing these docs