Skip to content

Commit 7c4f913

Browse files
matthewjasperjonas-schievink
authored andcommitted
Use the correct type for static qualifs
1 parent 03436b7 commit 7c4f913

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/librustc_mir/transform/check_consts/qualifs.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ pub trait Qualif {
3333
/// of the type.
3434
fn in_any_value_of_ty(_cx: &ConstCx<'_, 'tcx>, _ty: Ty<'tcx>) -> bool;
3535

36-
fn in_static(cx: &ConstCx<'_, 'tcx>, def_id: DefId) -> bool {
37-
// `mir_const_qualif` does return the qualifs in the final value of a `static`, so we could
38-
// use value-based qualification here, but we shouldn't do this without a good reason.
39-
Self::in_any_value_of_ty(cx, cx.tcx.type_of(def_id))
40-
}
41-
4236
fn in_projection_structurally(
4337
cx: &ConstCx<'_, 'tcx>,
4438
per_local: &impl Fn(Local) -> bool,
@@ -108,8 +102,14 @@ pub trait Qualif {
108102
Operand::Move(ref place) => Self::in_place(cx, per_local, place.as_ref()),
109103

110104
Operand::Constant(ref constant) => {
111-
if let Some(static_) = constant.check_static_ptr(cx.tcx) {
112-
Self::in_static(cx, static_)
105+
if constant.check_static_ptr(cx.tcx).is_some() {
106+
// `mir_const_qualif` does return the qualifs in the final value of a `static`,
107+
// so we could use value-based qualification here, but we shouldn't do this
108+
// without a good reason.
109+
//
110+
// Note: this uses `constant.literal.ty` which is a reference or pointer to the
111+
// type of the actual `static` item.
112+
Self::in_any_value_of_ty(cx, constant.literal.ty)
113113
} else if let ty::ConstKind::Unevaluated(def_id, _) = constant.literal.val {
114114
// Don't peek inside trait associated constants.
115115
if cx.tcx.trait_of_item(def_id).is_some() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// regression test for #67609.
2+
3+
// check-pass
4+
5+
static NONE: Option<String> = None;
6+
7+
static NONE_REF_REF: &&Option<String> = {
8+
let x = &&NONE;
9+
x
10+
};
11+
12+
fn main() {
13+
println!("{:?}", NONE_REF_REF);
14+
}

0 commit comments

Comments
 (0)