Skip to content

Commit 17b53b9

Browse files
committed
Remap more env constness for queries
1 parent 2bea3b3 commit 17b53b9

File tree

5 files changed

+40
-18
lines changed

5 files changed

+40
-18
lines changed

compiler/rustc_middle/src/infer/canonical.rs

+8
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,14 @@ impl<'tcx, R> Canonical<'tcx, QueryResponse<'tcx, R>> {
246246
}
247247
}
248248

249+
impl<'tcx, R> Canonical<'tcx, ty::ParamEnvAnd<'tcx, R>> {
250+
#[inline]
251+
pub fn without_const(mut self) -> Self {
252+
self.value = self.value.without_const();
253+
self
254+
}
255+
}
256+
249257
impl<'tcx, V> Canonical<'tcx, V> {
250258
/// Allows you to map the `value` of a canonical while keeping the
251259
/// same set of bound variables.

compiler/rustc_middle/src/query/mod.rs

+11
Original file line numberDiff line numberDiff line change
@@ -1655,6 +1655,7 @@ rustc_queries! {
16551655
NoSolution,
16561656
> {
16571657
desc { "normalizing `{:?}`", goal }
1658+
remap_env_constness
16581659
}
16591660

16601661
// FIXME: Implement `normalize_generic_arg_after_erasing_regions` and
@@ -1701,6 +1702,7 @@ rustc_queries! {
17011702
NoSolution,
17021703
> {
17031704
desc { "computing implied outlives bounds for `{:?}`", goal }
1705+
remap_env_constness
17041706
}
17051707

17061708
/// Do not call this query directly: invoke `infcx.at().dropck_outlives()` instead.
@@ -1711,6 +1713,7 @@ rustc_queries! {
17111713
NoSolution,
17121714
> {
17131715
desc { "computing dropck types for `{:?}`", goal }
1716+
remap_env_constness
17141717
}
17151718

17161719
/// Do not call this query directly: invoke `infcx.predicate_may_hold()` or
@@ -1738,6 +1741,7 @@ rustc_queries! {
17381741
NoSolution,
17391742
> {
17401743
desc { "evaluating `type_op_ascribe_user_type` `{:?}`", goal }
1744+
remap_env_constness
17411745
}
17421746

17431747
/// Do not call this query directly: part of the `Eq` type-op
@@ -1748,6 +1752,7 @@ rustc_queries! {
17481752
NoSolution,
17491753
> {
17501754
desc { "evaluating `type_op_eq` `{:?}`", goal }
1755+
remap_env_constness
17511756
}
17521757

17531758
/// Do not call this query directly: part of the `Subtype` type-op
@@ -1758,6 +1763,7 @@ rustc_queries! {
17581763
NoSolution,
17591764
> {
17601765
desc { "evaluating `type_op_subtype` `{:?}`", goal }
1766+
remap_env_constness
17611767
}
17621768

17631769
/// Do not call this query directly: part of the `ProvePredicate` type-op
@@ -1778,6 +1784,7 @@ rustc_queries! {
17781784
NoSolution,
17791785
> {
17801786
desc { "normalizing `{:?}`", goal }
1787+
remap_env_constness
17811788
}
17821789

17831790
/// Do not call this query directly: part of the `Normalize` type-op
@@ -1788,6 +1795,7 @@ rustc_queries! {
17881795
NoSolution,
17891796
> {
17901797
desc { "normalizing `{:?}`", goal }
1798+
remap_env_constness
17911799
}
17921800

17931801
/// Do not call this query directly: part of the `Normalize` type-op
@@ -1798,6 +1806,7 @@ rustc_queries! {
17981806
NoSolution,
17991807
> {
18001808
desc { "normalizing `{:?}`", goal }
1809+
remap_env_constness
18011810
}
18021811

18031812
/// Do not call this query directly: part of the `Normalize` type-op
@@ -1808,6 +1817,7 @@ rustc_queries! {
18081817
NoSolution,
18091818
> {
18101819
desc { "normalizing `{:?}`", goal }
1820+
remap_env_constness
18111821
}
18121822

18131823
query subst_and_check_impossible_predicates(key: (DefId, SubstsRef<'tcx>)) -> bool {
@@ -1821,6 +1831,7 @@ rustc_queries! {
18211831
goal: CanonicalTyGoal<'tcx>
18221832
) -> MethodAutoderefStepsResult<'tcx> {
18231833
desc { "computing autoderef types for `{:?}`", goal }
1834+
remap_env_constness
18241835
}
18251836

18261837
query supported_target_features(_: CrateNum) -> FxHashMap<String, Option<Symbol>> {

compiler/rustc_middle/src/ty/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1354,6 +1354,10 @@ impl<'tcx> ParamEnv<'tcx> {
13541354
self
13551355
}
13561356

1357+
pub fn remap_constness_with(&mut self, mut constness: ty::BoundConstness) {
1358+
*self = self.with_constness(constness.and(self.constness()))
1359+
}
1360+
13571361
/// Returns a new parameter environment with the same clauses, but
13581362
/// which "reveals" the true results of projections in all cases
13591363
/// (even for associated types that are specializable). This is

compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs

+10-17
Original file line numberDiff line numberDiff line change
@@ -67,27 +67,20 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
6767
) -> Result<EvaluationResult, OverflowError> {
6868
let mut _orig_values = OriginalQueryValues::default();
6969

70-
let (param_env, predicate) = match obligation.predicate.kind().skip_binder() {
71-
ty::PredicateKind::Trait(mut pred) => {
72-
let orig_pred_constness = pred.constness;
73-
let env_constness = pred.constness.and(obligation.param_env.constness());
74-
75-
let predicate = if orig_pred_constness != pred.constness {
76-
self.tcx.mk_predicate(
77-
obligation.predicate.kind().rebind(ty::PredicateKind::Trait(pred)),
78-
)
79-
} else {
80-
obligation.predicate
81-
};
82-
83-
(obligation.param_env.with_constness(env_constness), predicate)
70+
let param_env = match obligation.predicate.kind().skip_binder() {
71+
ty::PredicateKind::Trait(pred) => {
72+
// we ignore the value set to it.
73+
let mut _constness = pred.constness;
74+
obligation
75+
.param_env
76+
.with_constness(_constness.and(obligation.param_env.constness()))
8477
}
8578
// constness has no effect on the given predicate.
86-
_ => (obligation.param_env.without_const(), obligation.predicate),
79+
_ => obligation.param_env.without_const(),
8780
};
8881

89-
let c_pred =
90-
self.canonicalize_query_keep_static(param_env.and(predicate), &mut _orig_values);
82+
let c_pred = self
83+
.canonicalize_query_keep_static(param_env.and(obligation.predicate), &mut _orig_values);
9184
// Run canonical query. If overflow occurs, rerun from scratch but this time
9285
// in standard trait query mode so that overflow is handled appropriately
9386
// within `SelectionContext`.

compiler/rustc_trait_selection/src/traits/query/type_op/prove_predicate.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,14 @@ impl<'tcx> super::QueryTypeOp<'tcx> for ProvePredicate<'tcx> {
3030

3131
fn perform_query(
3232
tcx: TyCtxt<'tcx>,
33-
canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Self>>,
33+
mut canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Self>>,
3434
) -> Fallible<CanonicalizedQueryResponse<'tcx, ()>> {
35+
match canonicalized.value.value.predicate.kind().skip_binder() {
36+
ty::PredicateKind::Trait(pred) => {
37+
canonicalized.value.param_env.remap_constness_with(pred.constness);
38+
}
39+
_ => canonicalized.value.param_env = canonicalized.value.param_env.without_const(),
40+
}
3541
tcx.type_op_prove_predicate(canonicalized)
3642
}
3743
}

0 commit comments

Comments
 (0)