fix static_ptr_ty for foreign statics, and more comments in check_unsafety
This commit is contained in:
parent
cb33f956c3
commit
c1766c6372
2 changed files with 6 additions and 0 deletions
|
@ -529,8 +529,11 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
// Make sure that any constants in the static's type are evaluated.
|
// 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));
|
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) {
|
if self.is_mutable_static(def_id) {
|
||||||
self.mk_mut_ptr(static_ty)
|
self.mk_mut_ptr(static_ty)
|
||||||
|
} else if self.is_foreign_item(def_id) {
|
||||||
|
self.mk_imm_ptr(static_ty)
|
||||||
} else {
|
} else {
|
||||||
self.mk_imm_ref(self.lifetimes.re_erased, static_ty)
|
self.mk_imm_ref(self.lifetimes.re_erased, static_ty)
|
||||||
}
|
}
|
||||||
|
|
|
@ -204,6 +204,9 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
|
||||||
if let [] = proj_base {
|
if let [] = proj_base {
|
||||||
let decl = &self.body.local_decls[place.local];
|
let decl = &self.body.local_decls[place.local];
|
||||||
if decl.internal {
|
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 let Some(box LocalInfo::StaticRef { def_id, .. }) = decl.local_info {
|
||||||
if self.tcx.is_mutable_static(def_id) {
|
if self.tcx.is_mutable_static(def_id) {
|
||||||
self.require_unsafe(
|
self.require_unsafe(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue