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

Make qualify consts in_projection use PlaceRef #63299

Merged
merged 1 commit into from
Aug 6, 2019
Merged
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
29 changes: 15 additions & 14 deletions src/librustc_mir/transform/qualify_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,17 @@ trait Qualif {

fn in_projection_structurally(
cx: &ConstCx<'_, 'tcx>,
base: &PlaceBase<'tcx>,
proj: &Projection<'tcx>,
place: PlaceRef<'_, 'tcx>,
) -> bool {
let proj = place.projection.as_ref().unwrap();

let base_qualif = Self::in_place(cx, PlaceRef {
base,
base: place.base,
projection: &proj.base,
});
let qualif = base_qualif && Self::mask_for_ty(
cx,
Place::ty_from(&base, &proj.base, cx.body, cx.tcx)
Place::ty_from(place.base, &proj.base, cx.body, cx.tcx)
.projection_ty(cx.tcx, &proj.elem)
.ty,
);
Expand All @@ -208,10 +209,9 @@ trait Qualif {

fn in_projection(
cx: &ConstCx<'_, 'tcx>,
base: &PlaceBase<'tcx>,
proj: &Projection<'tcx>,
place: PlaceRef<'_, 'tcx>,
) -> bool {
Self::in_projection_structurally(cx, base, proj)
Self::in_projection_structurally(cx, place)
}

fn in_place(cx: &ConstCx<'_, 'tcx>, place: PlaceRef<'_, 'tcx>) -> bool {
Expand All @@ -234,9 +234,9 @@ trait Qualif {
Self::in_static(cx, static_)
},
PlaceRef {
base,
projection: Some(proj),
} => Self::in_projection(cx, base, proj),
base: _,
projection: Some(_),
} => Self::in_projection(cx, place),
}
}

Expand Down Expand Up @@ -448,9 +448,10 @@ impl Qualif for IsNotPromotable {

fn in_projection(
cx: &ConstCx<'_, 'tcx>,
base: &PlaceBase<'tcx>,
proj: &Projection<'tcx>,
place: PlaceRef<'_, 'tcx>,
) -> bool {
let proj = place.projection.as_ref().unwrap();

match proj.elem {
ProjectionElem::Deref |
ProjectionElem::Downcast(..) => return true,
Expand All @@ -461,7 +462,7 @@ impl Qualif for IsNotPromotable {

ProjectionElem::Field(..) => {
if cx.mode == Mode::NonConstFn {
let base_ty = Place::ty_from(base, &proj.base, cx.body, cx.tcx).ty;
let base_ty = Place::ty_from(place.base, &proj.base, cx.body, cx.tcx).ty;
if let Some(def) = base_ty.ty_adt_def() {
// No promotion of union field accesses.
if def.is_union() {
Expand All @@ -472,7 +473,7 @@ impl Qualif for IsNotPromotable {
}
}

Self::in_projection_structurally(cx, base, proj)
Self::in_projection_structurally(cx, place)
}

fn in_rvalue(cx: &ConstCx<'_, 'tcx>, rvalue: &Rvalue<'tcx>) -> bool {
Expand Down