summaryrefslogtreecommitdiffstats
path: root/src/test/ui/coercion
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/ui/coercion')
-rw-r--r--src/test/ui/coercion/coerce-block-tail-26978.rs11
-rw-r--r--src/test/ui/coercion/coerce-block-tail-26978.stderr16
-rw-r--r--src/test/ui/coercion/coerce-block-tail-57749.rs35
-rw-r--r--src/test/ui/coercion/coerce-block-tail-57749.stderr14
-rw-r--r--src/test/ui/coercion/coerce-block-tail-83783.rs13
-rw-r--r--src/test/ui/coercion/coerce-block-tail-83783.stderr12
-rw-r--r--src/test/ui/coercion/coerce-block-tail-83850.rs7
-rw-r--r--src/test/ui/coercion/coerce-block-tail-83850.stderr19
-rw-r--r--src/test/ui/coercion/coerce-block-tail.rs6
-rw-r--r--src/test/ui/coercion/coerce-block-tail.stderr16
-rw-r--r--src/test/ui/coercion/coerce-expect-unsized-ascribed.rs32
-rw-r--r--src/test/ui/coercion/coerce-expect-unsized-ascribed.stderr90
12 files changed, 210 insertions, 61 deletions
diff --git a/src/test/ui/coercion/coerce-block-tail-26978.rs b/src/test/ui/coercion/coerce-block-tail-26978.rs
new file mode 100644
index 000000000..01c8ab5a8
--- /dev/null
+++ b/src/test/ui/coercion/coerce-block-tail-26978.rs
@@ -0,0 +1,11 @@
+// check-fail
+fn f(_: &i32) {}
+
+fn main() {
+ let x = Box::new(1i32);
+
+ f(&x);
+ f(&(x));
+ f(&{x});
+ //~^ ERROR mismatched types
+}
diff --git a/src/test/ui/coercion/coerce-block-tail-26978.stderr b/src/test/ui/coercion/coerce-block-tail-26978.stderr
new file mode 100644
index 000000000..384debd48
--- /dev/null
+++ b/src/test/ui/coercion/coerce-block-tail-26978.stderr
@@ -0,0 +1,16 @@
+error[E0308]: mismatched types
+ --> $DIR/coerce-block-tail-26978.rs:9:9
+ |
+LL | f(&{x});
+ | ^ expected `i32`, found struct `Box`
+ |
+ = note: expected type `i32`
+ found struct `Box<i32>`
+help: consider unboxing the value
+ |
+LL | f(&{*x});
+ | +
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/coercion/coerce-block-tail-57749.rs b/src/test/ui/coercion/coerce-block-tail-57749.rs
new file mode 100644
index 000000000..79b5b3323
--- /dev/null
+++ b/src/test/ui/coercion/coerce-block-tail-57749.rs
@@ -0,0 +1,35 @@
+// check-fail
+use std::ops::Deref;
+
+fn main() {
+ fn save(who: &str) {
+ println!("I'll save you, {}!", who);
+ }
+
+ struct Madoka;
+
+ impl Deref for Madoka {
+ type Target = str;
+ fn deref(&self) -> &Self::Target {
+ "Madoka"
+ }
+ }
+
+ save(&{ Madoka });
+
+ fn reset(how: &u32) {
+ println!("Reset {} times", how);
+ }
+
+ struct Homura;
+
+ impl Deref for Homura {
+ type Target = u32;
+ fn deref(&self) -> &Self::Target {
+ &42
+ }
+ }
+
+ reset(&{ Homura });
+ //~^ ERROR mismatched types
+}
diff --git a/src/test/ui/coercion/coerce-block-tail-57749.stderr b/src/test/ui/coercion/coerce-block-tail-57749.stderr
new file mode 100644
index 000000000..d5660c81d
--- /dev/null
+++ b/src/test/ui/coercion/coerce-block-tail-57749.stderr
@@ -0,0 +1,14 @@
+error[E0308]: mismatched types
+ --> $DIR/coerce-block-tail-57749.rs:33:14
+ |
+LL | reset(&{ Homura });
+ | ^^^^^^ expected `u32`, found struct `Homura`
+ |
+help: consider dereferencing the type
+ |
+LL | reset(&{ *Homura });
+ | +
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/coercion/coerce-block-tail-83783.rs b/src/test/ui/coercion/coerce-block-tail-83783.rs
new file mode 100644
index 000000000..18c8ae3bb
--- /dev/null
+++ b/src/test/ui/coercion/coerce-block-tail-83783.rs
@@ -0,0 +1,13 @@
+// check-fail
+// edition:2018
+fn _consume_reference<T: ?Sized>(_: &T) {}
+
+async fn _foo() {
+ _consume_reference::<i32>(&Box::new(7_i32));
+ _consume_reference::<i32>(&async { Box::new(7_i32) }.await);
+ //~^ ERROR mismatched types
+ _consume_reference::<[i32]>(&vec![7_i32]);
+ _consume_reference::<[i32]>(&async { vec![7_i32] }.await);
+}
+
+fn main() { }
diff --git a/src/test/ui/coercion/coerce-block-tail-83783.stderr b/src/test/ui/coercion/coerce-block-tail-83783.stderr
new file mode 100644
index 000000000..5f53606ce
--- /dev/null
+++ b/src/test/ui/coercion/coerce-block-tail-83783.stderr
@@ -0,0 +1,12 @@
+error[E0308]: mismatched types
+ --> $DIR/coerce-block-tail-83783.rs:7:32
+ |
+LL | _consume_reference::<i32>(&async { Box::new(7_i32) }.await);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found struct `Box`
+ |
+ = note: expected type `i32`
+ found struct `Box<i32>`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/coercion/coerce-block-tail-83850.rs b/src/test/ui/coercion/coerce-block-tail-83850.rs
new file mode 100644
index 000000000..77fdf9998
--- /dev/null
+++ b/src/test/ui/coercion/coerce-block-tail-83850.rs
@@ -0,0 +1,7 @@
+// check-fail
+fn f(_: &[i32]) {}
+
+fn main() {
+ f(&Box::new([1, 2]));
+ //~^ ERROR mismatched types
+}
diff --git a/src/test/ui/coercion/coerce-block-tail-83850.stderr b/src/test/ui/coercion/coerce-block-tail-83850.stderr
new file mode 100644
index 000000000..bbf607543
--- /dev/null
+++ b/src/test/ui/coercion/coerce-block-tail-83850.stderr
@@ -0,0 +1,19 @@
+error[E0308]: mismatched types
+ --> $DIR/coerce-block-tail-83850.rs:5:7
+ |
+LL | f(&Box::new([1, 2]));
+ | - ^^^^^^^^^^^^^^^^^ expected slice `[i32]`, found struct `Box`
+ | |
+ | arguments to this function are incorrect
+ |
+ = note: expected reference `&[i32]`
+ found reference `&Box<[{integer}; 2]>`
+note: function defined here
+ --> $DIR/coerce-block-tail-83850.rs:2:4
+ |
+LL | fn f(_: &[i32]) {}
+ | ^ ---------
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/coercion/coerce-block-tail.rs b/src/test/ui/coercion/coerce-block-tail.rs
new file mode 100644
index 000000000..dcbcd3762
--- /dev/null
+++ b/src/test/ui/coercion/coerce-block-tail.rs
@@ -0,0 +1,6 @@
+// check-fail
+fn main() {
+ let _: &str = & { String::from("hahah")};
+ let _: &i32 = & { Box::new(1i32) };
+ //~^ ERROR mismatched types
+}
diff --git a/src/test/ui/coercion/coerce-block-tail.stderr b/src/test/ui/coercion/coerce-block-tail.stderr
new file mode 100644
index 000000000..318cf7586
--- /dev/null
+++ b/src/test/ui/coercion/coerce-block-tail.stderr
@@ -0,0 +1,16 @@
+error[E0308]: mismatched types
+ --> $DIR/coerce-block-tail.rs:4:23
+ |
+LL | let _: &i32 = & { Box::new(1i32) };
+ | ^^^^^^^^^^^^^^ expected `i32`, found struct `Box`
+ |
+ = note: expected type `i32`
+ found struct `Box<i32>`
+help: consider unboxing the value
+ |
+LL | let _: &i32 = & { *Box::new(1i32) };
+ | +
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/coercion/coerce-expect-unsized-ascribed.rs b/src/test/ui/coercion/coerce-expect-unsized-ascribed.rs
index c139e823c..d7b11317a 100644
--- a/src/test/ui/coercion/coerce-expect-unsized-ascribed.rs
+++ b/src/test/ui/coercion/coerce-expect-unsized-ascribed.rs
@@ -6,27 +6,27 @@
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]>;
+ let _ = type_ascribe!(box { [1, 2, 3] }, Box<[i32]>); //~ ERROR mismatched types
+ let _ = type_ascribe!(box if true { [1, 2, 3] } else { [1, 3, 4] }, Box<[i32]>); //~ ERROR mismatched types
+ let _ = type_ascribe!(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 _ = type_ascribe!(box { |x| (x as u8) }, Box<dyn Fn(i32) -> _>); //~ ERROR mismatched types
+ let _ = type_ascribe!(box if true { false } else { true }, Box<dyn Debug>); //~ ERROR mismatched types
+ let _ = type_ascribe!(box match true { true => 'a', false => 'b' }, Box<dyn 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];
+ let _ = type_ascribe!(&{ [1, 2, 3] }, &[i32]); //~ ERROR mismatched types
+ let _ = type_ascribe!(&if true { [1, 2, 3] } else { [1, 3, 4] }, &[i32]); //~ ERROR mismatched types
+ let _ = type_ascribe!(&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 _ = type_ascribe!(&{ |x| (x as u8) }, &dyn Fn(i32) -> _); //~ ERROR mismatched types
+ let _ = type_ascribe!(&if true { false } else { true }, &dyn Debug); //~ ERROR mismatched types
+ let _ = type_ascribe!(&match true { true => 'a', false => 'b' }, &dyn Debug); //~ ERROR mismatched types
- 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 _ = type_ascribe!(Box::new([1, 2, 3]), Box<[i32]>); //~ ERROR mismatched types
+ let _ = type_ascribe!(Box::new(|x| (x as u8)), Box<dyn Fn(i32) -> _>); //~ ERROR mismatched types
- let _ = vec![
+ let _ = type_ascribe!(vec![
Box::new(|x| (x as u8)),
box |x| (x as i16 as u8),
- ]: Vec<Box<dyn Fn(i32) -> _>>;
+ ], Vec<Box<dyn Fn(i32) -> _>>);
}
diff --git a/src/test/ui/coercion/coerce-expect-unsized-ascribed.stderr b/src/test/ui/coercion/coerce-expect-unsized-ascribed.stderr
index 9d614e610..44968244c 100644
--- a/src/test/ui/coercion/coerce-expect-unsized-ascribed.stderr
+++ b/src/test/ui/coercion/coerce-expect-unsized-ascribed.stderr
@@ -1,128 +1,128 @@
error[E0308]: mismatched types
- --> $DIR/coerce-expect-unsized-ascribed.rs:9:13
+ --> $DIR/coerce-expect-unsized-ascribed.rs:9:27
|
-LL | let _ = box { [1, 2, 3] }: Box<[i32]>;
- | ^^^^^^^^^^^^^^^^^ expected slice `[i32]`, found array `[i32; 3]`
+LL | let _ = type_ascribe!(box { [1, 2, 3] }, Box<[i32]>);
+ | ^^^^^^^^^^^^^^^^^ expected slice `[i32]`, found array `[i32; 3]`
|
= note: expected struct `Box<[i32]>`
found struct `Box<[i32; 3]>`
error[E0308]: mismatched types
- --> $DIR/coerce-expect-unsized-ascribed.rs:10:13
+ --> $DIR/coerce-expect-unsized-ascribed.rs:10:27
|
-LL | let _ = box if true { [1, 2, 3] } else { [1, 3, 4] }: Box<[i32]>;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected slice `[i32]`, found array `[i32; 3]`
+LL | let _ = type_ascribe!(box if true { [1, 2, 3] } else { [1, 3, 4] }, Box<[i32]>);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected slice `[i32]`, found array `[i32; 3]`
|
= note: expected struct `Box<[i32]>`
found struct `Box<[i32; 3]>`
error[E0308]: mismatched types
- --> $DIR/coerce-expect-unsized-ascribed.rs:11:13
+ --> $DIR/coerce-expect-unsized-ascribed.rs:11:27
|
-LL | let _ = box match true { true => [1, 2, 3], false => [1, 3, 4] }: Box<[i32]>;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected slice `[i32]`, found array `[i32; 3]`
+LL | let _ = type_ascribe!(box match true { true => [1, 2, 3], false => [1, 3, 4] }, Box<[i32]>);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected slice `[i32]`, found array `[i32; 3]`
|
= note: expected struct `Box<[i32]>`
found struct `Box<[i32; 3]>`
error[E0308]: mismatched types
- --> $DIR/coerce-expect-unsized-ascribed.rs:13:13
+ --> $DIR/coerce-expect-unsized-ascribed.rs:13:27
|
-LL | let _ = box { |x| (x as u8) }: Box<dyn Fn(i32) -> _>;
- | ^^^^^^^^^^^^^^^^^^^^^ expected trait object `dyn Fn`, found closure
+LL | let _ = type_ascribe!(box { |x| (x as u8) }, Box<dyn Fn(i32) -> _>);
+ | ^^^^^^^^^^^^^^^^^^^^^ expected trait object `dyn Fn`, found closure
|
= note: expected struct `Box<dyn Fn(i32) -> u8>`
- found struct `Box<[closure@$DIR/coerce-expect-unsized-ascribed.rs:13:19: 13:22]>`
+ found struct `Box<[closure@$DIR/coerce-expect-unsized-ascribed.rs:13:33: 13:36]>`
error[E0308]: mismatched types
- --> $DIR/coerce-expect-unsized-ascribed.rs:14:13
+ --> $DIR/coerce-expect-unsized-ascribed.rs:14:27
|
-LL | let _ = box if true { false } else { true }: Box<dyn Debug>;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected trait object `dyn Debug`, found `bool`
+LL | let _ = type_ascribe!(box if true { false } else { true }, Box<dyn Debug>);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected trait object `dyn Debug`, found `bool`
|
= note: expected struct `Box<dyn Debug>`
found struct `Box<bool>`
error[E0308]: mismatched types
- --> $DIR/coerce-expect-unsized-ascribed.rs:15:13
+ --> $DIR/coerce-expect-unsized-ascribed.rs:15:27
|
-LL | let _ = box match true { true => 'a', false => 'b' }: Box<dyn Debug>;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected trait object `dyn Debug`, found `char`
+LL | let _ = type_ascribe!(box match true { true => 'a', false => 'b' }, Box<dyn Debug>);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected trait object `dyn Debug`, found `char`
|
= note: expected struct `Box<dyn Debug>`
found struct `Box<char>`
error[E0308]: mismatched types
- --> $DIR/coerce-expect-unsized-ascribed.rs:17:13
+ --> $DIR/coerce-expect-unsized-ascribed.rs:17:27
|
-LL | let _ = &{ [1, 2, 3] }: &[i32];
- | ^^^^^^^^^^^^^^ expected slice `[i32]`, found array `[i32; 3]`
+LL | let _ = type_ascribe!(&{ [1, 2, 3] }, &[i32]);
+ | ^^^^^^^^^^^^^^ expected slice `[i32]`, found array `[i32; 3]`
|
= note: expected reference `&[i32]`
found reference `&[i32; 3]`
error[E0308]: mismatched types
- --> $DIR/coerce-expect-unsized-ascribed.rs:18:13
+ --> $DIR/coerce-expect-unsized-ascribed.rs:18:27
|
-LL | let _ = &if true { [1, 2, 3] } else { [1, 3, 4] }: &[i32];
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected slice `[i32]`, found array `[i32; 3]`
+LL | let _ = type_ascribe!(&if true { [1, 2, 3] } else { [1, 3, 4] }, &[i32]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected slice `[i32]`, found array `[i32; 3]`
|
= note: expected reference `&[i32]`
found reference `&[i32; 3]`
error[E0308]: mismatched types
- --> $DIR/coerce-expect-unsized-ascribed.rs:19:13
+ --> $DIR/coerce-expect-unsized-ascribed.rs:19:27
|
-LL | let _ = &match true { true => [1, 2, 3], false => [1, 3, 4] }: &[i32];
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected slice `[i32]`, found array `[i32; 3]`
+LL | let _ = type_ascribe!(&match true { true => [1, 2, 3], false => [1, 3, 4] }, &[i32]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected slice `[i32]`, found array `[i32; 3]`
|
= note: expected reference `&[i32]`
found reference `&[i32; 3]`
error[E0308]: mismatched types
- --> $DIR/coerce-expect-unsized-ascribed.rs:21:13
+ --> $DIR/coerce-expect-unsized-ascribed.rs:21:27
|
-LL | let _ = &{ |x| (x as u8) }: &dyn Fn(i32) -> _;
- | ^^^^^^^^^^^^^^^^^^ expected trait object `dyn Fn`, found closure
+LL | let _ = type_ascribe!(&{ |x| (x as u8) }, &dyn Fn(i32) -> _);
+ | ^^^^^^^^^^^^^^^^^^ expected trait object `dyn Fn`, found closure
|
= note: expected reference `&dyn Fn(i32) -> u8`
- found reference `&[closure@$DIR/coerce-expect-unsized-ascribed.rs:21:16: 21:19]`
+ found reference `&[closure@$DIR/coerce-expect-unsized-ascribed.rs:21:30: 21:33]`
error[E0308]: mismatched types
- --> $DIR/coerce-expect-unsized-ascribed.rs:22:13
+ --> $DIR/coerce-expect-unsized-ascribed.rs:22:27
|
-LL | let _ = &if true { false } else { true }: &dyn Debug;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected trait object `dyn Debug`, found `bool`
+LL | let _ = type_ascribe!(&if true { false } else { true }, &dyn Debug);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected trait object `dyn Debug`, found `bool`
|
= note: expected reference `&dyn Debug`
found reference `&bool`
error[E0308]: mismatched types
- --> $DIR/coerce-expect-unsized-ascribed.rs:23:13
+ --> $DIR/coerce-expect-unsized-ascribed.rs:23:27
|
-LL | let _ = &match true { true => 'a', false => 'b' }: &dyn Debug;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected trait object `dyn Debug`, found `char`
+LL | let _ = type_ascribe!(&match true { true => 'a', false => 'b' }, &dyn Debug);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected trait object `dyn Debug`, found `char`
|
= note: expected reference `&dyn Debug`
found reference `&char`
error[E0308]: mismatched types
- --> $DIR/coerce-expect-unsized-ascribed.rs:25:13
+ --> $DIR/coerce-expect-unsized-ascribed.rs:25:27
|
-LL | let _ = Box::new([1, 2, 3]): Box<[i32]>;
- | ^^^^^^^^^^^^^^^^^^^ expected slice `[i32]`, found array `[i32; 3]`
+LL | let _ = type_ascribe!(Box::new([1, 2, 3]), Box<[i32]>);
+ | ^^^^^^^^^^^^^^^^^^^ expected slice `[i32]`, found array `[i32; 3]`
|
= note: expected struct `Box<[i32]>`
found struct `Box<[i32; 3]>`
error[E0308]: mismatched types
- --> $DIR/coerce-expect-unsized-ascribed.rs:26:13
+ --> $DIR/coerce-expect-unsized-ascribed.rs:26:27
|
-LL | let _ = Box::new(|x| (x as u8)): Box<dyn Fn(i32) -> _>;
- | ^^^^^^^^^^^^^^^^^^^^^^^ expected trait object `dyn Fn`, found closure
+LL | let _ = type_ascribe!(Box::new(|x| (x as u8)), Box<dyn Fn(i32) -> _>);
+ | ^^^^^^^^^^^^^^^^^^^^^^^ expected trait object `dyn Fn`, found closure
|
= note: expected struct `Box<dyn Fn(i32) -> u8>`
- found struct `Box<[closure@$DIR/coerce-expect-unsized-ascribed.rs:26:22: 26:25]>`
+ found struct `Box<[closure@$DIR/coerce-expect-unsized-ascribed.rs:26:36: 26:39]>`
error: aborting due to 14 previous errors