Skip to content

Commit 3b12086

Browse files
authored
Rollup merge of rust-lang#103124 - ldm0:nohard_tests, r=Mark-Simulacrum
Add tests for autoderef on block tail ref: rust-lang#83850 (comment)
2 parents 23ff93c + 3e90419 commit 3b12086

10 files changed

+149
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// check-fail
2+
fn f(_: &i32) {}
3+
4+
fn main() {
5+
let x = Box::new(1i32);
6+
7+
f(&x);
8+
f(&(x));
9+
f(&{x});
10+
//~^ ERROR mismatched types
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/coerce-block-tail-26978.rs:9:9
3+
|
4+
LL | f(&{x});
5+
| ^ expected `i32`, found struct `Box`
6+
|
7+
= note: expected type `i32`
8+
found struct `Box<i32>`
9+
help: consider unboxing the value
10+
|
11+
LL | f(&{*x});
12+
| +
13+
14+
error: aborting due to previous error
15+
16+
For more information about this error, try `rustc --explain E0308`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// check-fail
2+
use std::ops::Deref;
3+
4+
fn main() {
5+
fn save(who: &str) {
6+
println!("I'll save you, {}!", who);
7+
}
8+
9+
struct Madoka;
10+
11+
impl Deref for Madoka {
12+
type Target = str;
13+
fn deref(&self) -> &Self::Target {
14+
"Madoka"
15+
}
16+
}
17+
18+
save(&{ Madoka });
19+
20+
fn reset(how: &u32) {
21+
println!("Reset {} times", how);
22+
}
23+
24+
struct Homura;
25+
26+
impl Deref for Homura {
27+
type Target = u32;
28+
fn deref(&self) -> &Self::Target {
29+
&42
30+
}
31+
}
32+
33+
reset(&{ Homura });
34+
//~^ ERROR mismatched types
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/coerce-block-tail-57749.rs:33:14
3+
|
4+
LL | reset(&{ Homura });
5+
| ^^^^^^ expected `u32`, found struct `Homura`
6+
|
7+
help: consider dereferencing the type
8+
|
9+
LL | reset(&{ *Homura });
10+
| +
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0308`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// check-fail
2+
// edition:2018
3+
fn _consume_reference<T: ?Sized>(_: &T) {}
4+
5+
async fn _foo() {
6+
_consume_reference::<i32>(&Box::new(7_i32));
7+
_consume_reference::<i32>(&async { Box::new(7_i32) }.await);
8+
//~^ ERROR mismatched types
9+
_consume_reference::<[i32]>(&vec![7_i32]);
10+
_consume_reference::<[i32]>(&async { vec![7_i32] }.await);
11+
}
12+
13+
fn main() { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/coerce-block-tail-83783.rs:7:32
3+
|
4+
LL | _consume_reference::<i32>(&async { Box::new(7_i32) }.await);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found struct `Box`
6+
|
7+
= note: expected type `i32`
8+
found struct `Box<i32>`
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0308`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// check-fail
2+
fn f(_: &[i32]) {}
3+
4+
fn main() {
5+
f(&Box::new([1, 2]));
6+
//~^ ERROR mismatched types
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/coerce-block-tail-83850.rs:5:7
3+
|
4+
LL | f(&Box::new([1, 2]));
5+
| - ^^^^^^^^^^^^^^^^^ expected slice `[i32]`, found struct `Box`
6+
| |
7+
| arguments to this function are incorrect
8+
|
9+
= note: expected reference `&[i32]`
10+
found reference `&Box<[{integer}; 2]>`
11+
note: function defined here
12+
--> $DIR/coerce-block-tail-83850.rs:2:4
13+
|
14+
LL | fn f(_: &[i32]) {}
15+
| ^ ---------
16+
17+
error: aborting due to previous error
18+
19+
For more information about this error, try `rustc --explain E0308`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// check-fail
2+
fn main() {
3+
let _: &str = & { String::from("hahah")};
4+
let _: &i32 = & { Box::new(1i32) };
5+
//~^ ERROR mismatched types
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/coerce-block-tail.rs:4:23
3+
|
4+
LL | let _: &i32 = & { Box::new(1i32) };
5+
| ^^^^^^^^^^^^^^ expected `i32`, found struct `Box`
6+
|
7+
= note: expected type `i32`
8+
found struct `Box<i32>`
9+
help: consider unboxing the value
10+
|
11+
LL | let _: &i32 = & { *Box::new(1i32) };
12+
| +
13+
14+
error: aborting due to previous error
15+
16+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)