[Pre-RFC] Allowing generic impls of external traits when bounds prevent re-impl


#1

Hi all, new to the forum/process so bear with me.

Let’s start with an example:

trait CenterOriginRect {
  fn center(&self) -> Point;
  fn width(&self) -> Meters;
  fn height(&self) -> Meters;
}

impl CenterOriginRect for Room {
  fn center(&self) -> Point { self.center }
  fn width(&self) -> f32 { self.width }
  fn height(&self) -> f32 { self.height }
}

impl<'a, T: CenterOriginRect> From<&'a T> for Rect {
  fn from(r: &T) -> Rect {
    Rect {
      x: r.center().x - r.width() / 2.0,
      y: r.center().y - r.height() / 2.0,
      w: r.width(),
      h: r.height(),
    }
  }
}

Trying to compile this will result my least favorite error, E0210 (type parameter T must be used as the type parameter for some local type (e.g. MyStruct<T>); only traits defined in the current crate can be implemented for a type parameter).

However, I think, and correct me if I’m wrong, this is impossble because CenterOriginRect is not public. No one could collide with this implementation because of the bounds.

Is that statement true? If so, this feels like it could be a straightforward usability win.