Skip to content

Commit

Permalink
fix static_ptr_ty for foreign statics, and more comments in check_uns…
Browse files Browse the repository at this point in the history
…afety
  • Loading branch information
RalfJung committed Oct 19, 2020
1 parent cb33f95 commit c1766c6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions compiler/rustc_middle/src/ty/util.rs
Expand Up @@ -529,8 +529,11 @@ impl<'tcx> TyCtxt<'tcx> {
// Make sure that any constants in the static's type are evaluated.
let static_ty = self.normalize_erasing_regions(ty::ParamEnv::empty(), self.type_of(def_id));

// Make sure that accesses to unsafe statics end up using raw pointers.
if self.is_mutable_static(def_id) {
self.mk_mut_ptr(static_ty)
} else if self.is_foreign_item(def_id) {
self.mk_imm_ptr(static_ty)
} else {
self.mk_imm_ref(self.lifetimes.re_erased, static_ty)
}
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_mir/src/transform/check_unsafety.rs
Expand Up @@ -204,6 +204,9 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
if let [] = proj_base {
let decl = &self.body.local_decls[place.local];
if decl.internal {
// If the projection root is an artifical local that we introduced when
// desugaring `static`, give a more specific error message
// (avoid the general "raw pointer" clause below, that would only be confusing).
if let Some(box LocalInfo::StaticRef { def_id, .. }) = decl.local_info {
if self.tcx.is_mutable_static(def_id) {
self.require_unsafe(
Expand Down

0 comments on commit c1766c6

Please sign in to comment.