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 Res::SelfTy a struct variant and update docs #93938

Merged
merged 4 commits into from
Feb 14, 2022

Conversation

BoxyUwU
Copy link
Member

@BoxyUwU BoxyUwU commented Feb 12, 2022

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

@rust-highfive
Copy link
Collaborator

Some changes occurred in clean/types.rs.

cc @camelid

Some changes occurred in src/tools/clippy.

cc @rust-lang/clippy

@rustbot rustbot added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Feb 12, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 12, 2022
Comment on lines 401 to 404
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 }
Copy link
Member Author

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>))

Copy link
Member

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 :)

Copy link
Contributor

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

@rust-log-analyzer

This comment has been minimized.

Comment on lines +323 to +328
/// 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)>,
Copy link
Member

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?

Copy link
Member Author

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 }`
}

Copy link
Member

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?

Copy link
Member

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 😅

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 a comment about this if you look at the examples above the SelfTy variant

Copy link
Member

@camelid camelid Feb 17, 2022

Choose a reason for hiding this comment

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

Thanks! That covers it.

Comment on lines 401 to 404
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 }
Copy link
Member

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 :)

@lcnr
Copy link
Contributor

lcnr commented Feb 14, 2022

after adding a fixme to rustdoc, r=me

@BoxyUwU
Copy link
Member Author

BoxyUwU commented Feb 14, 2022

@bors r=lcnr

@bors
Copy link
Contributor

bors commented Feb 14, 2022

📌 Commit 48a79bc has been approved by lcnr

@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 Feb 14, 2022
@bors
Copy link
Contributor

bors commented Feb 14, 2022

⌛ Testing commit 48a79bc with merge b321742...

@bors
Copy link
Contributor

bors commented Feb 14, 2022

☀️ Test successful - checks-actions
Approved by: lcnr
Pushing b321742 to master...

@rust-timer
Copy link
Collaborator

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

flip1995 pushed a commit to flip1995/rust that referenced this pull request Feb 24, 2022
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
dario23 added a commit to dario23/rust-semverver that referenced this pull request May 4, 2022
dario23 added a commit to dario23/rust-semverver that referenced this pull request May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. 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.

8 participants