about summary refs log tree commit diff
path: root/compiler/rustc_middle/src
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2024-12-11 22:18:39 +0000
committerMichael Goulet <michael@errs.io>2024-12-14 03:21:24 +0000
commitd714a22e7bc38b158d09ee6294d1716acd1a727d (patch)
tree29358e67e8018e8436f8798c6fa9a6909c43ddea /compiler/rustc_middle/src
parent1da411e750c7350d8a639ef9fbc73f29c2c1a856 (diff)
downloadrust-d714a22e7bc38b158d09ee6294d1716acd1a727d.tar.gz
rust-d714a22e7bc38b158d09ee6294d1716acd1a727d.zip
(Re-)Implement impl_trait_in_bindings
Diffstat (limited to 'compiler/rustc_middle/src')
-rw-r--r--compiler/rustc_middle/src/query/plumbing.rs2
-rw-r--r--compiler/rustc_middle/src/ty/typeck_results.rs23
2 files changed, 19 insertions, 6 deletions
diff --git a/compiler/rustc_middle/src/query/plumbing.rs b/compiler/rustc_middle/src/query/plumbing.rs
index f4135d8dbc6..3337f7ceee7 100644
--- a/compiler/rustc_middle/src/query/plumbing.rs
+++ b/compiler/rustc_middle/src/query/plumbing.rs
@@ -323,7 +323,7 @@ macro_rules! define_callbacks {
                 // Increase this limit if necessary, but do try to keep the size low if possible
                 #[cfg(target_pointer_width = "64")]
                 const _: () = {
-                    if mem::size_of::<Key<'static>>() > 80 {
+                    if mem::size_of::<Key<'static>>() > 88 {
                         panic!("{}", concat!(
                             "the query `",
                             stringify!($name),
diff --git a/compiler/rustc_middle/src/ty/typeck_results.rs b/compiler/rustc_middle/src/ty/typeck_results.rs
index 744a7384e8b..551c113aa59 100644
--- a/compiler/rustc_middle/src/ty/typeck_results.rs
+++ b/compiler/rustc_middle/src/ty/typeck_results.rs
@@ -704,11 +704,18 @@ pub type CanonicalUserType<'tcx> = Canonical<'tcx, UserType<'tcx>>;
 #[derive(Eq, Hash, HashStable, TypeFoldable, TypeVisitable)]
 pub struct UserType<'tcx> {
     pub kind: UserTypeKind<'tcx>,
+    pub bounds: ty::Clauses<'tcx>,
 }
 
 impl<'tcx> UserType<'tcx> {
     pub fn new(kind: UserTypeKind<'tcx>) -> UserType<'tcx> {
-        UserType { kind }
+        UserType { kind, bounds: ty::ListWithCachedTypeInfo::empty() }
+    }
+
+    /// A user type annotation with additional bounds that need to be enforced.
+    /// These bounds are lowered from `impl Trait` in bindings.
+    pub fn new_with_bounds(kind: UserTypeKind<'tcx>, bounds: ty::Clauses<'tcx>) -> UserType<'tcx> {
+        UserType { kind, bounds }
     }
 }
 
@@ -733,7 +740,9 @@ impl<'tcx> IsIdentity for CanonicalUserType<'tcx> {
     /// Returns `true` if this represents the generic parameters of the form `[?0, ?1, ?2]`,
     /// i.e., each thing is mapped to a canonical variable with the same index.
     fn is_identity(&self) -> bool {
-        // TODO:
+        if !self.value.bounds.is_empty() {
+            return false;
+        }
 
         match self.value.kind {
             UserTypeKind::Ty(_) => false,
@@ -779,9 +788,13 @@ impl<'tcx> IsIdentity for CanonicalUserType<'tcx> {
 
 impl<'tcx> std::fmt::Display for UserType<'tcx> {
     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
-        // TODO:
-
-        self.kind.fmt(f)
+        if self.bounds.is_empty() {
+            self.kind.fmt(f)
+        } else {
+            self.kind.fmt(f)?;
+            write!(f, " + ")?;
+            std::fmt::Debug::fmt(&self.bounds, f)
+        }
     }
 }