]> git.lizzy.rs Git - rust.git/commitdiff
visit impl self ty + trait
authorBastian Kauschke <bastian_kauschke@hotmail.de>
Tue, 22 Sep 2020 09:55:03 +0000 (11:55 +0200)
committerBastian Kauschke <bastian_kauschke@hotmail.de>
Thu, 24 Sep 2020 07:04:26 +0000 (09:04 +0200)
compiler/rustc_typeck/src/collect.rs
src/test/ui/const-generics/const_evaluatable_checked/impl-bounds.rs [new file with mode: 0644]

index d341e7eec41a34466144c7cdcb802168a21a2950..a571bd58abc34706a3b9908c2b6bc9efb5097abf 100644 (file)
@@ -2098,6 +2098,18 @@ fn visit_const(&mut self, ct: &'tcx Const<'tcx>) -> bool {
     let node = tcx.hir().get(hir_id);
 
     let mut collector = ConstCollector { tcx, preds: FxIndexSet::default() };
+    if let hir::Node::Item(item) = node {
+        if let hir::ItemKind::Impl { ref of_trait, ref self_ty, .. } = item.kind {
+            if let Some(of_trait) = of_trait {
+                warn!("const_evaluatable_predicates_of({:?}): visit impl trait_ref", def_id);
+                collector.visit_trait_ref(of_trait);
+            }
+
+            warn!("const_evaluatable_predicates_of({:?}): visit_self_ty", def_id);
+            collector.visit_ty(self_ty);
+        }
+    }
+
     if let Some(generics) = node.generics() {
         warn!("const_evaluatable_predicates_of({:?}): visit_generics", def_id);
         collector.visit_generics(generics);
diff --git a/src/test/ui/const-generics/const_evaluatable_checked/impl-bounds.rs b/src/test/ui/const-generics/const_evaluatable_checked/impl-bounds.rs
new file mode 100644 (file)
index 0000000..193a365
--- /dev/null
@@ -0,0 +1,25 @@
+// check-pass
+#![feature(const_generics, const_evaluatable_checked)]
+#![allow(incomplete_features)]
+
+use std::mem::size_of;
+
+struct Foo<T, const N: usize>(T);
+
+impl<T> Foo<T, { size_of::<T>() }> {
+    fn test() {
+        let _: [u8; std::mem::size_of::<T>()];
+    }
+}
+
+trait Bar<const N: usize> {
+    fn test_me();
+}
+
+impl<T> Bar<{ size_of::<T>() }> for Foo<T, 3> {
+    fn test_me() {
+        let _: [u8; std::mem::size_of::<T>()];
+    }
+}
+
+fn main() {}