@@ -24,6 +24,7 @@ use llvm;
24
24
use monomorphize:: Instance ;
25
25
use type_of:: LayoutLlvmExt ;
26
26
use rustc:: hir;
27
+ use rustc:: hir:: def:: Def ;
27
28
use rustc:: hir:: def_id:: DefId ;
28
29
use rustc:: mir:: mono:: { Linkage , Visibility } ;
29
30
use rustc:: ty:: TypeFoldable ;
@@ -46,24 +47,23 @@ pub trait MonoItemExt<'a, 'tcx>: fmt::Debug + BaseMonoItemExt<'a, 'tcx> {
46
47
match * self . as_mono_item ( ) {
47
48
MonoItem :: Static ( def_id) => {
48
49
let tcx = cx. tcx ;
49
- let node_id = match tcx. hir . as_local_node_id ( def_id) {
50
- Some ( node_id) => node_id,
50
+ let is_mutable = match tcx. describe_def ( def_id) {
51
+ Some ( Def :: Static ( _, is_mutable) ) => is_mutable,
52
+ Some ( other) => {
53
+ bug ! ( "Expected Def::Static, found {:?}" , other)
54
+ }
51
55
None => {
52
- bug ! ( "MonoItemExt::define() called for non-local \
53
- static `{:?}`.", def_id)
56
+ bug ! ( "Expected Def::Static for {:?}, found nothing" , def_id)
57
+ }
58
+ } ;
59
+ let attrs = tcx. get_attrs ( def_id) ;
60
+
61
+ match consts:: trans_static ( & cx, def_id, is_mutable, & attrs) {
62
+ Ok ( _) => { /* Cool, everything's alright. */ } ,
63
+ Err ( err) => {
64
+ err. report ( tcx, tcx. def_span ( def_id) , "static" ) ;
54
65
}
55
66
} ;
56
- let item = tcx. hir . expect_item ( node_id) ;
57
- if let hir:: ItemStatic ( _, m, _) = item. node {
58
- match consts:: trans_static ( & cx, m, def_id, & item. attrs ) {
59
- Ok ( _) => { /* Cool, everything's alright. */ } ,
60
- Err ( err) => {
61
- err. report ( tcx, item. span , "static" ) ;
62
- }
63
- } ;
64
- } else {
65
- span_bug ! ( item. span, "Mismatch between hir::Item type and TransItem type" )
66
- }
67
67
}
68
68
MonoItem :: GlobalAsm ( node_id) => {
69
69
let item = cx. tcx . hir . expect_item ( node_id) ;
@@ -137,20 +137,12 @@ fn predefine_static<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
137
137
linkage : Linkage ,
138
138
visibility : Visibility ,
139
139
symbol_name : & str ) {
140
- let node_id = match cx. tcx . hir . as_local_node_id ( def_id) {
141
- Some ( node_id) => node_id,
142
- None => {
143
- bug ! ( "MonoItemExt::predefine() called for non-local static `{:?}`." ,
144
- def_id)
145
- }
146
- } ;
147
-
148
140
let instance = Instance :: mono ( cx. tcx , def_id) ;
149
141
let ty = instance. ty ( cx. tcx ) ;
150
142
let llty = cx. layout_of ( ty) . llvm_type ( cx) ;
151
143
152
144
let g = declare:: define_global ( cx, symbol_name, llty) . unwrap_or_else ( || {
153
- cx. sess ( ) . span_fatal ( cx. tcx . hir . span ( node_id ) ,
145
+ cx. sess ( ) . span_fatal ( cx. tcx . def_span ( def_id ) ,
154
146
& format ! ( "symbol `{}` is already defined" , symbol_name) )
155
147
} ) ;
156
148
0 commit comments