Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions src/test/ui/coercion/coerce-expect-unsized-ascribed.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
// A version of coerce-expect-unsized that uses type ascription.
// Doesn't work so far, but supposed to work eventually

// check-pass

#![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 { [1, 2, 3] }: Box<[i32]>;
let _ = box if true { [1, 2, 3] } else { [1, 3, 4] }: Box<[i32]>;
let _ = box match true { true => [1, 2, 3], false => [1, 3, 4] }: Box<[i32]>;
//~^ ERROR mismatched types
let _ = box { |x| (x as u8) }: Box<dyn Fn(i32) -> _>; //~ ERROR mismatched types
let _ = box if true { false } else { true }: Box<dyn Debug>; //~ ERROR mismatched types
let _ = box match true { true => 'a', false => 'b' }: Box<dyn Debug>; //~ ERROR mismatched types
let _ = box { |x| (x as u8) }: Box<dyn Fn(i32) -> _>;
let _ = box if true { false } else { true }: Box<dyn Debug>;
let _ = box match true { true => 'a', false => 'b' }: Box<dyn Debug>;

let _ = &{ [1, 2, 3] }: &[i32]; //~ ERROR mismatched types
let _ = &if true { [1, 2, 3] } else { [1, 3, 4] }: &[i32]; //~ ERROR mismatched types
let _ = &{ [1, 2, 3] }: &[i32];
let _ = &if true { [1, 2, 3] } else { [1, 3, 4] }: &[i32];
let _ = &match true { true => [1, 2, 3], false => [1, 3, 4] }: &[i32];
//~^ ERROR mismatched types
let _ = &{ |x| (x as u8) }: &dyn Fn(i32) -> _; //~ ERROR mismatched types
let _ = &if true { false } else { true }: &dyn Debug; //~ ERROR mismatched types
let _ = &match true { true => 'a', false => 'b' }: &dyn Debug; //~ ERROR mismatched types
let _ = &{ |x| (x as u8) }: &dyn Fn(i32) -> _;
let _ = &if true { false } else { true }: &dyn Debug;
let _ = &match true { true => 'a', false => 'b' }: &dyn Debug;

let _ = Box::new([1, 2, 3]): Box<[i32]>; //~ ERROR mismatched types
let _ = Box::new(|x| (x as u8)): Box<dyn Fn(i32) -> _>; //~ ERROR mismatched types
let _ = Box::new([1, 2, 3]): Box<[i32]>;
let _ = Box::new(|x| (x as u8)): Box<dyn Fn(i32) -> _>;

