-
Notifications
You must be signed in to change notification settings - Fork 32
/
type-unsatisfiable.rs
71 lines (59 loc) · 1.51 KB
/
type-unsatisfiable.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//@ revisions: lib usage
//@[lib] compile-flags: --crate-type=lib
//@[lib] build-pass
use std::ops::Sub;
trait Vector2 {
type ScalarType;
fn from_values(x: Self::ScalarType, y: Self::ScalarType) -> Self
where
Self: Sized;
fn x(&self) -> Self::ScalarType;
fn y(&self) -> Self::ScalarType;
}
impl<T> Sub for dyn Vector2<ScalarType = T>
where
T: Sub<Output = T>,
(dyn Vector2<ScalarType = T>): Sized,
{
type Output = dyn Vector2<ScalarType = T>;
fn sub(self, rhs: Self) -> Self::Output {
Self::from_values(self.x() - rhs.x(), self.y() - rhs.y())
}
}
struct Vec2 {
x: i32,
y: i32,
}
impl Vector2 for Vec2 {
type ScalarType = i32;
fn from_values(x: Self::ScalarType, y: Self::ScalarType) -> Self
where
Self: Sized,
{
Self { x, y }
}
fn x(&self) -> Self::ScalarType {
self.x
}
fn y(&self) -> Self::ScalarType {
self.y
}
}
#[cfg(usage)]
fn main() {
let hey: Box<dyn Vector2<ScalarType = i32>> = Box::new(Vec2 { x: 1, y: 2 });
let word: Box<dyn Vector2<ScalarType = i32>> = Box::new(Vec2 { x: 1, y: 2 });
let bar = *hey - *word;
//[usage]~^ ERROR cannot subtract
}
// ferrocene-annotations: fls_qa98qdi42orq
// Trait Object Types
// ferrocene-annotations: fls_1k9mkv7rbezi
// Arithmetic Expressions
// ferrocene-annotations: fls_jeoas4n6su4
// Trait and Lifetime Bounds
// ferrocene-annotations: fls_7nv8ualeaqe3
// Where Clauses
//
// ferrocene-annotations: fls_zfibijmf8qe1
// Arithmetic Overflow