Trait with another type trait bound in where clause - compilation failed

I expected this to work, but compilation fails:

use core::ops::{Add, AddAssign};

pub trait Add1
    Self: Sized,
    Self: Add<Self, Output = Self>,
    for<'a> &'a Self: Add<Self, Output = Self>,
    for<'b> Self: Add<&'b Self, Output = Self>,
    for<'c, 'd> &'c Self: Add<&'d Self, Output = Self>,
    Self: AddAssign<Self>,
    for<'e> Self: AddAssign<&'e Self>,

fn foo<T: Add1>(a: &T, b: &T) {

It is obviously some sort of limitation. But is it temporary, or it is by-design? Can anyone provide links to related issues?

This is a known issue, and there are plans to fix it eventually: where clauses are only elaborated for supertraits, and not other things · Issue #20671 · rust-lang/rust · GitHub

See this recent thread for some more information: Fn requires to duplicate trait bounds from a trait

1 Like


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.