Skip to content

Commit 4f1d1d5

Browse files
committed
add a coercion test that fails
1 parent 3943cba commit 4f1d1d5

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

library/alloc/src/macros.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ macro_rules! vec {
5050
// Using `write_box_via_move` produces a dramatic improvement in stack usage for unoptimized
5151
// programs using this code path to construct large Vecs. We can't use `write_via_move`
5252
// because this entire invocation has to remain a call chain without `let` bindings, or else
53-
// inference and temporary lifetimes change and things break (see `vec-macro-rvalue-scope`
54-
// and `autoderef-vec-box-fn-36786` tests). This function isn't actually safe but the way we
55-
// use it here is. We can't use an unsafe block as that would also wrap `$x`.
53+
// inference and temporary lifetimes change and things break (see `vec-macro-rvalue-scope`,
54+
// `vec-macro-coercions`, and `autoderef-vec-box-fn-36786` tests).
55+
//
56+
// `box_uninit_array_into_vec_unsafe` isn't actually safe but the way we use it here is. We
57+
// can't use an unsafe block as that would also wrap `$x`.
5658
$crate::boxed::box_uninit_array_into_vec_unsafe(
5759
$crate::intrinsics::write_box_via_move($crate::boxed::Box::new_uninit(), [$($x),+])
5860
)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@ check-pass
2+
3+
fn main() {
4+
let functions = &vec![
5+
|x: i32| -> i32 { x + 3 },
6+
|x: i32| -> i32 { x + 3 },
7+
];
8+
9+
let string = String::new();
10+
let a = vec![&string, "abc"];
11+
let b = vec!["abc", &string];
12+
}

0 commit comments

Comments
 (0)