Skip to content

Commit b9b64b1

Browse files
authored
Rollup merge of rust-lang#95761 - c410-f3r:meta-var-stuff, r=petrochenkov
Kickstart the inner usage of `macro_metavar_expr` There can be more use-cases but I am out of ideas. cc rust-lang#83527 r? `@petrochenkov`
2 parents feddbc5 + 3191d27 commit b9b64b1

File tree

4 files changed

+28
-120
lines changed

4 files changed

+28
-120
lines changed

compiler/rustc_expand/src/expand.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ macro_rules! ast_fragments {
8383
}
8484
match self {
8585
$($(AstFragment::$Kind(ast) => ast.extend(placeholders.iter().flat_map(|id| {
86-
// We are repeating through arguments with `many`, to do that we have to
87-
// mention some macro variable from those arguments even if it's not used.
88-
macro _repeating($flat_map_ast_elt) {}
86+
${ignore(flat_map_ast_elt)}
8987
placeholder(AstFragmentKind::$Kind, *id, None).$make_ast()
9088
})),)?)*
9189
_ => panic!("unexpected AST fragment kind")

compiler/rustc_expand/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1+
#![allow(rustc::potential_query_instability)]
12
#![feature(associated_type_bounds)]
23
#![feature(associated_type_defaults)]
34
#![feature(crate_visibility_modifier)]
45
#![feature(decl_macro)]
56
#![feature(if_let_guard)]
67
#![feature(let_chains)]
78
#![feature(let_else)]
9+
#![feature(macro_metavar_expr)]
810
#![feature(proc_macro_diagnostic)]
911
#![feature(proc_macro_internals)]
1012
#![feature(proc_macro_span)]
1113
#![feature(try_blocks)]
1214
#![recursion_limit = "256"]
13-
#![allow(rustc::potential_query_instability)]
1415

1516
#[macro_use]
1617
extern crate rustc_macros;

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@
181181
#![feature(intrinsics)]
182182
#![feature(lang_items)]
183183
#![feature(link_llvm_intrinsics)]
184+
#![feature(macro_metavar_expr)]
184185
#![feature(min_specialization)]
185186
#![feature(mixed_integer_ops)]
186187
#![feature(must_not_suspend)]

library/core/src/tuple.rs

+24-116
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,17 @@ use crate::cmp::*;
55

66
// macro for implementing n-ary tuple functions and operations
77
macro_rules! tuple_impls {
8-
($(
9-
$Tuple:ident {
10-
$(($idx:tt) -> $T:ident)+
11-
}
12-
)+) => {
8+
( $( $Tuple:ident( $( $T:ident )+ ) )+ ) => {
139
$(
1410
#[stable(feature = "rust1", since = "1.0.0")]
1511
impl<$($T:PartialEq),+> PartialEq for ($($T,)+) where last_type!($($T,)+): ?Sized {
1612
#[inline]
1713
fn eq(&self, other: &($($T,)+)) -> bool {
18-
$(self.$idx == other.$idx)&&+
14+
$( ${ignore(T)} self.${index()} == other.${index()} )&&+
1915
}
2016
#[inline]
2117
fn ne(&self, other: &($($T,)+)) -> bool {
22-
$(self.$idx != other.$idx)||+
18+
$( ${ignore(T)} self.${index()} != other.${index()} )||+
2319
}
2420
}
2521

@@ -28,34 +24,36 @@ macro_rules! tuple_impls {
2824

2925
#[stable(feature = "rust1", since = "1.0.0")]
3026
impl<$($T:PartialOrd + PartialEq),+> PartialOrd for ($($T,)+)
31-
where last_type!($($T,)+): ?Sized {
27+
where
28+
last_type!($($T,)+): ?Sized
29+
{
3230
#[inline]
3331
fn partial_cmp(&self, other: &($($T,)+)) -> Option<Ordering> {
34-
lexical_partial_cmp!($(self.$idx, other.$idx),+)
32+
lexical_partial_cmp!($( ${ignore(T)} self.${index()}, other.${index()} ),+)
3533
}
3634
#[inline]
3735
fn lt(&self, other: &($($T,)+)) -> bool {
38-
lexical_ord!(lt, $(self.$idx, other.$idx),+)
36+
lexical_ord!(lt, $( ${ignore(T)} self.${index()}, other.${index()} ),+)
3937
}
4038
#[inline]
4139
fn le(&self, other: &($($T,)+)) -> bool {
42-
lexical_ord!(le, $(self.$idx, other.$idx),+)
40+
lexical_ord!(le, $( ${ignore(T)} self.${index()}, other.${index()} ),+)
4341
}
4442
#[inline]
4543
fn ge(&self, other: &($($T,)+)) -> bool {
46-
lexical_ord!(ge, $(self.$idx, other.$idx),+)
44+
lexical_ord!(ge, $( ${ignore(T)} self.${index()}, other.${index()} ),+)
4745
}
4846
#[inline]
4947
fn gt(&self, other: &($($T,)+)) -> bool {
50-
lexical_ord!(gt, $(self.$idx, other.$idx),+)
48+
lexical_ord!(gt, $( ${ignore(T)} self.${index()}, other.${index()} ),+)
5149
}
5250
}
5351

5452
#[stable(feature = "rust1", since = "1.0.0")]
5553
impl<$($T:Ord),+> Ord for ($($T,)+) where last_type!($($T,)+): ?Sized {
5654
#[inline]
5755
fn cmp(&self, other: &($($T,)+)) -> Ordering {
58-
lexical_cmp!($(self.$idx, other.$idx),+)
56+
lexical_cmp!($( ${ignore(T)} self.${index()}, other.${index()} ),+)
5957
}
6058
}
6159

@@ -108,106 +106,16 @@ macro_rules! last_type {
108106
}
109107

110108
tuple_impls! {
111-
Tuple1 {
112-
(0) -> A
113-
}
114-
Tuple2 {
115-
(0) -> A
116-
(1) -> B
117-
}
118-
Tuple3 {
119-
(0) -> A
120-
(1) -> B
121-
(2) -> C
122-
}
123-
Tuple4 {
124-
(0) -> A
125-
(1) -> B
126-
(2) -> C
127-
(3) -> D
128-
}
129-
Tuple5 {
130-
(0) -> A
131-
(1) -> B
132-
(2) -> C
133-
(3) -> D
134-
(4) -> E
135-
}
136-
Tuple6 {
137-
(0) -> A
138-
(1) -> B
139-
(2) -> C
140-
(3) -> D
141-
(4) -> E
142-
(5) -> F
143-
}
144-
Tuple7 {
145-
(0) -> A
146-
(1) -> B
147-
(2) -> C
148-
(3) -> D
149-
(4) -> E
150-
(5) -> F
151-
(6) -> G
152-
}
153-
Tuple8 {
154-
(0) -> A
155-
(1) -> B
156-
(2) -> C
157-
(3) -> D
158-
(4) -> E
159-
(5) -> F
160-
(6) -> G
161-
(7) -> H
162-
}
163-
Tuple9 {
164-
(0) -> A
165-
(1) -> B
166-
(2) -> C
167-
(3) -> D
168-
(4) -> E
169-
(5) -> F
170-
(6) -> G
171-
(7) -> H
172-
(8) -> I
173-
}
174-
Tuple10 {
175-
(0) -> A
176-
(1) -> B
177-
(2) -> C
178-
(3) -> D
179-
(4) -> E
180-
(5) -> F
181-
(6) -> G
182-
(7) -> H
183-
(8) -> I
184-
(9) -> J
185-
}
186-
Tuple11 {
187-
(0) -> A
188-
(1) -> B
189-
(2) -> C
190-
(3) -> D
191-
(4) -> E
192-
(5) -> F
193-
(6) -> G
194-
(7) -> H
195-
(8) -> I
196-
(9) -> J
197-
(10) -> K
198-
}
199-
Tuple12 {
200-
(0) -> A
201-
(1) -> B
202-
(2) -> C
203-
(3) -> D
204-
(4) -> E
205-
(5) -> F
206-
(6) -> G
207-
(7) -> H
208-
(8) -> I
209-
(9) -> J
210-
(10) -> K
211-
(11) -> L
212-
}
109+
Tuple1(A)
110+
Tuple2(A B)
111+
Tuple3(A B C)
112+
Tuple4(A B C D)
113+
Tuple5(A B C D E)
114+
Tuple6(A B C D E F)
115+
Tuple7(A B C D E F G)
116+
Tuple8(A B C D E F G H)
117+
Tuple9(A B C D E F G H I)
118+
Tuple10(A B C D E F G H I J)
119+
Tuple11(A B C D E F G H I J K)
120+
Tuple12(A B C D E F G H I J K L)
213121
}

0 commit comments

Comments
 (0)