diff --git a/src/librustc_mir/transform/check_consts/qualifs.rs b/src/librustc_mir/transform/check_consts/qualifs.rs index 746d83b05c6b3..bd895171e358e 100644 --- a/src/librustc_mir/transform/check_consts/qualifs.rs +++ b/src/librustc_mir/transform/check_consts/qualifs.rs @@ -1,6 +1,5 @@ //! A copy of the `Qualif` trait in `qualify_consts.rs` that is suitable for the new validator. -use rustc::hir::def_id::DefId; use rustc::mir::*; use rustc::ty::{self, Ty}; use syntax_pos::DUMMY_SP; @@ -33,12 +32,6 @@ pub trait Qualif { /// of the type. fn in_any_value_of_ty(_cx: &ConstCx<'_, 'tcx>, _ty: Ty<'tcx>) -> bool; - fn in_static(cx: &ConstCx<'_, 'tcx>, def_id: DefId) -> bool { - // `mir_const_qualif` does return the qualifs in the final value of a `static`, so we could - // use value-based qualification here, but we shouldn't do this without a good reason. - Self::in_any_value_of_ty(cx, cx.tcx.type_of(def_id)) - } - fn in_projection_structurally( cx: &ConstCx<'_, 'tcx>, per_local: &impl Fn(Local) -> bool, @@ -101,8 +94,14 @@ pub trait Qualif { } Operand::Constant(ref constant) => { - if let Some(static_) = constant.check_static_ptr(cx.tcx) { - Self::in_static(cx, static_) + if constant.check_static_ptr(cx.tcx).is_some() { + // `mir_const_qualif` does return the qualifs in the final value of a `static`, + // so we could use value-based qualification here, but we shouldn't do this + // without a good reason. + // + // Note: this uses `constant.literal.ty` which is a reference or pointer to the + // type of the actual `static` item. + Self::in_any_value_of_ty(cx, constant.literal.ty) } else if let ty::ConstKind::Unevaluated(def_id, _) = constant.literal.val { // Don't peek inside trait associated constants. if cx.tcx.trait_of_item(def_id).is_some() { diff --git a/src/test/ui/consts/const-eval/promote-static.rs b/src/test/ui/consts/const-eval/promote-static.rs new file mode 100644 index 0000000000000..d3c663c53e905 --- /dev/null +++ b/src/test/ui/consts/const-eval/promote-static.rs @@ -0,0 +1,14 @@ +// regression test for #67609. + +// check-pass + +static NONE: Option = None; + +static NONE_REF_REF: &&Option = { + let x = &&NONE; + x +}; + +fn main() { + println!("{:?}", NONE_REF_REF); +}