Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 05dec8f

Browse files
committed
ImpliedOutlivesBounds to rustc_middle
1 parent f79fae3 commit 05dec8f

File tree

6 files changed

+27
-29
lines changed

6 files changed

+27
-29
lines changed

compiler/rustc_borrowck/src/type_check/free_region_relations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
373373
) -> Option<&'tcx QueryRegionConstraints<'tcx>> {
374374
let TypeOpOutput { output: bounds, constraints, .. } = self
375375
.param_env
376-
.and(type_op::implied_outlives_bounds::ImpliedOutlivesBounds { ty })
376+
.and(type_op::ImpliedOutlivesBounds { ty })
377377
.fully_perform(self.infcx, span)
378378
.map_err(|_: ErrorGuaranteed| debug!("failed to compute implied bounds {:?}", ty))
379379
.ok()?;

compiler/rustc_middle/src/query/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ use crate::query::plumbing::{
6565
CyclePlaceholder, DynamicQuery, query_ensure, query_ensure_error_guaranteed, query_get_at,
6666
};
6767
use crate::traits::query::{
68-
CanonicalAliasGoal, CanonicalPredicateGoal, CanonicalTyGoal,
69-
CanonicalTypeOpAscribeUserTypeGoal, CanonicalTypeOpNormalizeGoal,
68+
CanonicalAliasGoal, CanonicalImpliedOutlivesBoundsGoal, CanonicalPredicateGoal,
69+
CanonicalTyGoal, CanonicalTypeOpAscribeUserTypeGoal, CanonicalTypeOpNormalizeGoal,
7070
CanonicalTypeOpProvePredicateGoal, DropckConstraint, DropckOutlivesResult,
7171
MethodAutoderefStepsResult, NoSolution, NormalizationResult, OutlivesBound,
7272
};
@@ -2049,21 +2049,21 @@ rustc_queries! {
20492049
}
20502050

20512051
query implied_outlives_bounds_compat(
2052-
goal: CanonicalTyGoal<'tcx>
2052+
goal: CanonicalImpliedOutlivesBoundsGoal<'tcx>
20532053
) -> Result<
20542054
&'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>,
20552055
NoSolution,
20562056
> {
2057-
desc { "computing implied outlives bounds for `{}`", goal.value.value }
2057+
desc { "computing implied outlives bounds for `{}`", goal.value.value.ty }
20582058
}
20592059

20602060
query implied_outlives_bounds(
2061-
goal: CanonicalTyGoal<'tcx>
2061+
goal: CanonicalImpliedOutlivesBoundsGoal<'tcx>
20622062
) -> Result<
20632063
&'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>,
20642064
NoSolution,
20652065
> {
2066-
desc { "computing implied outlives bounds v2 for `{}`", goal.value.value }
2066+
desc { "computing implied outlives bounds v2 for `{}`", goal.value.value.ty }
20672067
}
20682068

20692069
/// Do not call this query directly:

compiler/rustc_middle/src/traits/query.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ pub mod type_op {
7070
Self { value }
7171
}
7272
}
73+
74+
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable, TypeFoldable, TypeVisitable)]
75+
pub struct ImpliedOutlivesBounds<'tcx> {
76+
pub ty: Ty<'tcx>,
77+
}
7378
}
7479

7580
pub type CanonicalAliasGoal<'tcx> = Canonical<'tcx, ty::ParamEnvAnd<'tcx, ty::AliasTy<'tcx>>>;
@@ -92,6 +97,9 @@ pub type CanonicalTypeOpProvePredicateGoal<'tcx> =
9297
pub type CanonicalTypeOpNormalizeGoal<'tcx, T> =
9398
Canonical<'tcx, ty::ParamEnvAnd<'tcx, type_op::Normalize<T>>>;
9499

100+
pub type CanonicalImpliedOutlivesBoundsGoal<'tcx> =
101+
Canonical<'tcx, ty::ParamEnvAnd<'tcx, type_op::ImpliedOutlivesBounds<'tcx>>>;
102+
95103
#[derive(Clone, Debug, Default, HashStable, TypeFoldable, TypeVisitable)]
96104
pub struct DropckOutlivesResult<'tcx> {
97105
pub kinds: Vec<GenericArg<'tcx>>,

