@@ -24,6 +24,7 @@ use llvm;
2424use monomorphize:: Instance ;
2525use type_of:: LayoutLlvmExt ;
2626use rustc:: hir;
27+ use rustc:: hir:: def:: Def ;
2728use rustc:: hir:: def_id:: DefId ;
2829use rustc:: mir:: mono:: { Linkage , Visibility } ;
2930use rustc:: ty:: TypeFoldable ;
@@ -46,24 +47,23 @@ pub trait MonoItemExt<'a, 'tcx>: fmt::Debug + BaseMonoItemExt<'a, 'tcx> {
4647 match * self . as_mono_item ( ) {
4748 MonoItem :: Static ( def_id) => {
4849 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+ }
5155 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" ) ;
5465 }
5566 } ;
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- }
6767 }
6868 MonoItem :: GlobalAsm ( node_id) => {
6969 let item = cx. tcx . hir . expect_item ( node_id) ;
@@ -137,20 +137,12 @@ fn predefine_static<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
137137 linkage : Linkage ,
138138 visibility : Visibility ,
139139 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-
148140 let instance = Instance :: mono ( cx. tcx , def_id) ;
149141 let ty = instance. ty ( cx. tcx ) ;
150142 let llty = cx. layout_of ( ty) . llvm_type ( cx) ;
151143
152144 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 ) ,
154146 & format ! ( "symbol `{}` is already defined" , symbol_name) )
155147 } ) ;
156148
0 commit comments