Skip to content

Commit

Permalink
Pass Substs to in_adt_inherently
Browse files Browse the repository at this point in the history
  • Loading branch information
ecstatic-morse committed Apr 28, 2020
1 parent d7afaa7 commit 0850c3b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/librustc_mir/transform/check_consts/qualifs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! See the `Qualif` trait for more info.
use rustc_middle::mir::*;
use rustc_middle::ty::{self, AdtDef, Ty};
use rustc_middle::ty::{self, subst::SubstsRef, AdtDef, Ty};
use rustc_span::DUMMY_SP;

use super::ConstCx;
Expand Down Expand Up @@ -53,7 +53,11 @@ pub trait Qualif {
/// with a custom `Drop` impl is inherently `NeedsDrop`.
///
/// Returning `true` for `in_adt_inherently` but `false` for `in_any_value_of_ty` is unsound.
fn in_adt_inherently(cx: &ConstCx<'_, 'tcx>, adt: &AdtDef) -> bool;
fn in_adt_inherently(
cx: &ConstCx<'_, 'tcx>,
adt: &'tcx AdtDef,
substs: SubstsRef<'tcx>,
) -> bool;
}

/// Constant containing interior mutability (`UnsafeCell<T>`).
Expand All @@ -74,7 +78,7 @@ impl Qualif for HasMutInterior {
!ty.is_freeze(cx.tcx, cx.param_env, DUMMY_SP)
}

fn in_adt_inherently(cx: &ConstCx<'_, 'tcx>, adt: &AdtDef) -> bool {
fn in_adt_inherently(cx: &ConstCx<'_, 'tcx>, adt: &'tcx AdtDef, _: SubstsRef<'tcx>) -> bool {
// Exactly one type, `UnsafeCell`, has the `HasMutInterior` qualif inherently.
// It arises structurally for all other types.
Some(adt.did) == cx.tcx.lang_items().unsafe_cell_type()
Expand All @@ -99,7 +103,7 @@ impl Qualif for NeedsDrop {
ty.needs_drop(cx.tcx, cx.param_env)
}

fn in_adt_inherently(cx: &ConstCx<'_, 'tcx>, adt: &AdtDef) -> bool {
fn in_adt_inherently(cx: &ConstCx<'_, 'tcx>, adt: &'tcx AdtDef, _: SubstsRef<'tcx>) -> bool {
adt.has_dtor(cx.tcx)
}
}
Expand Down Expand Up @@ -147,8 +151,8 @@ where
Rvalue::Aggregate(kind, operands) => {
// Return early if we know that the struct or enum being constructed is always
// qualified.
if let AggregateKind::Adt(def, ..) = **kind {
if Q::in_adt_inherently(cx, def) {
if let AggregateKind::Adt(def, _, substs, ..) = **kind {
if Q::in_adt_inherently(cx, def, substs) {
return true;
}
}
Expand Down

0 comments on commit 0850c3b

Please sign in to comment.