Skip to content

Commit 0663f25

Browse files
committed
Always qualify literals by type
1 parent a1912f2 commit 0663f25

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

src/librustc_mir/transform/check_consts/qualifs.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,32 +94,23 @@ pub trait Qualif {
9494
}
9595

9696
Operand::Constant(ref constant) => {
97-
if constant.check_static_ptr(cx.tcx).is_some() {
98-
// `mir_const_qualif` does return the qualifs in the final value of a `static`,
99-
// so we could use value-based qualification here, but we shouldn't do this
100-
// without a good reason.
101-
//
102-
// Note: this uses `constant.literal.ty` which is a reference or pointer to the
103-
// type of the actual `static` item.
104-
Self::in_any_value_of_ty(cx, constant.literal.ty)
105-
} else if let ty::ConstKind::Unevaluated(def_id, _, promoted) = constant.literal.val
106-
{
97+
// Check the qualifs of the value of `const` items.
98+
if let ty::ConstKind::Unevaluated(def_id, _, promoted) = constant.literal.val {
10799
assert!(promoted.is_none());
108100
// Don't peek inside trait associated constants.
109-
if cx.tcx.trait_of_item(def_id).is_some() {
110-
Self::in_any_value_of_ty(cx, constant.literal.ty)
111-
} else {
101+
if cx.tcx.trait_of_item(def_id).is_none() {
112102
let qualifs = cx.tcx.at(constant.span).mir_const_qualif(def_id);
113-
let qualif = Self::in_qualifs(&qualifs);
103+
if !Self::in_qualifs(&qualifs) {
104+
return false;
105+
}
114106

115107
// Just in case the type is more specific than
116108
// the definition, e.g., impl associated const
117109
// with type parameters, take it into account.
118-
qualif && Self::in_any_value_of_ty(cx, constant.literal.ty)
119110
}
120-
} else {
121-
false
122111
}
112+
// Otherwise use the qualifs of the type.
113+
Self::in_any_value_of_ty(cx, constant.literal.ty)
123114
}
124115
}
125116
}
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![feature(no_core, lang_items)]
2-
#![crate_type="rlib"]
2+
#![crate_type = "rlib"]
33
#![no_core]
44

55
pub static STATIC_BOOL: bool = true;
@@ -9,7 +9,6 @@ pub static mut STATIC_MUT_BOOL: bool = true;
99
const CONST_BOOL: bool = true;
1010
pub static CONST_BOOL_REF: &'static bool = &CONST_BOOL;
1111

12-
1312
#[lang = "sized"]
1413
trait Sized {}
1514

@@ -19,10 +18,13 @@ trait Copy {}
1918
#[lang = "freeze"]
2019
trait Freeze {}
2120

21+
// No `UnsafeCell`, so everything is `Freeze`.
22+
impl<T: ?Sized> Freeze for T {}
23+
2224
#[lang = "sync"]
2325
trait Sync {}
2426
impl Sync for bool {}
2527
impl Sync for &'static bool {}
2628

27-
#[lang="drop_in_place"]
28-
pub unsafe fn drop_in_place<T: ?Sized>(_: *mut T) { }
29+
#[lang = "drop_in_place"]
30+
pub unsafe fn drop_in_place<T: ?Sized>(_: *mut T) {}

0 commit comments

Comments
 (0)