Skip to content

Commit 59ea17e

Browse files
committed
rename upcast to cast_to_tcx_lifetime and improve comment
1 parent d695512 commit 59ea17e

File tree

6 files changed

+21
-16
lines changed

6 files changed

+21
-16
lines changed

src/librustc/traits/query/type_op/eq.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl<'gcx: 'tcx, 'tcx> super::QueryTypeOp<'gcx, 'tcx> for Eq<'tcx> {
4848
tcx.type_op_eq(canonicalized)
4949
}
5050

51-
fn upcast_result(
51+
fn cast_to_tcx_lifetime(
5252
v: &'a CanonicalizedQueryResult<'gcx, ()>,
5353
) -> &'a Canonical<'tcx, QueryResult<'tcx, ()>> {
5454
v

src/librustc/traits/query/type_op/mod.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,19 @@ pub trait QueryTypeOp<'gcx: 'tcx, 'tcx>: fmt::Debug + Sized {
5454
canonicalized: Canonicalized<'gcx, Self::QueryKey>,
5555
) -> Fallible<CanonicalizedQueryResult<'gcx, Self::QueryResult>>;
5656

57-
/// "Upcasts" a lifted query result (which is in the gcx lifetime)
57+
/// Casts a lifted query result (which is in the gcx lifetime)
5858
/// into the tcx lifetime. This is always just an identity cast,
59-
/// but the generic code does't realize it, so we have to push the
60-
/// operation into the impls that know more specifically what
59+
/// but the generic code doesn't realize it -- put another way, in
60+
/// the generic code, we have a `Lifted<'gcx, Self::QueryResult>`
61+
/// and we want to convert that to a `Self::QueryResult`. This is
62+
/// not a priori valid, so we can't do it -- but in practice, it
63+
/// is always a no-op (e.g., the lifted form of a type,
64+
/// `Ty<'gcx>`, is a subtype of `Ty<'tcx>`). So we have to push
65+
/// the operation into the impls that know more specifically what
6166
/// `QueryResult` is. This operation would (maybe) be nicer with
6267
/// something like HKTs or GATs, since then we could make
6368
/// `QueryResult` parametric and `'gcx` and `'tcx` etc.
64-
fn upcast_result(
69+
fn cast_to_tcx_lifetime(
6570
lifted_query_result: &'a CanonicalizedQueryResult<'gcx, Self::QueryResult>,
6671
) -> &'a Canonical<'tcx, QueryResult<'tcx, Self::QueryResult>>;
6772

@@ -80,7 +85,7 @@ pub trait QueryTypeOp<'gcx: 'tcx, 'tcx>: fmt::Debug + Sized {
8085
let (canonical_self, canonical_var_values) =
8186
infcx.canonicalize_hr_query_hack(&query_key);
8287
let canonical_result = Self::perform_query(infcx.tcx, canonical_self)?;
83-
let canonical_result = Self::upcast_result(&canonical_result);
88+
let canonical_result = Self::cast_to_tcx_lifetime(&canonical_result);
8489

8590
let param_env = Self::param_env(&query_key);
8691

src/librustc/traits/query/type_op/normalize.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ where
5555
T::type_op_method(tcx, canonicalized)
5656
}
5757

58-
fn upcast_result(
58+
fn cast_to_tcx_lifetime(
5959
v: &'a CanonicalizedQueryResult<'gcx, T>,
6060
) -> &'a Canonical<'tcx, QueryResult<'tcx, T>> {
61-
T::upcast_result(v)
61+
T::cast_to_tcx_lifetime(v)
6262
}
6363
}
6464

@@ -70,7 +70,7 @@ pub trait Normalizable<'gcx, 'tcx>: fmt::Debug + TypeFoldable<'tcx> + Lift<'gcx>
7070

7171
/// Convert from the `'gcx` (lifted) form of `Self` into the `tcx`
7272
/// form of `Self`.
73-
fn upcast_result(
73+
fn cast_to_tcx_lifetime(
7474
v: &'a CanonicalizedQueryResult<'gcx, Self>,
7575
) -> &'a Canonical<'tcx, QueryResult<'tcx, Self>>;
7676
}
@@ -86,7 +86,7 @@ where
8686
tcx.type_op_normalize_ty(canonicalized)
8787
}
8888

89-
fn upcast_result(
89+
fn cast_to_tcx_lifetime(
9090
v: &'a CanonicalizedQueryResult<'gcx, Self>,
9191
) -> &'a Canonical<'tcx, QueryResult<'tcx, Self>> {
9292
v
@@ -104,7 +104,7 @@ where
104104
tcx.type_op_normalize_predicate(canonicalized)
105105
}
106106

107-
fn upcast_result(
107+
fn cast_to_tcx_lifetime(
108108
v: &'a CanonicalizedQueryResult<'gcx, Self>,
109109
) -> &'a Canonical<'tcx, QueryResult<'tcx, Self>> {
110110
v
@@ -122,7 +122,7 @@ where
122122
tcx.type_op_normalize_poly_fn_sig(canonicalized)
123123
}
124124

125-
fn upcast_result(
125+
fn cast_to_tcx_lifetime(
126126
v: &'a CanonicalizedQueryResult<'gcx, Self>,
127127
) -> &'a Canonical<'tcx, QueryResult<'tcx, Self>> {
128128
v
@@ -140,7 +140,7 @@ where
140140
tcx.type_op_normalize_fn_sig(canonicalized)
141141
}
142142

143-
fn upcast_result(
143+
fn cast_to_tcx_lifetime(
144144
v: &'a CanonicalizedQueryResult<'gcx, Self>,
145145
) -> &'a Canonical<'tcx, QueryResult<'tcx, Self>> {
146146
v

src/librustc/traits/query/type_op/outlives.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ where
5555
tcx.dropck_outlives(canonicalized)
5656
}
5757

58-
fn upcast_result(
58+
fn cast_to_tcx_lifetime(
5959
lifted_query_result: &'a CanonicalizedQueryResult<'gcx, Self::QueryResult>,
6060
) -> &'a Canonical<'tcx, QueryResult<'tcx, Self::QueryResult>> {
6161
lifted_query_result

src/librustc/traits/query/type_op/prove_predicate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl<'gcx: 'tcx, 'tcx> super::QueryTypeOp<'gcx, 'tcx> for ProvePredicate<'tcx> {
4646
tcx.type_op_prove_predicate(canonicalized)
4747
}
4848

49-
fn upcast_result(
49+
fn cast_to_tcx_lifetime(
5050
v: &'a CanonicalizedQueryResult<'gcx, ()>,
5151
) -> &'a Canonical<'tcx, QueryResult<'tcx, ()>> {
5252
v

src/librustc/traits/query/type_op/subtype.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl<'gcx: 'tcx, 'tcx> super::QueryTypeOp<'gcx, 'tcx> for Subtype<'tcx> {
5252
tcx.type_op_subtype(canonicalized)
5353
}
5454

55-
fn upcast_result(
55+
fn cast_to_tcx_lifetime(
5656
v: &'a CanonicalizedQueryResult<'gcx, ()>,
5757
) -> &'a Canonical<'tcx, QueryResult<'tcx, ()>> {
5858
v

0 commit comments

Comments
 (0)