Skip to content

Commit

Permalink
Rollup merge of #111810 - compiler-errors:less-macro, r=thomcc
Browse files Browse the repository at this point in the history
Don't use inner macro in `marker_impls`

Just recurse instead of having to define an inner macro to avoid the problem with expansion binders being misnumbered between the `$meta` and `$T` variables.

cc `@Veykril` this should fix rust-lang/rust-analyzer#14862 since we've gotten rid of the inner macro.
  • Loading branch information
matthiaskrgr authored May 22, 2023
2 parents 3869b7b + e9a5a9d commit b0415db
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions library/core/src/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,17 @@ use crate::hash::Hasher;
/// ```
#[unstable(feature = "internal_impls_macro", issue = "none")]
macro marker_impls {
( $(#[$($meta:tt)*])* $Trait:ident for $( $({$($bounds:tt)*})? $T:ty ),+ $(,)?) => {
// This inner macro is needed because... idk macros are weird.
// It allows repeating `meta` on all impls.
#[unstable(feature = "internal_impls_macro", issue = "none")]
macro _impl {
( $$({$$($$bounds_:tt)*})? $$T_:ty ) => {
$(#[$($meta)*])* impl<$$($$($$bounds_)*)?> $Trait for $$T_ {}
}
}
$( _impl! { $({$($bounds)*})? $T } )+
( $(#[$($meta:tt)*])* $Trait:ident for $({$($bounds:tt)*})? $T:ty $(, $($rest:tt)*)? ) => {
$(#[$($meta)*])* impl< $($($bounds)*)? > $Trait for $T {}
marker_impls! { $(#[$($meta)*])* $Trait for $($($rest)*)? }
},
( $(#[$($meta:tt)*])* unsafe $Trait:ident for $( $({$($bounds:tt)*})? $T:ty ),+ $(,)?) => {
#[unstable(feature = "internal_impls_macro", issue = "none")]
macro _impl {
( $$({$$($$bounds_:tt)*})? $$T_:ty ) => {
$(#[$($meta)*])* unsafe impl<$$($$($$bounds_)*)?> $Trait for $$T_ {}
}
}
( $(#[$($meta:tt)*])* $Trait:ident for ) => {},

$( _impl! { $({$($bounds)*})? $T } )+
( $(#[$($meta:tt)*])* unsafe $Trait:ident for $({$($bounds:tt)*})? $T:ty $(, $($rest:tt)*)? ) => {
$(#[$($meta)*])* unsafe impl< $($($bounds)*)? > $Trait for $T {}
marker_impls! { $(#[$($meta)*])* unsafe $Trait for $($($rest)*)? }
},
( $(#[$($meta:tt)*])* unsafe $Trait:ident for ) => {},
}

/// Types that can be transferred across thread boundaries.
Expand Down

0 comments on commit b0415db

Please sign in to comment.