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

ices/79768.rs: fixed with errors #645

Merged
merged 1 commit into from
Feb 6, 2021
Merged

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Feb 6, 2021

Issue: rust-lang/rust#79768

#![feature(generic_associated_types)]

trait Monad /* : Applicative (for pure/return, doesn't matter for this example) */ {
    // Self is like the "f a" in haskell

    /// extract the "a" from "f a"
    type Unplug;

    /// exchange the "a" in "f a" in the type of Self with B
    type Plug<B>: Monad;

    fn bind<B, F>(self, f: F) -> Self::Plug<B>
    where
        F: Fn(Self::Unplug) -> Self::Plug<B>;
}

impl<A> Monad for Option<A> {
    type Unplug = A;
    type Plug<B> = Option<B>;
    fn bind<B, F>(self, f: F) -> Option<B>
    where
        F: Fn(A) -> Option<B>,
    {
        self.and_then(f)
    }
}

// This function causes the compiler error, specifically, when i added the Plug = P constraint.
fn stringify<T, M1, P>(m: M1) -> M1::Plug<P>
where
    T: core::fmt::Display,
    M1: Monad<Unplug = T, Plug = P>,
{
    m.bind(|x| format!("{}", x))
}

fn main() {
    let x = Some(1).bind(|x| Some(x * 2));
    println!("{:?}", x);
}
=== stdout ===
=== stderr ===
warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /home/runner/work/glacier/glacier/ices/79768.rs:1:12
  |
1 | #![feature(generic_associated_types)]
  |            ^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information

error[E0107]: missing generics for associated type `Monad::Plug`
  --> /home/runner/work/glacier/glacier/ices/79768.rs:10:10
   |
10 |     type Plug<B>: Monad;
   |          ^^^^ expected 1 type argument
   |
note: associated type defined here, with 1 type parameter: `B`
  --> /home/runner/work/glacier/glacier/ices/79768.rs:10:10
   |
10 |     type Plug<B>: Monad;
   |          ^^^^ -
help: use angle brackets to add missing type argument
   |
10 |     type Plug<B><B>: Monad;
   |              ^^^

error: aborting due to previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0107`.
==============

=== stdout ===
=== stderr ===
warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /home/runner/work/glacier/glacier/ices/79768.rs:1:12
  |
1 | #![feature(generic_associated_types)]
  |            ^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #44265 <rust-lang/rust#44265> for more information

error[E0107]: missing generics for associated type `Monad::Plug`
  --> /home/runner/work/glacier/glacier/ices/79768.rs:10:10
   |
10 |     type Plug<B>: Monad;
   |          ^^^^ expected 1 type argument
   |
note: associated type defined here, with 1 type parameter: `B`
  --> /home/runner/work/glacier/glacier/ices/79768.rs:10:10
   |
10 |     type Plug<B>: Monad;
   |          ^^^^ -
help: use angle brackets to add missing type argument
   |
10 |     type Plug<B><B>: Monad;
   |              ^^^

error: aborting due to previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0107`.
==============
@Alexendoo Alexendoo merged commit 2868c1f into master Feb 6, 2021
@Alexendoo Alexendoo deleted the autofix/ices/79768.rs branch February 6, 2021 13:41
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