]> git.lizzy.rs Git - rust.git/blob - src/test/ui/type/type-ascription-precedence.rs
Auto merge of #99443 - jam1garner:mips-virt-feature, r=nagisa
[rust.git] / src / test / ui / type / type-ascription-precedence.rs
1 // Operator precedence of type ascription
2 // Type ascription has very high precedence, the same as operator `as`
3
4 #![feature(type_ascription)]
5
6 use std::ops::*;
7
8 struct S;
9 struct Z;
10
11 impl Add<Z> for S {
12     type Output = S;
13     fn add(self, _rhs: Z) -> S { panic!() }
14 }
15 impl Mul<Z> for S {
16     type Output = S;
17     fn mul(self, _rhs: Z) -> S { panic!() }
18 }
19 impl Neg for S {
20     type Output = Z;
21     fn neg(self) -> Z { panic!() }
22 }
23 impl Deref for S {
24     type Target = Z;
25     fn deref(&self) -> &Z { panic!() }
26 }
27
28 fn main() {
29     &S: &S; // OK
30     (&S): &S; // OK
31     &(S: &S); //~ ERROR mismatched types
32
33     *S: Z; // OK
34     (*S): Z; // OK
35     *(S: Z); //~ ERROR mismatched types
36     //~^ ERROR type `Z` cannot be dereferenced
37
38     -S: Z; // OK
39     (-S): Z; // OK
40     -(S: Z); //~ ERROR mismatched types
41     //~^ ERROR cannot apply unary operator `-` to type `Z`
42
43     S + Z: Z; // OK
44     S + (Z: Z); // OK
45     (S + Z): Z; //~ ERROR mismatched types
46
47     S * Z: Z; // OK
48     S * (Z: Z); // OK
49     (S * Z): Z; //~ ERROR mismatched types
50
51     S .. S: S; // OK
52     S .. (S: S); // OK
53     (S .. S): S; //~ ERROR mismatched types
54 }