@@ -7,15 +7,24 @@ use crate::traits::*;
7
7
use rustc:: mir:: mono:: MonoItem ;
8
8
9
9
pub trait MonoItemExt < ' a , ' tcx : ' a > {
10
- fn as_mono_item ( & self ) -> & MonoItem < ' tcx > ;
10
+ fn define < Bx : BuilderMethods < ' a , ' tcx > > ( & self , cx : & ' a Bx :: CodegenCx ) ;
11
+ fn predefine < Bx : BuilderMethods < ' a , ' tcx > > (
12
+ & self ,
13
+ cx : & ' a Bx :: CodegenCx ,
14
+ linkage : Linkage ,
15
+ visibility : Visibility
16
+ ) ;
17
+ fn to_raw_string ( & self ) -> String ;
18
+ }
11
19
20
+ impl < ' a , ' tcx : ' a > MonoItemExt < ' a , ' tcx > for MonoItem < ' tcx > {
12
21
fn define < Bx : BuilderMethods < ' a , ' tcx > > ( & self , cx : & ' a Bx :: CodegenCx ) {
13
22
debug ! ( "BEGIN IMPLEMENTING '{} ({})' in cgu {}" ,
14
- self . as_mono_item ( ) . to_string( cx. tcx( ) , true ) ,
15
- self . as_mono_item ( ) . to_raw_string( ) ,
23
+ self . to_string( cx. tcx( ) , true ) ,
24
+ self . to_raw_string( ) ,
16
25
cx. codegen_unit( ) . name( ) ) ;
17
26
18
- match * self . as_mono_item ( ) {
27
+ match * self {
19
28
MonoItem :: Static ( def_id) => {
20
29
cx. codegen_static ( def_id, cx. tcx ( ) . is_mutable_static ( def_id) ) ;
21
30
}
@@ -33,8 +42,8 @@ pub trait MonoItemExt<'a, 'tcx: 'a> {
33
42
}
34
43
35
44
debug ! ( "END IMPLEMENTING '{} ({})' in cgu {}" ,
36
- self . as_mono_item ( ) . to_string( cx. tcx( ) , true ) ,
37
- self . as_mono_item ( ) . to_raw_string( ) ,
45
+ self . to_string( cx. tcx( ) , true ) ,
46
+ self . to_raw_string( ) ,
38
47
cx. codegen_unit( ) . name( ) ) ;
39
48
}
40
49
@@ -45,15 +54,15 @@ pub trait MonoItemExt<'a, 'tcx: 'a> {
45
54
visibility : Visibility
46
55
) {
47
56
debug ! ( "BEGIN PREDEFINING '{} ({})' in cgu {}" ,
48
- self . as_mono_item ( ) . to_string( cx. tcx( ) , true ) ,
49
- self . as_mono_item ( ) . to_raw_string( ) ,
57
+ self . to_string( cx. tcx( ) , true ) ,
58
+ self . to_raw_string( ) ,
50
59
cx. codegen_unit( ) . name( ) ) ;
51
60
52
- let symbol_name = self . as_mono_item ( ) . symbol_name ( cx. tcx ( ) ) . as_str ( ) ;
61
+ let symbol_name = self . symbol_name ( cx. tcx ( ) ) . as_str ( ) ;
53
62
54
63
debug ! ( "symbol {}" , & symbol_name) ;
55
64
56
- match * self . as_mono_item ( ) {
65
+ match * self {
57
66
MonoItem :: Static ( def_id) => {
58
67
cx. predefine_static ( def_id, linkage, visibility, & symbol_name) ;
59
68
}
@@ -64,13 +73,13 @@ pub trait MonoItemExt<'a, 'tcx: 'a> {
64
73
}
65
74
66
75
debug ! ( "END PREDEFINING '{} ({})' in cgu {}" ,
67
- self . as_mono_item ( ) . to_string( cx. tcx( ) , true ) ,
68
- self . as_mono_item ( ) . to_raw_string( ) ,
76
+ self . to_string( cx. tcx( ) , true ) ,
77
+ self . to_raw_string( ) ,
69
78
cx. codegen_unit( ) . name( ) ) ;
70
79
}
71
80
72
81
fn to_raw_string ( & self ) -> String {
73
- match * self . as_mono_item ( ) {
82
+ match * self {
74
83
MonoItem :: Fn ( instance) => {
75
84
format ! ( "Fn({:?}, {})" ,
76
85
instance. def,
@@ -85,9 +94,3 @@ pub trait MonoItemExt<'a, 'tcx: 'a> {
85
94
}
86
95
}
87
96
}
88
-
89
- impl < ' a , ' tcx : ' a > MonoItemExt < ' a , ' tcx > for MonoItem < ' tcx > {
90
- fn as_mono_item ( & self ) -> & MonoItem < ' tcx > {
91
- self
92
- }
93
- }
0 commit comments