From 3e5686340d7ce38414bdf2acc1d0de96c8b1bc39 Mon Sep 17 00:00:00 2001 From: rustbot <47979223+rustbot@users.noreply.github.com> Date: Tue, 8 Dec 2020 00:06:12 +0100 Subject: [PATCH] Add ICE reproduction for issue rust-lang/rust#79768. --- ices/79768.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 ices/79768.rs diff --git a/ices/79768.rs b/ices/79768.rs new file mode 100644 index 00000000..763bc1e8 --- /dev/null +++ b/ices/79768.rs @@ -0,0 +1,40 @@ +#![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: Monad; + + fn bind(self, f: F) -> Self::Plug + where + F: Fn(Self::Unplug) -> Self::Plug; +} + +impl Monad for Option { + type Unplug = A; + type Plug = Option; + fn bind(self, f: F) -> Option + where + F: Fn(A) -> Option, + { + self.and_then(f) + } +} + +// This function causes the compiler error, specifically, when i added the Plug = P constraint. +fn stringify(m: M1) -> M1::Plug

+where + T: core::fmt::Display, + M1: Monad, +{ + m.bind(|x| format!("{}", x)) +} + +fn main() { + let x = Some(1).bind(|x| Some(x * 2)); + println!("{:?}", x); +} \ No newline at end of file