-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Derive TypeFoldable using a proc-macro #66384
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
Conversation
r? @eddyb (rust_highfive has picked a reviewer for you, use r? to override) |
src/librustc/ty/context.rs
Outdated
@@ -307,7 +307,8 @@ pub struct ResolvedOpaqueTy<'tcx> { | |||
/// | |||
/// Here, we would store the type `T`, the span of the value `x`, and the "scope-span" for | |||
/// the scope that contains `x`. | |||
#[derive(RustcEncodable, RustcDecodable, Clone, Debug, Eq, Hash, HashStable, PartialEq)] | |||
#[derive(RustcEncodable, RustcDecodable, Clone, Debug, Eq, Hash, HashStable, PartialEq, | |||
TypeFoldable)] |
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.
Maybe we should have two #[derive(...)]
attributes, one for the standard derives and one for the rustc-specific derives?
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.
LGTM, really nice! cc @rust-lang/compiler Anyone see any reason not to do this?
Maybe we could handle those by having |
This is awesome. We should definitely do this. |
I changed the formatting of the derives. If you don't mind, I would like to keep the Clone-based implementations for another PR. |
@cjgillot It's a good idea to keep PR small anyway. Moving |
} | ||
}; | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! EnumTypeFoldableImpl { |
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.
Is this still used?
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.
It is still used to implement TypeFoldable
for types defined in librustc's dependencies.
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... maybe we should keep the other macros too then since they could also be used for 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.
I wonder if we should just use the derives for all librustc*
and libsyntax*
crates, even if they don't are/depend on librustc
.
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.
@eddyb As in, add a generic Fold
trait for librustc dependencies? That seems maybe too complex. I'm not sure there's many uses of this macro left.
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.
Oh, right, sorry. What I said makes sense for HashStable
but not as much this.
@bors r+ |
📌 Commit cb46c35 has been approved by |
Derive TypeFoldable using a proc-macro A new proc macro is added in librustc_macros. It is used to derive TypeFoldable inside librustc and librustc_traits. For now, the macro uses the `'tcx` lifetime implicitly, and does not allow for a more robust selection of the adequate lifetime. The Clone-based TypeFoldable implementations are not migrated. Closes #65674
☀️ Test successful - checks-azure |
A new proc macro is added in librustc_macros.
It is used to derive TypeFoldable inside librustc and librustc_traits.
For now, the macro uses the
'tcx
lifetime implicitly, and does not allow for a more robust selection of the adequate lifetime.The Clone-based TypeFoldable implementations are not migrated.
Closes #65674