Skip to content

Commit c1766c6

Browse files
committed
fix static_ptr_ty for foreign statics, and more comments in check_unsafety
1 parent cb33f95 commit c1766c6

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

compiler/rustc_middle/src/ty/util.rs

+3
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,11 @@ impl<'tcx> TyCtxt<'tcx> {
529529
// Make sure that any constants in the static's type are evaluated.
530530
let static_ty = self.normalize_erasing_regions(ty::ParamEnv::empty(), self.type_of(def_id));
531531

532+
// Make sure that accesses to unsafe statics end up using raw pointers.
532533
if self.is_mutable_static(def_id) {
533534
self.mk_mut_ptr(static_ty)
535+
} else if self.is_foreign_item(def_id) {
536+
self.mk_imm_ptr(static_ty)
534537
} else {
535538
self.mk_imm_ref(self.lifetimes.re_erased, static_ty)
536539
}

compiler/rustc_mir/src/transform/check_unsafety.rs

+3
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
204204
if let [] = proj_base {
205205
let decl = &self.body.local_decls[place.local];
206206
if decl.internal {
207+
// If the projection root is an artifical local that we introduced when
208+
// desugaring `static`, give a more specific error message
209+
// (avoid the general "raw pointer" clause below, that would only be confusing).
207210
if let Some(box LocalInfo::StaticRef { def_id, .. }) = decl.local_info {
208211
if self.tcx.is_mutable_static(def_id) {
209212
self.require_unsafe(

0 commit comments

Comments
 (0)