Skip to content

Commit 2ba1f35

Browse files
committed
Be honest about data mutability
1 parent 871be2a commit 2ba1f35

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/constant.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,15 @@ fn data_id_for_alloc_id<B: Backend>(module: &mut Module<B>, alloc_id: AllocId) -
133133
.unwrap()
134134
}
135135

136-
fn data_id_for_static<B: Backend>(tcx: TyCtxt, module: &mut Module<B>, def_id: DefId) -> DataId {
136+
fn data_id_for_static<'a, 'tcx: 'a, B: Backend>(tcx: TyCtxt<'a, 'tcx, 'tcx>, module: &mut Module<B>, def_id: DefId) -> DataId {
137137
let symbol_name = tcx.symbol_name(Instance::mono(tcx, def_id)).as_str();
138+
let is_mutable = if let ::rustc::hir::Mutability::MutMutable = tcx.is_static(def_id).unwrap() {
139+
true
140+
} else {
141+
!tcx.type_of(def_id).is_freeze(tcx, ParamEnv::reveal_all(), DUMMY_SP)
142+
};
138143
module
139-
.declare_data(&*symbol_name, Linkage::Export, false)
144+
.declare_data(&*symbol_name, Linkage::Export, is_mutable)
140145
.unwrap()
141146
}
142147

0 commit comments

Comments
 (0)