-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require exact type equality + add tests
+ Rebase fixes
- Loading branch information
1 parent
e0ceef5
commit 95fdaf2
Showing
9 changed files
with
188 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// A version of coerce-expect-unsized that uses type ascription. | ||
// Doesn't work so far, but supposed to work eventually | ||
|
||
#![feature(box_syntax, type_ascription)] | ||
|
||
use std::fmt::Debug; | ||
|
||
pub fn main() { | ||
let _ = box { [1, 2, 3] }: Box<[i32]>; //~ ERROR mismatched types | ||
let _ = box if true { [1, 2, 3] } else { [1, 3, 4] }: Box<[i32]>; //~ ERROR mismatched types | ||
let _ = box match true { true => [1, 2, 3], false => [1, 3, 4] }: Box<[i32]>; | ||
//~^ ERROR mismatched types | ||
let _ = box { |x| (x as u8) }: Box<Fn(i32) -> _>; //~ ERROR mismatched types | ||
let _ = box if true { false } else { true }: Box<Debug>; //~ ERROR mismatched types | ||
let _ = box match true { true => 'a', false => 'b' }: Box<Debug>; //~ ERROR mismatched types | ||
|
||
let _ = &{ [1, 2, 3] }: &[i32]; //~ ERROR mismatched types | ||
let _ = &if true { [1, 2, 3] } else { [1, 3, 4] }: &[i32]; //~ ERROR mismatched types | ||
let _ = &match true { true => [1, 2, 3], false => [1, 3, 4] }: &[i32]; | ||
//~^ ERROR mismatched types | ||
let _ = &{ |x| (x as u8) }: &Fn(i32) -> _; //~ ERROR mismatched types | ||
let _ = &if true { false } else { true }: &Debug; //~ ERROR mismatched types | ||
let _ = &match true { true => 'a', false => 'b' }: &Debug; //~ ERROR mismatched types | ||
|
||
let _ = Box::new([1, 2, 3]): Box<[i32]>; //~ ERROR mismatched types | ||
let _ = Box::new(|x| (x as u8)): Box<Fn(i32) -> _>; //~ ERROR mismatched types | ||
|
||
let _ = vec![ | ||
Box::new(|x| (x as u8)), | ||
box |x| (x as i16 as u8), | ||
]: Vec<Box<Fn(i32) -> _>>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Operator precedence of type ascription | ||
// Type ascription has very high precedence, the same as operator `as` | ||
|
||
#![feature(type_ascription)] | ||
|
||
use std::ops::*; | ||
|
||
struct S; | ||
struct Z; | ||
|
||
impl Add<Z> for S { | ||
type Output = S; | ||
fn add(self, _rhs: Z) -> S { panic!() } | ||
} | ||
impl Mul<Z> for S { | ||
type Output = S; | ||
fn mul(self, _rhs: Z) -> S { panic!() } | ||
} | ||
impl Neg for S { | ||
type Output = Z; | ||
fn neg(self) -> Z { panic!() } | ||
} | ||
impl Deref for S { | ||
type Target = Z; | ||
fn deref(&self) -> &Z { panic!() } | ||
} | ||
|
||
fn main() { | ||
&S: &S; // OK | ||
(&S): &S; // OK | ||
&(S: &S); //~ ERROR mismatched types | ||
|
||
*S: Z; // OK | ||
(*S): Z; // OK | ||
*(S: Z); //~ ERROR mismatched types | ||
//~^ ERROR type `Z` cannot be dereferenced | ||
|
||
-S: Z; // OK | ||
(-S): Z; // OK | ||
-(S: Z); //~ ERROR mismatched types | ||
//~^ ERROR cannot apply unary operator `-` to type `Z` | ||
|
||
S + Z: Z; // OK | ||
S + (Z: Z); // OK | ||
(S + Z): Z; //~ ERROR mismatched types | ||
|
||
S * Z: Z; // OK | ||
S * (Z: Z); // OK | ||
(S * Z): Z; //~ ERROR mismatched types | ||
|
||
S .. S: S; // OK | ||
S .. (S: S); // OK | ||
(S .. S): S; //~ ERROR mismatched types | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Type ascription doesn't lead to unsoundness | ||
|
||
#![feature(type_ascription)] | ||
|
||
fn main() { | ||
let arr = &[1u8, 2, 3]; | ||
let ref x = arr: &[u8]; //~ ERROR mismatched types | ||
let ref mut x = arr: &[u8]; //~ ERROR mismatched types | ||
match arr: &[u8] { //~ ERROR mismatched types | ||
ref x => {} | ||
} | ||
let _len = (arr: &[u8]).len(); //~ ERROR mismatched types | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Type ascription doesn't lead to unsoundness | ||
|
||
#![feature(type_ascription)] | ||
|
||
use std::mem; | ||
|
||
const C1: u8 = 10: u8; | ||
const C2: [u8; 1: usize] = [1]; | ||
|
||
struct S { | ||
a: u8 | ||
} | ||
|
||
fn main() { | ||
assert_eq!(C1.into(): i32, 10); | ||
assert_eq!(C2[0], 1); | ||
|
||
let s = S { a: 10: u8 }; | ||
let arr = &[1u8, 2, 3]; | ||
|
||
let mut v = arr.iter().cloned().collect(): Vec<_>; | ||
v.push(4); | ||
assert_eq!(v, [1, 2, 3, 4]); | ||
|
||
let a = 1: u8; | ||
let b = a.into(): u16; | ||
assert_eq!(v[a.into(): usize], 2); | ||
assert_eq!(mem::size_of_val(&a), 1); | ||
assert_eq!(mem::size_of_val(&b), 2); | ||
assert_eq!(b, 1: u16); | ||
|
||
let mut v = Vec::new(); | ||
v: Vec<u8> = vec![1, 2, 3]; // Lvalue type ascription | ||
assert_eq!(v, [1u8, 2, 3]); | ||
} |