]> git.lizzy.rs Git - rust.git/blob - src/test/ui/type/type-unsatisfiable.rs
Auto merge of #99443 - jam1garner:mips-virt-feature, r=nagisa
[rust.git] / src / test / ui / type / type-unsatisfiable.rs
1 // revisions: lib usage
2 //[lib] compile-flags: --crate-type=lib
3 //[lib] build-pass
4
5 use std::ops::Sub;
6 trait Vector2 {
7     type ScalarType;
8
9     fn from_values(x: Self::ScalarType, y: Self::ScalarType) -> Self
10     where
11         Self: Sized;
12
13     fn x(&self) -> Self::ScalarType;
14     fn y(&self) -> Self::ScalarType;
15 }
16
17 impl<T> Sub for dyn Vector2<ScalarType = T>
18 where
19     T: Sub<Output = T>,
20     (dyn Vector2<ScalarType = T>): Sized,
21 {
22     type Output = dyn Vector2<ScalarType = T>;
23
24     fn sub(self, rhs: Self) -> Self::Output {
25         Self::from_values(self.x() - rhs.x(), self.y() - rhs.y())
26     }
27 }
28
29 struct Vec2 {
30     x: i32,
31     y: i32,
32 }
33
34 impl Vector2 for Vec2 {
35     type ScalarType = i32;
36
37     fn from_values(x: Self::ScalarType, y: Self::ScalarType) -> Self
38     where
39         Self: Sized,
40     {
41         Self { x, y }
42     }
43
44     fn x(&self) -> Self::ScalarType {
45         self.x
46     }
47     fn y(&self) -> Self::ScalarType {
48         self.y
49     }
50 }
51
52 #[cfg(usage)]
53 fn main() {
54     let hey: Box<dyn Vector2<ScalarType = i32>> = Box::new(Vec2 { x: 1, y: 2 });
55     let word: Box<dyn Vector2<ScalarType = i32>> = Box::new(Vec2 { x: 1, y: 2 });
56
57     let bar = *hey - *word;
58     //[usage]~^ ERROR cannot subtract
59 }