about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-10-23 16:11:48 -0400
committerMichael Goulet <michael@errs.io>2023-10-25 16:25:11 +0000
commit8f3b4f94ef739b9ad7d4f3cdee6be91f6913938f (patch)
treef8ba4c7adc1829cf4e42306a3e11f54730dd60d7
parent024ca99de5d39956a94815532db32bb241cef555 (diff)
downloadrust-8f3b4f94ef739b9ad7d4f3cdee6be91f6913938f.tar.gz
rust-8f3b4f94ef739b9ad7d4f3cdee6be91f6913938f.zip
Add a IsIdentity extension trait for CanonicalUserType
-rw-r--r--compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs4
-rw-r--r--compiler/rustc_middle/src/ty/mod.rs4
-rw-r--r--compiler/rustc_middle/src/ty/typeck_results.rs10
3 files changed, 11 insertions, 7 deletions
diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
index 82e9bd50cc8..b5a07f0d3e9 100644
--- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
+++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
@@ -26,7 +26,7 @@ use rustc_middle::ty::error::TypeError;
 use rustc_middle::ty::fold::TypeFoldable;
 use rustc_middle::ty::visit::{TypeVisitable, TypeVisitableExt};
 use rustc_middle::ty::{
-    self, AdtKind, CanonicalUserType, GenericParamDefKind, Ty, TyCtxt, UserType,
+    self, AdtKind, CanonicalUserType, GenericParamDefKind, IsIdentity, Ty, TyCtxt, UserType,
 };
 use rustc_middle::ty::{GenericArgKind, GenericArgsRef, UserArgs, UserSelfTy};
 use rustc_session::lint;
@@ -208,7 +208,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         debug!("fcx {}", self.tag());
 
         // FIXME: is_identity being on `UserType` and not `Canonical<UserType>` is awkward
-        if !canonical_user_type_annotation.value.is_identity() {
+        if !canonical_user_type_annotation.is_identity() {
             self.typeck_results
                 .borrow_mut()
                 .user_provided_types_mut()
diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs
index cc0db39ac57..5d6d46e16b7 100644
--- a/compiler/rustc_middle/src/ty/mod.rs
+++ b/compiler/rustc_middle/src/ty/mod.rs
@@ -106,8 +106,8 @@ pub use self::sty::{
 };
 pub use self::trait_def::TraitDef;
 pub use self::typeck_results::{
-    CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, TypeckResults,
-    UserType, UserTypeAnnotationIndex,
+    CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, IsIdentity,
+    TypeckResults, UserType, UserTypeAnnotationIndex,
 };
 
 pub mod _match;
diff --git a/compiler/rustc_middle/src/ty/typeck_results.rs b/compiler/rustc_middle/src/ty/typeck_results.rs
index 51f36e282e2..58ad1eb900f 100644
--- a/compiler/rustc_middle/src/ty/typeck_results.rs
+++ b/compiler/rustc_middle/src/ty/typeck_results.rs
@@ -607,11 +607,15 @@ pub enum UserType<'tcx> {
     TypeOf(DefId, UserArgs<'tcx>),
 }
 
-impl<'tcx> UserType<'tcx> {
+pub trait IsIdentity {
+    fn is_identity(&self) -> bool;
+}
+
+impl<'tcx> IsIdentity for CanonicalUserType<'tcx> {
     /// Returns `true` if this represents a substitution of the form `[?0, ?1, ?2]`,
     /// i.e., each thing is mapped to a canonical variable with the same index.
-    pub fn is_identity(&self) -> bool {
-        match self {
+    fn is_identity(&self) -> bool {
+        match self.value {
             UserType::Ty(_) => false,
             UserType::TypeOf(_, user_args) => {
                 if user_args.user_self_ty.is_some() {