>>685
リスコフの置換原則は設計的な原則だから言語仕様で違反を防ぐことはできないぞ
悪名高い長方形・正方形の問題はトレイトがあっても起こり得る

trait Rectangle {
 fn set_width(&mut self, width: i32);
 fn set_height(&mut self, height: i32);
 fn width(&self) -> i32;
 fn height(&self) -> i32;
 fn area(&self) -> i32 { self.width() * self.height() }
}

struct Square { len: i32 }

impl Rectangle for Square {
 fn set_width(&mut self, width: i32) { self.len = width; }
 fn set_height(&mut self, height: i32) { self.len = width; }
 fn width(&self) -> i32 { self.len }
 fn height(&self) -> i32 { self.len }
}

fn func(x: &mut impl Rectangle) {
 x.set_width(3);
 x.set_height(4);

 // xが長方形であれば以下が成り立つはずだが、Square型を渡された場合に失敗する
 assert!(x.area() == 12);
}