File tree Expand file tree Collapse file tree 2 files changed +30
-9
lines changed
crates/formality-macros/src Expand file tree Collapse file tree 2 files changed +30
-9
lines changed Original file line number Diff line number Diff line change 2
2
3
3
- [ Intro] ( ./intro.md )
4
4
- [ ` formality_core ` : the Formality system] ( ./formality_core.md )
5
- - [ Defining your lang] ( ./formality_core/lang.md )
6
- - [ Defining terms with the ` term ` macro] ( ./formality_core/terms.md )
7
- - [ Parsing] ( ./formality_core/parse.md )
8
- - [ Customizing debug] ( ./formality_core/debug.md )
9
- - [ Variables] ( ./formality_core/variables.md )
10
- - [ Collections] ( ./formality_core/collections.md )
11
- - [ Judgment functions and inference rules] ( ./formality_core/judgment_fn.md )
12
- - [ FAQ and troubleshooting] ( ./formality_core/faq.md )
5
+ - [ Defining your lang] ( ./formality_core/lang.md )
6
+ - [ Defining terms with the ` term ` macro] ( ./formality_core/terms.md )
7
+ - [ Parsing] ( ./formality_core/parse.md )
8
+ - [ Customizing debug] ( ./formality_core/debug.md )
9
+ - [ Constructors] ( ./formality_core/constructors.md )
10
+ - [ Variables] ( ./formality_core/variables.md )
11
+ - [ Collections] ( ./formality_core/collections.md )
12
+ - [ Judgment functions and inference rules] ( ./formality_core/judgment_fn.md )
13
+ - [ FAQ and troubleshooting] ( ./formality_core/faq.md )
Original file line number Diff line number Diff line change @@ -11,8 +11,9 @@ pub(crate) fn upcast_impls(s: synstructure::Structure) -> Vec<TokenStream> {
11
11
s. variants ( )
12
12
. iter ( )
13
13
. filter ( |v| num_variants == 1 || has_isa_attr ( v. ast ( ) . attrs ) )
14
- . map ( |v| upcast_to_variant ( & s, v) )
14
+ . map ( |v : & VariantInfo < ' _ > | upcast_to_variant ( & s, v) )
15
15
. chain ( Some ( self_upcast ( & s) ) )
16
+ . chain ( Some ( arc_upcast ( & s) ) )
16
17
. collect ( )
17
18
}
18
19
@@ -28,6 +29,25 @@ fn self_upcast(s: &synstructure::Structure) -> TokenStream {
28
29
} )
29
30
}
30
31
32
+ fn arc_upcast ( s : & synstructure:: Structure ) -> TokenStream {
33
+ let type_name = & s. ast ( ) . ident ;
34
+ let ( impl_generics, type_generics, where_clauses) = s. ast ( ) . generics . split_for_impl ( ) ;
35
+
36
+ quote_spanned ! { type_name. span( ) =>
37
+ const _: ( ) = {
38
+ use formality_core:: Upcast ;
39
+ use std:: sync:: Arc ;
40
+
41
+ impl #impl_generics Upcast <Arc <Self >> for #type_name #type_generics
42
+ #where_clauses {
43
+ fn upcast( self ) -> Arc <Self > {
44
+ Arc :: new( self )
45
+ }
46
+ }
47
+ } ;
48
+ }
49
+ }
50
+
31
51
fn upcast_to_variant ( s : & synstructure:: Structure , v : & VariantInfo ) -> TokenStream {
32
52
let binding_tys: Vec < & Type > = v. bindings ( ) . iter ( ) . map ( |b| & b. ast ( ) . ty ) . collect ( ) ;
33
53
let binding_names: Vec < & syn:: Ident > = v. bindings ( ) . iter ( ) . map ( |b| & b. binding ) . collect ( ) ;
You can’t perform that action at this time.
0 commit comments