Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

ices/87750.rs: fixed with errors #960

Merged
merged 1 commit into from
Sep 4, 2021
Merged

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Sep 3, 2021

Issue: rust-lang/rust#87750

#![feature(generic_associated_types)]
use std::rc::Rc;
use std::ops::Deref;

trait PointerFamily {
    type Pointer<T>: Deref<Target=T> + Sized;

    fn new<T>(obj: T) -> Self::Pointer<T>;
}

#[derive(Debug)]
struct RcFamily;

impl PointerFamily for RcFamily {
    type Pointer<T> = Rc<T>;

    fn new<T>(obj: T) -> Rc<T> {
        Rc::new(obj)
    }
}

#[derive(Debug)]
enum Node<T, P: PointerFamily> where P::Pointer<Node<T, P>>: Sized {
    Cons(T, P::Pointer<Node<T, P>>),
    Nil
}

type List<T, P> = <P as PointerFamily>::Pointer<Node<T, P>>;
type RcList<T> = List<T, RcFamily>;
type RcNode<T> = Node<T, RcFamily>;

impl<T, P: PointerFamily> Node<T, P> where P::Pointer<Node<T, P>>: Sized {
    fn new() -> P::Pointer<Self> {
        P::new(Self::Nil)
    }

    fn cons(head: T, tail: P::Pointer<Self>) -> P::Pointer<Self> {
        P::new(Self::Cons(head, tail))
    }
}

fn main() {
    let mut list: RcList<i32> = RcNode::<i32>::new();
    list = RcNode::<i32>::cons(1, list);
    //println!("{:?}", list);

}
=== stdout ===
=== stderr ===
error[E0599]: the variant or associated item `new` exists for enum `Node<i32, RcFamily>`, but its trait bounds were not satisfied
  --> /home/runner/work/glacier/glacier/ices/87750.rs:43:48
   |
23 | enum Node<T, P: PointerFamily> where P::Pointer<Node<T, P>>: Sized {
   | ------------------------------------------------------------------
   | |
   | variant or associated item `new` not found here
   | doesn't satisfy `Node<i32, RcFamily>: Sized`
...
43 |     let mut list: RcList<i32> = RcNode::<i32>::new();
   |                                                ^^^ variant or associated item cannot be called on `Node<i32, RcFamily>` due to unsatisfied trait bounds
   |
   = note: the following trait bounds were not satisfied:
           `Node<i32, RcFamily>: Sized`

error[E0275]: overflow evaluating the requirement `Node<i32, RcFamily>: Sized`
  --> /home/runner/work/glacier/glacier/ices/87750.rs:43:19
   |
43 |     let mut list: RcList<i32> = RcNode::<i32>::new();
   |                   ^^^^^^^^^^^

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0275, E0599.
For more information about an error, try `rustc --explain E0275`.
==============

=== stdout ===
=== stderr ===
error[E0599]: the variant or associated item `new` exists for enum `Node<i32, RcFamily>`, but its trait bounds were not satisfied
  --> /home/runner/work/glacier/glacier/ices/87750.rs:43:48
   |
23 | enum Node<T, P: PointerFamily> where P::Pointer<Node<T, P>>: Sized {
   | ------------------------------------------------------------------
   | |
   | variant or associated item `new` not found here
   | doesn't satisfy `Node<i32, RcFamily>: Sized`
...
43 |     let mut list: RcList<i32> = RcNode::<i32>::new();
   |                                                ^^^ variant or associated item cannot be called on `Node<i32, RcFamily>` due to unsatisfied trait bounds
   |
   = note: the following trait bounds were not satisfied:
           `Node<i32, RcFamily>: Sized`

error[E0275]: overflow evaluating the requirement `Node<i32, RcFamily>: Sized`
  --> /home/runner/work/glacier/glacier/ices/87750.rs:43:19
   |
43 |     let mut list: RcList<i32> = RcNode::<i32>::new();
   |                   ^^^^^^^^^^^

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0275, E0599.
For more information about an error, try `rustc --explain E0275`.
==============
@Alexendoo Alexendoo merged commit 83a9327 into master Sep 4, 2021
@Alexendoo Alexendoo deleted the autofix/ices/87750.rs branch September 4, 2021 10:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants