File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,18 @@ fn main() {
18
18
GenericLabel :: <f64 >:: One . as_label( ) ,
19
19
GenericLabel :: <char >:: One . as_label( ) ,
20
20
) ;
21
+
22
+ assert_eq ! ( format!( "{:?}" , UnitLabel . as_label( ) ) , "UnitLabel" ) ;
23
+ assert_eq ! ( format!( "{:?}" , WeirdLabel ( 1 ) . as_label( ) ) , "WeirdLabel" ) ;
24
+ assert_eq ! ( format!( "{:?}" , WeirdLabel ( 2 ) . as_label( ) ) , "WeirdLabel" ) ;
25
+ assert_eq ! (
26
+ format!( "{:?}" , GenericLabel :: <f64 >:: One . as_label( ) ) ,
27
+ "GenericLabel::One::<f64>"
28
+ ) ;
29
+ assert_eq ! (
30
+ format!( "{:?}" , ConstGenericLabel :: <21 >. as_label( ) ) ,
31
+ "ConstGenericLabel::<21>"
32
+ ) ;
21
33
}
22
34
23
35
#[ derive( SystemLabel ) ]
@@ -40,6 +52,9 @@ pub enum GenericLabel<T> {
40
52
Two ( PhantomData < T > ) ,
41
53
}
42
54
55
+ #[ derive( SystemLabel ) ]
56
+ pub struct ConstGenericLabel < const N : usize > ;
57
+
43
58
// FIXME: this should be a compile_fail test
44
59
/*#[derive(SystemLabel)]
45
60
pub union Foo {
Original file line number Diff line number Diff line change @@ -271,14 +271,33 @@ fn derive_named_label(
271
271
}
272
272
} ;
273
273
274
+ // Formatting for generics
275
+ let generics = input. generics . params . iter ( ) ;
276
+ let fmt_generics = generics
277
+ . filter_map ( |p| match p {
278
+ syn:: GenericParam :: Type ( ty) => Some ( {
279
+ let ident = & ty. ident ;
280
+ quote ! { write!( f, "{}" , :: std:: any:: type_name:: <#ident>( ) ) }
281
+ } ) ,
282
+ syn:: GenericParam :: Const ( c) => Some ( {
283
+ let ident = & c. ident ;
284
+ quote ! { write!( f, "{:?}" , { #ident } ) }
285
+ } ) ,
286
+ _ => None ,
287
+ } )
288
+ . reduce ( |a, b| quote ! { #a?; write!( f, ", " ) ?; #b } )
289
+ . map ( |x| quote ! { write!( f, "::<" ) ?; #x?; write!( f, ">" ) ?; } ) ;
290
+
274
291
Ok ( quote ! {
275
292
impl #impl_generics #trait_path for #ident #ty_generics #where_clause {
276
293
#[ inline]
277
294
fn data( & self ) -> u64 {
278
295
#data
279
296
}
280
297
fn fmt( data: u64 , f: & mut :: std:: fmt:: Formatter ) -> :: std:: fmt:: Result {
281
- #fmt
298
+ #fmt?;
299
+ #fmt_generics
300
+ Ok ( ( ) )
282
301
}
283
302
}
284
303
} )
You can’t perform that action at this time.
0 commit comments