Skip to content

Commit 3f9015b

Browse files
committed
visit impl self ty + trait
1 parent b8402d6 commit 3f9015b

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

compiler/rustc_typeck/src/collect.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,6 +2098,18 @@ fn const_evaluatable_predicates_of<'tcx>(
20982098
let node = tcx.hir().get(hir_id);
20992099

21002100
let mut collector = ConstCollector { tcx, preds: FxIndexSet::default() };
2101+
if let hir::Node::Item(item) = node {
2102+
if let hir::ItemKind::Impl { ref of_trait, ref self_ty, .. } = item.kind {
2103+
if let Some(of_trait) = of_trait {
2104+
warn!("const_evaluatable_predicates_of({:?}): visit impl trait_ref", def_id);
2105+
collector.visit_trait_ref(of_trait);
2106+
}
2107+
2108+
warn!("const_evaluatable_predicates_of({:?}): visit_self_ty", def_id);
2109+
collector.visit_ty(self_ty);
2110+
}
2111+
}
2112+
21012113
if let Some(generics) = node.generics() {
21022114
warn!("const_evaluatable_predicates_of({:?}): visit_generics", def_id);
21032115
collector.visit_generics(generics);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// check-pass
2+
#![feature(const_generics, const_evaluatable_checked)]
3+
#![allow(incomplete_features)]
4+
5+
use std::mem::size_of;
6+
7+
struct Foo<T, const N: usize>(T);
8+
9+
impl<T> Foo<T, { size_of::<T>() }> {
10+
fn test() {
11+
let _: [u8; std::mem::size_of::<T>()];
12+
}
13+
}
14+
15+
trait Bar<const N: usize> {
16+
fn test_me();
17+
}
18+
19+
impl<T> Bar<{ size_of::<T>() }> for Foo<T, 3> {
20+
fn test_me() {
21+
let _: [u8; std::mem::size_of::<T>()];
22+
}
23+
}
24+
25+
fn main() {}

0 commit comments

Comments
 (0)