Skip to content

Commit 5d19d4d

Browse files
committed
Use the correct type for static qualifs
1 parent ed33453 commit 5d19d4d

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

src/librustc_mir/transform/check_consts/qualifs.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! A copy of the `Qualif` trait in `qualify_consts.rs` that is suitable for the new validator.
22
3-
use rustc::hir::def_id::DefId;
43
use rustc::mir::*;
54
use rustc::ty::{self, Ty};
65
use syntax_pos::DUMMY_SP;
@@ -33,12 +32,6 @@ pub trait Qualif {
3332
/// of the type.
3433
fn in_any_value_of_ty(_cx: &ConstCx<'_, 'tcx>, _ty: Ty<'tcx>) -> bool;
3534

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-
4235
fn in_projection_structurally(
4336
cx: &ConstCx<'_, 'tcx>,
4437
per_local: &impl Fn(Local) -> bool,
@@ -101,8 +94,14 @@ pub trait Qualif {
10194
}
10295

10396
Operand::Constant(ref constant) => {
104-
if let Some(static_) = constant.check_static_ptr(cx.tcx) {
105-
Self::in_static(cx, static_)
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)
106105
} else if let ty::ConstKind::Unevaluated(def_id, _) = constant.literal.val {
107106
// Don't peek inside trait associated constants.
108107
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)