about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2022-11-10 21:29:20 +0000
committerMichael Goulet <michael@errs.io>2022-11-10 21:29:20 +0000
commitfea8d0eb999dbe732a70cd61518d79195c139b2c (patch)
tree8d86b7043de91534913675d300b3c3d0a2b50151
parent43ad19b2506c4e4ce6204e3ecf8b35869bd76eff (diff)
downloadrust-fea8d0eb999dbe732a70cd61518d79195c139b2c.tar.gz
rust-fea8d0eb999dbe732a70cd61518d79195c139b2c.zip
More nits
-rw-r--r--compiler/rustc_middle/src/ty/mod.rs4
-rw-r--r--compiler/rustc_trait_selection/src/traits/select/mod.rs5
-rw-r--r--src/test/ui/sized/coinductive-1-gat.rs14
3 files changed, 19 insertions, 4 deletions
diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs
index b509ae6dd3b..18eb06b83c9 100644
--- a/compiler/rustc_middle/src/ty/mod.rs
+++ b/compiler/rustc_middle/src/ty/mod.rs
@@ -2506,6 +2506,10 @@ impl<'tcx> TyCtxt<'tcx> {
         self.trait_def(trait_def_id).has_auto_impl
     }
 
+    pub fn trait_is_coinductive(self, trait_def_id: DefId) -> bool {
+        self.trait_is_auto(trait_def_id) || self.lang_items().sized_trait() == Some(trait_def_id)
+    }
+
     /// Returns layout of a generator. Layout might be unavailable if the
     /// generator is tainted by errors.
     pub fn generator_layout(self, def_id: DefId) -> Option<&'tcx GeneratorLayout<'tcx>> {
diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs
index 49bb3d03621..a12f67125bb 100644
--- a/compiler/rustc_trait_selection/src/traits/select/mod.rs
+++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs
@@ -959,10 +959,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
 
     fn coinductive_predicate(&self, predicate: ty::Predicate<'tcx>) -> bool {
         let result = match predicate.kind().skip_binder() {
-            ty::PredicateKind::Trait(ref data) => {
-                self.tcx().trait_is_auto(data.def_id())
-                    || self.tcx().lang_items().sized_trait() == Some(data.def_id())
-            }
+            ty::PredicateKind::Trait(ref data) => self.tcx().trait_is_coinductive(data.def_id()),
             ty::PredicateKind::WellFormed(_) => true,
             _ => false,
         };
diff --git a/src/test/ui/sized/coinductive-1-gat.rs b/src/test/ui/sized/coinductive-1-gat.rs
new file mode 100644
index 00000000000..cdf70920f00
--- /dev/null
+++ b/src/test/ui/sized/coinductive-1-gat.rs
@@ -0,0 +1,14 @@
+// check-pass
+struct Node<C: Trait>(C::Assoc::<Self>);
+
+trait Trait {
+    type Assoc<T>;
+}
+
+impl Trait for Vec<()> {
+    type Assoc<T> = Vec<T>;
+}
+
+fn main() {
+    let _ = Node::<Vec<()>>(Vec::new());
+}