compiler/rustc_trait_selection/src/traits/outlives_bounds.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use rustc_data_structures::fx::FxIndexSet;
22
use rustc_infer::infer::InferOk;
33
use rustc_infer::infer::resolve::OpportunisticRegionResolver;
4+
use rustc_infer::traits::query::type_op::ImpliedOutlivesBounds;
45
use rustc_macros::extension;
56
use rustc_middle::infer::canonical::{OriginalQueryValues, QueryRegionConstraints};
67
use rustc_middle::span_bug;
@@ -54,11 +55,12 @@ fn implied_outlives_bounds<'a, 'tcx>(
5455
assert!(!ty.has_non_region_infer());
5556

5657
let mut canonical_var_values = OriginalQueryValues::default();
57-
let canonical_ty = infcx.canonicalize_query(param_env.and(ty), &mut canonical_var_values);
58+
let input = ImpliedOutlivesBounds { ty };
59+
let canonical = infcx.canonicalize_query(param_env.and(input), &mut canonical_var_values);
5860
let implied_bounds_result = if compat {
59-
infcx.tcx.implied_outlives_bounds_compat(canonical_ty)
61+
infcx.tcx.implied_outlives_bounds_compat(canonical)
6062
} else {
61-
infcx.tcx.implied_outlives_bounds(canonical_ty)
63+
infcx.tcx.implied_outlives_bounds(canonical)
6264
};
6365
let Ok(canonical_result) = implied_bounds_result else {
6466
return vec![];

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_infer::infer::canonical::Canonical;
22
use rustc_infer::infer::resolve::OpportunisticRegionResolver;
33
use rustc_infer::traits::query::OutlivesBound;
4-
use rustc_macros::{HashStable, TypeFoldable, TypeVisitable};
4+
use rustc_infer::traits::query::type_op::ImpliedOutlivesBounds;
55
use rustc_middle::infer::canonical::CanonicalQueryResponse;
66
use rustc_middle::traits::ObligationCause;
77
use rustc_middle::ty::{self, ParamEnvAnd, Ty, TyCtxt, TypeFolder, TypeVisitableExt};
@@ -14,11 +14,6 @@ use tracing::debug;
1414
use crate::traits::query::NoSolution;
1515
use crate::traits::{ObligationCtxt, wf};
1616

17-
#[derive(Copy, Clone, Debug, HashStable, TypeFoldable, TypeVisitable)]
18-
pub struct ImpliedOutlivesBounds<'tcx> {
19-
pub ty: Ty<'tcx>,
20-
}
21-
2217
impl<'tcx> super::QueryTypeOp<'tcx> for ImpliedOutlivesBounds<'tcx> {
2318
type QueryResponse = Vec<OutlivesBound<'tcx>>;
2419

@@ -40,14 +35,6 @@ impl<'tcx> super::QueryTypeOp<'tcx> for ImpliedOutlivesBounds<'tcx> {
4035
tcx: TyCtxt<'tcx>,
4136
canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, Self>>,
4237
) -> Result<CanonicalQueryResponse<'tcx, Self::QueryResponse>, NoSolution> {
43-
// FIXME this `unchecked_map` is only necessary because the
44-
// query is defined as taking a `ParamEnvAnd<Ty>`; it should
45-
// take an `ImpliedOutlivesBounds` instead
46-
let canonicalized = canonicalized.unchecked_map(|ParamEnvAnd { param_env, value }| {
47-
let ImpliedOutlivesBounds { ty } = value;
48-
param_env.and(ty)
49-
});
50-
5138
if tcx.sess.opts.unstable_opts.no_implied_bounds_compat {
5239
tcx.implied_outlives_bounds(canonicalized)
5340
} else {

compiler/rustc_traits/src/implied_outlives_bounds.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
use rustc_infer::infer::TyCtxtInferExt;
66
use rustc_infer::infer::canonical::{self, Canonical};
77
use rustc_infer::traits::query::OutlivesBound;
8+
use rustc_infer::traits::query::type_op::ImpliedOutlivesBounds;
89
use rustc_middle::query::Providers;
910
use rustc_middle::ty::TyCtxt;
1011
use rustc_trait_selection::infer::InferCtxtBuilderExt;
1112
use rustc_trait_selection::traits::query::type_op::implied_outlives_bounds::{
1213
compute_implied_outlives_bounds_compat_inner, compute_implied_outlives_bounds_inner,
1314
};
14-
use rustc_trait_selection::traits::query::{CanonicalTyGoal, NoSolution};
15+
use rustc_trait_selection::traits::query::{CanonicalImpliedOutlivesBoundsGoal, NoSolution};
1516

1617
pub(crate) fn provide(p: &mut Providers) {
1718
*p = Providers { implied_outlives_bounds_compat, ..*p };
@@ -20,26 +21,26 @@ pub(crate) fn provide(p: &mut Providers) {
2021

2122
fn implied_outlives_bounds_compat<'tcx>(
2223
tcx: TyCtxt<'tcx>,
23-
goal: CanonicalTyGoal<'tcx>,
24+
goal: CanonicalImpliedOutlivesBoundsGoal<'tcx>,
2425
) -> Result<
2526
&'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>,
2627
NoSolution,
2728
> {
2829
tcx.infer_ctxt().enter_canonical_trait_query(&goal, |ocx, key| {
29-
let (param_env, ty) = key.into_parts();
30+
let (param_env, ImpliedOutlivesBounds { ty }) = key.into_parts();
3031
compute_implied_outlives_bounds_compat_inner(ocx, param_env, ty)
3132
})
3233
}
3334

3435
fn implied_outlives_bounds<'tcx>(
3536
tcx: TyCtxt<'tcx>,
36-
goal: CanonicalTyGoal<'tcx>,
37+
goal: CanonicalImpliedOutlivesBoundsGoal<'tcx>,
3738
) -> Result<
3839
&'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>,
3940
NoSolution,
4041
> {
4142
tcx.infer_ctxt().enter_canonical_trait_query(&goal, |ocx, key| {
42-
let (param_env, ty) = key.into_parts();
43+
let (param_env, ImpliedOutlivesBounds { ty }) = key.into_parts();
4344
compute_implied_outlives_bounds_inner(ocx, param_env, ty)
4445
})
4546
}

0 commit comments

Comments
 (0)