Skip to content

Commit

Permalink
visit impl self ty + trait
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed Sep 24, 2020
1 parent b8402d6 commit 3f9015b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
12 changes: 12 additions & 0 deletions compiler/rustc_typeck/src/collect.rs
Expand Up @@ -2098,6 +2098,18 @@ fn const_evaluatable_predicates_of<'tcx>(
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);
Expand Down
@@ -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() {}

0 comments on commit 3f9015b

Please sign in to comment.