These are chat archives for rust-lang/rust

10th
Jan 2017
Matanel Levi
@matanelevi
Jan 10 2017 11:09
Why this doesnt work?
fn g<T: Add>(x: T) -> T { x + 1 }
There is a use std:ops::Add before
Igor
@target-san
Jan 10 2017 11:41
@matanelevi fn g<T: Add<Rhs=i32>>(x: T) -> T { x + 1 } ?
Matanel Levi
@matanelevi
Jan 10 2017 11:50
@target-san cant it be general? Without the associated type?
Igor
@target-san
Jan 10 2017 11:54
@matanelevi Nope: pub trait Add<RHS = Self> { ... }, RHS is Self by default
Alexander Ronald Altman
@pthariensflame
Jan 10 2017 15:35
If you want:
fn g<T: Add>(x: T) -> T::Output
    where i32: Into<T::Rhs>
{
    x + 1.into()
}
I think that's about as general as you're going to get, though.
Matanel Levi
@matanelevi
Jan 10 2017 20:59
Ok, thanks!
Alexander Ronald Altman
@pthariensflame
Jan 10 2017 21:07
Sorry; the correct version of the above is:
fn g<T, U>(x: T#) -> T::Output
    where T: Add<U>,
          i32: Into<U>
{
    x + 1.into()
}
s/#//1
Leah
@ForsakenHarmony
Jan 10 2017 23:44
is it possible to tell the rust compiler to just expand macros and put the generated code somewhere?