This test code (playpen):
use std::fmt::{Display, Formatter, Error};
struct MyLocalType;
type MyResult = Result;
impl Display f
There's no direct way to solve this for a pure alias like type
.
The code is the same as
impl Display for Result
and the compiler can't ensure that there will be no conflicting implementations in other crates (aka, can't ensure that the implementation is 'coherent'). Being able to do it is definitely useful sometimes, but it was unfortunately a bug that the compiler accepted it before.
Solutions include:
Result
, e.g. struct MyResult(Result);
,enum MyResult { Ok(MyType), Err(String) }
,println!("{}", Wrapper(r));
instead of println!("{}", r);
.Both of these make MyResult
a local type, and so the impl
then should be legal.