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+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: type ascriptions are not allowed in lvalue contexts
2+
--> $DIR/unsound-type-ascription-coercion.rs:10:16
3+
|
4+
LL | let p = &mut (arg1 : &'b u32);
5+
| ^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
error: language item required, but not found: `panic_info`
22

3-
error: aborting due to previous error
3+
error: requires `copy` lang_item
4+
5+
error: aborting due to 2 previous errors
46

src/test/ui/raw-ref-op/raw-ref-temp.stderr

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,30 @@ error[E0745]: cannot take address of a temporary
9494
LL | let ascribe_index_ref = &raw mut (ARRAY[0]: i32);
9595
| ^^^^^^^^^^^^^^^ temporary value
9696

97-
error: aborting due to 16 previous errors
97+
error: type ascriptions are not allowed in lvalue contexts
98+
--> $DIR/raw-ref-temp.rs:26:34
99+
|
100+
LL | let ref_ascribe = &raw const (2: i32);
101+
| ^^^^^^^^
102+
103+
error: type ascriptions are not allowed in lvalue contexts
104+
--> $DIR/raw-ref-temp.rs:27:36
105+
|
106+
LL | let mut_ref_ascribe = &raw mut (3: i32);
107+
| ^^^^^^^^
108+
109+
error: type ascriptions are not allowed in lvalue contexts
110+
--> $DIR/raw-ref-temp.rs:29:40
111+
|
112+
LL | let ascribe_field_ref = &raw const (PAIR.0: i32);
113+
| ^^^^^^^^^^^^^
114+
115+
error: type ascriptions are not allowed in lvalue contexts
116+
--> $DIR/raw-ref-temp.rs:30:38
117+
|
118+
LL | let ascribe_index_ref = &raw mut (ARRAY[0]: i32);
119+
| ^^^^^^^^^^^^^^^
120+
121+
error: aborting due to 20 previous errors
98122

99123
For more information about this error, try `rustc --explain E0745`.

src/test/ui/type-ascription/as_ref.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#![feature(type_ascription)]
2+
3+
use std::convert::AsRef;
4+
5+
struct Foo {
6+
a : u32,
7+
}
8+
9+
impl AsRef<Foo> for Foo {
10+
fn as_ref(&self) -> &Foo {
11+
&self
12+
}
13+
}
14+
15+
fn main() {
16+
let foo = Foo { a : 1 };
17+
let r = &mut foo;
18+
19+
let x = (r : &Foo).as_ref();
20+
//~^ ERROR: type ascriptions are not
21+
22+
let another_one = (r : &Foo).as_ref().a;
23+
//~^ ERROR: type ascriptions are not
24+
25+
let last_one = &*((r : &Foo).as_ref());
26+
//~^ ERROR: type ascriptions are not
27+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
error: type ascriptions are not allowed in lvalue contexts
2+
--> $DIR/as_ref.rs:19:11
3+
|
4+
LL | let x = (r : &Foo).as_ref();
5+
| ^^^^^^^^^^
6+
|
7+
help: try to use the type ascription when creating the local variable
8+
|
9+
LL | let r: &Foo = &mut foo;
10+
| ^^^^^^^^^^^
11+
12+
error: type ascriptions are not allowed in lvalue contexts
13+
--> $DIR/as_ref.rs:22:21
14+
|
15+
LL | let another_one = (r : &Foo).as_ref().a;
16+
| ^^^^^^^^^^
17+
|
18+
help: try to use the type ascription when creating the local variable
19+
|
20+
LL | let r: &Foo = &mut foo;
21+
| ^^^^^^^^^^^
22+
23+
error: type ascriptions are not allowed in lvalue contexts
24+
--> $DIR/as_ref.rs:25:21
25+
|
26+
LL | let last_one = &*((r : &Foo).as_ref());
27+
| ^^^^^^^^^^
28+
|
29+
help: try to use the type ascription when creating the local variable
30+
|
31+
LL | let r: &Foo = &mut foo;
32+
| ^^^^^^^^^^^
33+
34+
error: type ascriptions are not allowed in lvalue contexts
35+
--> $DIR/as_ref.rs:25:21
36+
|
37+
LL | let last_one = &*((r : &Foo).as_ref());
38+
| ^^^^^^^^^^
39+
|
40+
help: try to use the type ascription when creating the local variable
41+
|
42+
LL | let r: &Foo = &mut foo;
43+
| ^^^^^^^^^^^
44+
45+
error: aborting due to 4 previous errors
46+

src/test/ui/type-ascription/assign.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![feature(type_ascription)]
2+
3+
fn main() {
4+
let arr1 = [4,5,6];
5+
let arr2 = [2,2,2];
6+
let mut x = &arr1;
7+
x : &[u32] = &arr2;
8+
//~^ ERROR type ascriptions are not allowed
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: type ascriptions are not allowed in lvalue contexts
2+
--> $DIR/assign.rs:7:3
3+
|
4+
LL | x : &[u32] = &arr2;
5+
| ^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#![feature(type_ascription)]
2+
3+
struct Foo<'a> {
4+
a : &'a [u32],
5+
}
6+
7+
impl Foo<'_> {
8+
fn foo_that<'a>(&self, p : &'a [u32]) {}
9+
}
10+
11+
12+
fn main() {
13+
let arr = [4,5,6];
14+
let r = &arr;
15+
let foo = Foo {a : (r : &[u32]) };
16+
//~^ ERROR: type ascriptions are not
17+
18+
let fooer = Foo {a : r};
19+
fooer.foo_that(r : &[u32]);
20+
//~^ ERROR: type ascriptions are not
21+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error: type ascriptions are not allowed in lvalue contexts
2+
--> $DIR/automatic_reborrows.rs:15:22
3+
|
4+
LL | let foo = Foo {a : (r : &[u32]) };
5+
| ^^^^^^^^^^^^
6+
|
7+
help: try to use the type ascription when creating the local variable
8+
|
9+
LL | let r: &[u32] = &arr;
10+
| ^^^^^^^^^^^^^
11+
12+
error: type ascriptions are not allowed in lvalue contexts
13+
--> $DIR/automatic_reborrows.rs:19:18
14+
|
15+
LL | fooer.foo_that(r : &[u32]);
16+
| ^^^^^^^^^^
17+
|
18+
help: try to use the type ascription when creating the local variable
19+
|
20+
LL | let r: &[u32] = &arr;
21+
| ^^^^^^^^^^^^^
22+
23+
error: aborting due to 2 previous errors
24+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![feature(type_ascription)]
2+
3+
struct Foo {}
4+
5+
impl Foo {
6+
fn foo(&self) {}
7+
}
8+
9+
fn main() {
10+
let mut fooer = Foo {};
11+
let x = &mut fooer;
12+
(x : &Foo).foo();
13+
//~^ ERROR: type ascriptions are not allowed
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error: type ascriptions are not allowed in lvalue contexts
2+
--> $DIR/autoref-method.rs:12:3
3+
|
4+
LL | (x : &Foo).foo();
5+
| ^^^^^^^^^^
6+
|
7+
help: try to use the type ascription when creating the local variable
8+
|
9+
LL | let x: &Foo = &mut fooer;
10+
| ^^^^^^^^^^^
11+
12+
error: aborting due to previous error
13+

src/test/ui/type-ascription/borrow.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#![feature(type_ascription)]
2+
3+
struct Foo {
4+
a : u32,
5+
}
6+
7+
fn main() {
8+
let foo = Foo { a : 1 };
9+
let r = &mut foo;
10+
11+
let x = &(r : &Foo);
12+
//~^ ERROR: type ascriptions are not
13+
14+
let another_one = &(r : &Foo).a;
15+
//~^ ERROR: type ascriptions are not
16+
17+
let arr = [4,5,6];
18+
let arr_ref = &arr;
19+
let ref last_one = &(arr_ref : &[u32])[1];
20+
//~^ ERROR: type ascriptions are not
21+
}

0 commit comments

Comments
 (0)