Skip to content

Commit 0f2e45b

Browse files
lcnrcompiler-errors
authored andcommitted
make Sized coinductive
1 parent a3c0a02 commit 0f2e45b

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

compiler/rustc_trait_selection/src/traits/select/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
959959

960960
fn coinductive_predicate(&self, predicate: ty::Predicate<'tcx>) -> bool {
961961
let result = match predicate.kind().skip_binder() {
962-
ty::PredicateKind::Trait(ref data) => self.tcx().trait_is_auto(data.def_id()),
962+
ty::PredicateKind::Trait(ref data) => {
963+
self.tcx().trait_is_auto(data.def_id())
964+
|| self.tcx().lang_items().sized_trait() == Some(data.def_id())
965+
}
963966
ty::PredicateKind::WellFormed(_) => true,
964967
_ => false,
965968
};

src/test/ui/sized/coinductive-1.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// check-pass
2+
struct Node<C: Trait<Self>>(C::Assoc);
3+
4+
trait Trait<T> {
5+
type Assoc;
6+
}
7+
8+
impl<T> Trait<T> for Vec<()> {
9+
type Assoc = Vec<T>;
10+
}
11+
12+
fn main() {
13+
let _ = Node::<Vec<()>>(Vec::new());
14+
}

src/test/ui/sized/coinductive-2.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// run-pass
2+
struct Node<C: CollectionFactory<Self>> {
3+
_children: C::Collection,
4+
}
5+
6+
trait CollectionFactory<T> {
7+
type Collection;
8+
}
9+
10+
impl<T> CollectionFactory<T> for Vec<()> {
11+
type Collection = Vec<T>;
12+
}
13+
14+
trait Collection<T>: Sized {
15+
fn push(&mut self, v: T);
16+
}
17+
18+
impl<T> Collection<T> for Vec<T> {
19+
fn push(&mut self, v: T) {
20+
self.push(v)
21+
}
22+
}
23+
24+
fn main() {
25+
let _ = Node::<Vec<()>> {
26+
_children: Vec::new(),
27+
};
28+
}

0 commit comments

Comments
 (0)