forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#132046 - lcnr:trivial-type-visitable, r=<try>
'improve' type traversal questionable :3 r? `@ghost`
- Loading branch information
Showing
39 changed files
with
647 additions
and
438 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,39 @@ | ||
use quote::quote; | ||
use syn::parse_quote; | ||
|
||
pub(super) fn noop_type_traversable_derive( | ||
mut s: synstructure::Structure<'_>, | ||
) -> proc_macro2::TokenStream { | ||
if let syn::Data::Union(_) = s.ast().data { | ||
panic!("cannot derive on union") | ||
} | ||
|
||
s.underscore_const(true); | ||
|
||
if !s.ast().generics.lifetimes().any(|lt| lt.lifetime.ident == "tcx") { | ||
s.add_impl_generic(parse_quote! { 'tcx }); | ||
} | ||
|
||
s.add_bounds(synstructure::AddBounds::None); | ||
let mut where_clauses = None; | ||
s.add_trait_bounds( | ||
&parse_quote!( | ||
::rustc_middle::ty::traverse::TypeTraversable< | ||
::rustc_middle::ty::TyCtxt<'tcx>, | ||
Kind = ::rustc_middle::ty::traverse::NoopTypeTraversal, | ||
> | ||
), | ||
&mut where_clauses, | ||
synstructure::AddBounds::Fields, | ||
); | ||
for pred in where_clauses.into_iter().flat_map(|c| c.predicates) { | ||
s.add_where_predicate(pred); | ||
} | ||
|
||
s.bound_impl( | ||
quote!(::rustc_middle::ty::traverse::TypeTraversable<::rustc_middle::ty::TyCtxt<'tcx>>), | ||
quote! { | ||
type Kind = ::rustc_middle::ty::traverse::NoopTypeTraversal; | ||
}, | ||
) | ||
} |
This file contains 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 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 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 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 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
Oops, something went wrong.