Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the correct type for static qualifs #67621

Merged
merged 1 commit into from
Dec 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/librustc_mir/transform/check_consts/qualifs.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
oli-obk marked this conversation as resolved.
Show resolved Hide resolved
} 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() {
Expand Down
14 changes: 14 additions & 0 deletions src/test/ui/consts/const-eval/promote-static.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// regression test for #67609.

// check-pass

static NONE: Option<String> = None;

static NONE_REF_REF: &&Option<String> = {
let x = &&NONE;
x
};

fn main() {
println!("{:?}", NONE_REF_REF);
}