-
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
Separate out a hir::Impl
struct
#79322
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
a88a906
to
c417d8d
Compare
Another thing I noticed is that it's really common to match on |
This would be an excellent use case for rust-lang/rfcs#2593 ("Enum variant types"). |
I don't know. |
If it helps, it would also improve some rustdoc code, that was the original use case. |
This comment has been minimized.
This comment has been minimized.
Need second opinion. |
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 that Impl
had grown a lot of fields so this makes a lot of sense. I would take more opportunities to use the nested types destructuring to avoid using field access, but this is fine as is.
r=me.
src/librustdoc/visit_ast.rs
Outdated
hir::ItemKind::Impl(ref impl_) => { | ||
// Don't duplicate impls when inlining or if it's implementing a trait, we'll pick | ||
// them up regardless of where they're located. | ||
if !self.inlining && of_trait.is_none() { | ||
let items = | ||
items.iter().map(|item| self.cx.tcx.hir().impl_item(item.id)).collect(); | ||
if !self.inlining && impl_.of_trait.is_none() { | ||
let items = impl_ | ||
.items | ||
.iter() | ||
.map(|item| self.cx.tcx.hir().impl_item(item.id)) | ||
.collect(); | ||
let i = Impl { | ||
unsafety, | ||
polarity, | ||
defaultness, | ||
constness, | ||
generics, | ||
trait_: of_trait, | ||
for_: self_ty, | ||
unsafety: impl_.unsafety, | ||
polarity: impl_.polarity, | ||
defaultness: impl_.defaultness, | ||
constness: impl_.constness, | ||
generics: &impl_.generics, | ||
trait_: &impl_.of_trait, | ||
for_: &impl_.self_ty, |
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 that this bit would be slightly nicer by using destructuring as it was before by using hir::ItemKind::Impl(hir::Impl { .. }) =>
like you do in other places.
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 whole block of code disappeared when rebasing over #79312; the new changes are in https://github.com/rust-lang/rust/pull/79322/files#diff-384affc1b4190940f114f3fcebbf969e7e18657a71ef9001da6b223a036687d9R2037. I think you'll agree the new code is a lot nicer :)
c417d8d
to
925a48d
Compare
55083ce
to
485a980
Compare
I fixed the merge conflicts. @estebank could you take another look? This bitrots rather quickly. |
☔ The latest upstream changes (presumably #80253) made this pull request unmergeable. Please resolve the merge conflicts. Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels:
|
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 sorry about the delay. Please rebase and r=me.
self_ty: &'hir Ty<'hir>, | ||
items: &'hir [ImplItemRef<'hir>], | ||
}, | ||
Impl(Impl<'hir>), |
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 Box
ing this would have any perf benefits 👀
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 opened #80961 to find out :)
This makes it possible to pass the `Impl` directly to functions, instead of having to pass each of the many fields one at a time. It also simplifies matches in many cases.
@bors r=estebank rollup=iffy |
📌 Commit a8ff647 has been approved by |
☀️ Test successful - checks-actions |
This makes it possible to pass the
Impl
directly to functions, insteadof having to pass each of the many fields one at a time. It also
simplifies matches in many cases.
See
rustc_save_analysis::dump_visitor::process_impl
orrustdoc::clean::clean_impl
for a good example of how this makesimpl
s easier to work with.r? @petrochenkov maybe?