]> git.lizzy.rs Git - rust.git/blob - src/test/ui/type/type-ascription-precedence.rs
Auto merge of #54720 - davidtwco:issue-51191, r=nikomatsakis
[rust.git] / src / test / ui / type / type-ascription-precedence.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Operator precedence of type ascription
12 // Type ascription has very high precedence, the same as operator `as`
13
14 #![feature(type_ascription)]
15
16 use std::ops::*;
17
18 struct S;
19 struct Z;
20
21 impl Add<Z> for S {
22     type Output = S;
23     fn add(self, _rhs: Z) -> S { panic!() }
24 }
25 impl Mul<Z> for S {
26     type Output = S;
27     fn mul(self, _rhs: Z) -> S { panic!() }
28 }
29 impl Neg for S {
30     type Output = Z;
31     fn neg(self) -> Z { panic!() }
32 }
33 impl Deref for S {
34     type Target = Z;
35     fn deref(&self) -> &Z { panic!() }
36 }
37
38 fn main() {
39     &S: &S; // OK
40     (&S): &S; // OK
41     &(S: &S); //~ ERROR mismatched types
42
43     *S: Z; // OK
44     (*S): Z; // OK
45     *(S: Z); //~ ERROR mismatched types
46     //~^ ERROR type `Z` cannot be dereferenced
47
48     -S: Z; // OK
49     (-S): Z; // OK
50     -(S: Z); //~ ERROR mismatched types
51     //~^ ERROR cannot apply unary operator `-` to type `Z`
52
53     S + Z: Z; // OK
54     S + (Z: Z); // OK
55     (S + Z): Z; //~ ERROR mismatched types
56
57     S * Z: Z; // OK
58     S * (Z: Z); // OK
59     (S * Z): Z; //~ ERROR mismatched types
60
61     S .. S: S; // OK
62     S .. (S: S); // OK
63     (S .. S): S; //~ ERROR mismatched types
64 }