let _ = vec![
Box::new(|x| (x as u8)),
Expand Down
129 changes: 0 additions & 129 deletions src/test/ui/coercion/coerce-expect-unsized-ascribed.stderr

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#![feature(type_ascription)]

// build-pass

fn foo(_arg : [&[u32];3]) {}

fn main() {
let arr = [4,5,6];
foo([&arr : &[u32]; 3]);
//~^ ERROR type ascriptions are not
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: type ascriptions are not allowed in lvalue contexts
--> $DIR/coerce-array-repeat-in-fn-arg.rs:7:8
|
LL | foo([&arr : &[u32]; 3]);
| ^^^^^^^^^^^^^

error: aborting due to previous error

3 changes: 1 addition & 2 deletions src/test/ui/coercion/type-ascription/coerce-enum-variant.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// build-pass

#![feature(type_ascription)]

enum Foo<'a> {
Expand All @@ -10,4 +8,5 @@ enum Foo<'a> {
fn main() {
let arr = [4,5,6];
let temp = Foo::A((10, &arr : &[u32]));
//~^ ERROR type ascriptions are not
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: type ascriptions are not allowed in lvalue contexts
--> $DIR/coerce-enum-variant.rs:10:26
|
LL | let temp = Foo::A((10, &arr : &[u32]));
| ^^^^^^^^^^^^^

error: aborting due to previous error

Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Here we test for coercions in struct fields of nested type ascriptions
// inside a tuple using an unsized coercion and a coercion from &mut -> &

// run-pass

#![feature(type_ascription)]

use std::any::type_name;
Expand All @@ -26,4 +24,5 @@ fn main() {
let tup = (9, (3, &arr : &[u32]), &mut bar);
Copy link
Contributor Author

@b-naber b-naber Feb 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no error here, but two lines down there is, in what looks to be the same expression. Is this correct?

assert_eq!(type_of(tup), "(i32, (i32, &[u32]), &mut coerce_struct_fields_pass_in_let_stmt::Bar)");
let _ = Foo { _a : (9, (3, &arr : &[u32]), &mut bar) };
//~^ ERROR type ascriptions are not
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: type ascriptions are not allowed in lvalue contexts
--> $DIR/coerce-struct-fields-pass-in-let-stmt.rs:26:30
|
LL | let _ = Foo { _a : (9, (3, &arr : &[u32]), &mut bar) };
| ^^^^^^^^^^^^^

error: aborting due to previous error

Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// build-pass

#![feature(type_ascription)]

fn foo<'a>(arg : &'a [u32; 3]) -> &'a [u32] {
arg : &[u32]
//~^ ERROR type ascriptions are not
}

fn main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: type ascriptions are not allowed in lvalue contexts
--> $DIR/coerce-to-unsized-in-return-expr.rs:4:3
|
LL | arg : &[u32]
| ^^^^^^^^^^^^

error: aborting due to previous error

4 changes: 2 additions & 2 deletions src/test/ui/coercion/type-ascription/coerce-union-field.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// build-pass

#![feature(type_ascription)]

union Foo<'a> {
Expand All @@ -11,4 +9,6 @@ fn main() {
let arr = [4,5,6];
let x = &mut 26;
let _ = Foo { f1: (x : &u32, (5, &arr : &[u32])) };
//~^ ERROR type ascriptions
//~^^ ERROR type ascriptions
}
19 changes: 19 additions & 0 deletions src/test/ui/coercion/type-ascription/coerce-union-field.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error: type ascriptions are not allowed in lvalue contexts
--> $DIR/coerce-union-field.rs:11:22
|
LL | let _ = Foo { f1: (x : &u32, (5, &arr : &[u32])) };
| ^^^^^^^^
|
help: try to use the type ascription when creating the local variable
|
LL | let x: &u32 = &mut 26;
| ^^^^^^^^^^^

error: type ascriptions are not allowed in lvalue contexts
--> $DIR/coerce-union-field.rs:11:36
|
LL | let _ = Foo { f1: (x : &u32, (5, &arr : &[u32])) };
| ^^^^^^^^^^^^^

error: aborting due to 2 previous errors

2 changes: 1 addition & 1 deletion src/test/ui/mir/mir_ascription_coercion.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// run-pass
// Tests that the result of type ascription has adjustments applied

#![feature(type_ascription)]
Expand All @@ -7,4 +6,5 @@ fn main() {
let x = [1, 2, 3];
// The RHS should coerce to &[i32]
let _y : &[i32] = &x : &[i32; 3];
//~^ ERROR type ascriptions
}
8 changes: 8 additions & 0 deletions src/test/ui/mir/mir_ascription_coercion.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: type ascriptions are not allowed in lvalue contexts
--> $DIR/mir_ascription_coercion.rs:8:23
|
LL | let _y : &[i32] = &x : &[i32; 3];
| ^^^^^^^^^^^^^^

error: aborting due to previous error

Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@

fn main() {
let x = 22_u32;
let y: &u32 = &x: &'static u32; //~ ERROR E0597
let y: &u32 = &x: &'static u32;
//~^ ERROR type ascriptions are not
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
error[E0597]: `x` does not live long enough
error: type ascriptions are not allowed in lvalue contexts
--> $DIR/type_ascription_static_lifetime.rs:6:19
|
LL | let y: &u32 = &x: &'static u32;
| ^^--------------
| |
| borrowed value does not live long enough
| type annotation requires that `x` is borrowed for `'static`
LL | }
| - `x` dropped here while still borrowed
LL | let y: &u32 = &x: &'static u32;
| ^^^^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0597`.
Loading