make Sized
coinductive
This commit is contained in:
parent
a3c0a02361
commit
0f2e45b18f
3 changed files with 46 additions and 1 deletions
|
@ -959,7 +959,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
|
|
||||||
fn coinductive_predicate(&self, predicate: ty::Predicate<'tcx>) -> bool {
|
fn coinductive_predicate(&self, predicate: ty::Predicate<'tcx>) -> bool {
|
||||||
let result = match predicate.kind().skip_binder() {
|
let result = match predicate.kind().skip_binder() {
|
||||||
ty::PredicateKind::Trait(ref data) => self.tcx().trait_is_auto(data.def_id()),
|
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::WellFormed(_) => true,
|
ty::PredicateKind::WellFormed(_) => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
|
|
14
src/test/ui/sized/coinductive-1.rs
Normal file
14
src/test/ui/sized/coinductive-1.rs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
// check-pass
|
||||||
|
struct Node<C: Trait<Self>>(C::Assoc);
|
||||||
|
|
||||||
|
trait Trait<T> {
|
||||||
|
type Assoc;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Trait<T> for Vec<()> {
|
||||||
|
type Assoc = Vec<T>;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _ = Node::<Vec<()>>(Vec::new());
|
||||||
|
}
|
28
src/test/ui/sized/coinductive-2.rs
Normal file
28
src/test/ui/sized/coinductive-2.rs
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
// run-pass
|
||||||
|
struct Node<C: CollectionFactory<Self>> {
|
||||||
|
_children: C::Collection,
|
||||||
|
}
|
||||||
|
|
||||||
|
trait CollectionFactory<T> {
|
||||||
|
type Collection;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> CollectionFactory<T> for Vec<()> {
|
||||||
|
type Collection = Vec<T>;
|
||||||
|
}
|
||||||
|
|
||||||
|
trait Collection<T>: Sized {
|
||||||
|
fn push(&mut self, v: T);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Collection<T> for Vec<T> {
|
||||||
|
fn push(&mut self, v: T) {
|
||||||
|
self.push(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _ = Node::<Vec<()>> {
|
||||||
|
_children: Vec::new(),
|
||||||
|
};
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue