Skip to content

Commit d2485ca

Browse files
committed
add tests
1 parent d70f5bc commit d2485ca

27 files changed

+547
-23
lines changed

src/test/ui/associated-types/associated-types-ICE-when-projecting-out-of-err.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ error[E0277]: the trait bound `(): Add<A>` is not satisfied
44
LL | r = r + a;
55
| ^ the trait `Add<A>` is not implemented for `()`
66

7-
error: aborting due to previous error
7+
error: requires `copy` lang_item
8+
9+
error: aborting due to 2 previous errors
810

911
For more information about this error, try `rustc --explain E0277`.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(type_ascription)]
2+
3+
// build-pass
4+
5+
fn foo(_arg : [&[u32];3]) {}
6+
7+
fn main() {
8+
let arr = [4,5,6];
9+
foo([&arr : &[u32]; 3]);
10+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// build-pass
2+
3+
#![feature(type_ascription)]
4+
5+
enum Foo<'a> {
6+
A((u32, &'a [u32])),
7+
B((u32, &'a [u32; 4])),
8+
}
9+
10+
fn main() {
11+
let arr = [4,5,6];
12+
let temp = Foo::A((10, &arr : &[u32]));
13+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// run-pass
2+
3+
#![feature(type_ascription)]
4+
5+
use std::any::type_name;
6+
use std::assert_eq;
7+
8+
fn type_of<T>(_: T) -> &'static str {
9+
type_name::<T>()
10+
}
11+
12+
fn main() {
13+
let arr = [5,6,7];
14+
let tup = (5, (3, (12, &arr : &[u32])), &arr : &[u32]);
15+
assert_eq!(type_of(tup), "(i32, (i32, (i32, &[u32])), &[u32])");
16+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![feature(type_ascription)]
2+
3+
fn foo<'a>(arg : (u32, (u32, &'a [u32; 3]))) -> (u32, (u32, &'a [u32])) {
4+
arg : (u32, (u32, &[u32]))
5+
//~^ ERROR: mismatched types
6+
}
7+
8+
fn main() {
9+
let arr = [4,5,6];
10+
let tup = (3, (9, &arr));
11+
let result = foo(tup);
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/coerce-return-expr.rs:4:3
3+
|
4+
LL | arg : (u32, (u32, &[u32]))
5+
| ^^^ expected slice `[u32]`, found array `[u32; 3]`
6+
|
7+
= note: expected tuple `(_, (_, &[u32]))`
8+
found tuple `(_, (_, &'a [u32; 3]))`
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0308`.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Here we test for coercions in struct fields of nested type ascriptions
2+
// inside a tuple using an unsized coercion and a coercion from &mut -> &
3+
4+
// run-pass
5+
6+
#![feature(type_ascription)]
7+
8+
use std::any::type_name;
9+
use std::assert_eq;
10+
11+
fn type_of<T>(_: T) -> &'static str {
12+
type_name::<T>()
13+
}
14+
15+
struct Foo<'a, 'b, T1, T2> {
16+
_a : (T1, (T1, &'a [T1]), &'b T2),
17+
}
18+
19+
struct Bar {
20+
_b : u32,
21+
}
22+
23+
fn main() {
24+
let mut bar = Bar {_b : 26};
25+
let arr = [4,5,6];
26+
let tup = (9, (3, &arr : &[u32]), &mut bar);
27+
assert_eq!(type_of(tup), "(i32, (i32, &[u32]), &mut coerce_struct_fields_pass_in_let_stmt::Bar)");
28+
let _ = Foo { _a : (9, (3, &arr : &[u32]), &mut bar) };
29+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// build-pass
2+
3+
#![feature(type_ascription)]
4+
5+
fn foo<'a>(arg : &'a [u32; 3]) -> &'a [u32] {
6+
arg : &[u32]
7+
}
8+
9+
fn main() {
10+
let arr = [4,5,6];
11+
let _ = foo(&arr);
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// build-pass
2+
3+
#![feature(type_ascription)]
4+
5+
union Foo<'a> {
6+
f1: (&'a u32, (u32, &'a [u32])),
7+
_f2: u32,
8+
}
9+
10+
fn main() {
11+
let arr = [4,5,6];
12+
let x = &mut 26;
13+
let _ = Foo { f1: (x : &u32, (5, &arr : &[u32])) };
14+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#![feature(type_ascription)]
2+
3+
fn f() {
4+
let mut x: &'static u32 = &22;
5+
let y = &44;
6+
foo(x, y);
7+
}
8+
9+
fn foo<'a, 'b>(arg1 : &'a u32, arg2 : &'b u32) {
10+
let p = &mut (arg1 : &'b u32);
11+
//~^ ERROR: type ascriptions are not allowed
12+
*p = arg2;
13+
}
14+
15+
fn main() {
16+
f();
17+
}

0 commit comments

Comments
 (0)