Skip to content

Commit 7279f7e

Browse files
Add a IsIdentity extension trait for CanonicalUserType
1 parent 154fc09 commit 7279f7e

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc_middle::ty::error::TypeError;
2626
use rustc_middle::ty::fold::TypeFoldable;
2727
use rustc_middle::ty::visit::{TypeVisitable, TypeVisitableExt};
2828
use rustc_middle::ty::{
29-
self, AdtKind, CanonicalUserType, GenericParamDefKind, Ty, TyCtxt, UserType,
29+
self, AdtKind, CanonicalUserType, GenericParamDefKind, IsIdentity, Ty, TyCtxt, UserType,
3030
};
3131
use rustc_middle::ty::{GenericArgKind, GenericArgsRef, UserArgs, UserSelfTy};
3232
use rustc_session::lint;
@@ -208,7 +208,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
208208
debug!("fcx {}", self.tag());
209209

210210
// FIXME: is_identity being on `UserType` and not `Canonical<UserType>` is awkward
211-
if !canonical_user_type_annotation.value.is_identity() {
211+
if !canonical_user_type_annotation.is_identity() {
212212
self.typeck_results
213213
.borrow_mut()
214214
.user_provided_types_mut()

compiler/rustc_middle/src/ty/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ pub use self::sty::{
106106
};
107107
pub use self::trait_def::TraitDef;
108108
pub use self::typeck_results::{
109-
CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, TypeckResults,
110-
UserType, UserTypeAnnotationIndex,
109+
CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, IsIdentity,
110+
TypeckResults, UserType, UserTypeAnnotationIndex,
111111
};
112112

113113
pub mod _match;

compiler/rustc_middle/src/ty/typeck_results.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -607,11 +607,15 @@ pub enum UserType<'tcx> {
607607
TypeOf(DefId, UserArgs<'tcx>),
608608
}
609609

610-
impl<'tcx> UserType<'tcx> {
610+
pub trait IsIdentity {
611+
fn is_identity(&self) -> bool;
612+
}
613+
614+
impl<'tcx> IsIdentity for CanonicalUserType<'tcx> {
611615
/// Returns `true` if this represents a substitution of the form `[?0, ?1, ?2]`,
612616
/// i.e., each thing is mapped to a canonical variable with the same index.
613-
pub fn is_identity(&self) -> bool {
614-
match self {
617+
fn is_identity(&self) -> bool {
618+
match self.value {
615619
UserType::Ty(_) => false,
616620
UserType::TypeOf(_, user_args) => {
617621
if user_args.user_self_ty.is_some() {

0 commit comments

Comments
 (0)