Skip to content

Commit 0c82a13

Browse files
committed
Remove #[rustc_box] usage in the vec![] macro
1 parent ab78384 commit 0c82a13

11 files changed

+67
-56
lines changed

library/alloc/src/macros.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ macro_rules! vec {
4848
);
4949
($($x:expr),+ $(,)?) => (
5050
<[_]>::into_vec(
51-
// Using the intrinsic produces a dramatic improvement in compile
52-
// time when constructing arrays with many elements.
53-
$crate::boxed::box_new([$($x),+])
51+
$crate::boxed::Box::new([$($x),+])
5452
)
5553
);
5654
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const fn foo(a: i32) -> Vec<i32> {
22
vec![1, 2, 3]
3-
//~^ ERROR allocations are not allowed
4-
//~| ERROR cannot call non-const method
3+
//~^ ERROR cannot call non-const
4+
//~| ERROR cannot call non-const
55
}
66

77
fn main() {}

tests/ui/consts/min_const_fn/bad_const_fn_body_ice.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
error[E0010]: allocations are not allowed in constant functions
1+
error[E0015]: cannot call non-const associated function `Box::<[i32; 3]>::new` in constant functions
22
--> $DIR/bad_const_fn_body_ice.rs:2:5
33
|
44
LL | vec![1, 2, 3]
5-
| ^^^^^^^^^^^^^ allocation not allowed in constant functions
5+
| ^^^^^^^^^^^^^
66
|
7+
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
78
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
89

910
error[E0015]: cannot call non-const method `slice::<impl [i32]>::into_vec::<std::alloc::Global>` in constant functions
@@ -17,5 +18,4 @@ LL | vec![1, 2, 3]
1718

1819
error: aborting due to 2 previous errors
1920

20-
Some errors have detailed explanations: E0010, E0015.
21-
For more information about an error, try `rustc --explain E0010`.
21+
For more information about this error, try `rustc --explain E0015`.

tests/ui/error-codes/E0010-teach.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
#![allow(warnings)]
44

5-
const CON: Vec<i32> = vec![1, 2, 3]; //~ ERROR E0010
6-
//~| ERROR cannot call non-const method
5+
const CON: Vec<i32> = vec![1, 2, 3]; //~ ERROR cannot call non-const
6+
//~| ERROR cannot call non-const
77
fn main() {}

tests/ui/error-codes/E0010-teach.stderr

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error[E0010]: allocations are not allowed in constants
1+
error[E0015]: cannot call non-const associated function `Box::<[i32; 3]>::new` in constants
22
--> $DIR/E0010-teach.rs:5:23
33
|
44
LL | const CON: Vec<i32> = vec![1, 2, 3];
5-
| ^^^^^^^^^^^^^ allocation not allowed in constants
5+
| ^^^^^^^^^^^^^
66
|
7-
= note: The runtime heap is not yet available at compile-time, so no runtime heap allocations can be created.
7+
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
88
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
99

1010
error[E0015]: cannot call non-const method `slice::<impl [i32]>::into_vec::<std::alloc::Global>` in constants
@@ -18,5 +18,4 @@ LL | const CON: Vec<i32> = vec![1, 2, 3];
1818

1919
error: aborting due to 2 previous errors
2020

21-
Some errors have detailed explanations: E0010, E0015.
22-
For more information about an error, try `rustc --explain E0010`.
21+
For more information about this error, try `rustc --explain E0015`.

tests/ui/error-codes/E0010.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![allow(warnings)]
22

3-
const CON: Vec<i32> = vec![1, 2, 3]; //~ ERROR E0010
4-
//~| ERROR cannot call non-const method
3+
const CON: Vec<i32> = vec![1, 2, 3]; //~ ERROR cannot call non-const
4+
//~| ERROR cannot call non-const
55
fn main() {}

tests/ui/error-codes/E0010.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
error[E0010]: allocations are not allowed in constants
1+
error[E0015]: cannot call non-const associated function `Box::<[i32; 3]>::new` in constants
22
--> $DIR/E0010.rs:3:23
33
|
44
LL | const CON: Vec<i32> = vec![1, 2, 3];
5-
| ^^^^^^^^^^^^^ allocation not allowed in constants
5+
| ^^^^^^^^^^^^^
66
|
7+
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
78
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
89

910
error[E0015]: cannot call non-const method `slice::<impl [i32]>::into_vec::<std::alloc::Global>` in constants
@@ -17,5 +18,4 @@ LL | const CON: Vec<i32> = vec![1, 2, 3];
1718

1819
error: aborting due to 2 previous errors
1920

20-
Some errors have detailed explanations: E0010, E0015.
21-
For more information about an error, try `rustc --explain E0010`.
21+
For more information about this error, try `rustc --explain E0015`.

tests/ui/macros/vec-macro-in-pattern.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
fn main() {
66
match Some(vec![42]) {
7-
Some(vec![43]) => {} //~ ERROR expected a pattern, found a function call
7+
Some(vec![43]) => {} //~ ERROR expected tuple struct or tuple variant, found associated function
88
//~| ERROR found associated function
99
//~| ERROR usage of qualified paths in this context is experimental
1010
_ => {}

tests/ui/macros/vec-macro-in-pattern.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
error[E0532]: expected a pattern, found a function call
2-
--> $DIR/vec-macro-in-pattern.rs:7:14
3-
|
4-
LL | Some(vec![43]) => {}
5-
| ^^^^^^^^ not a tuple struct or tuple variant
6-
|
7-
= note: function calls are not allowed in patterns: <https://doc.rust-lang.org/book/ch19-00-patterns.html>
8-
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
9-
101
error[E0658]: usage of qualified paths in this context is experimental
112
--> $DIR/vec-macro-in-pattern.rs:7:14
123
|
@@ -27,7 +18,16 @@ LL | Some(vec![43]) => {}
2718
= help: for more information, visit https://doc.rust-lang.org/book/ch19-00-patterns.html
2819
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
2920

21+
error[E0164]: expected tuple struct or tuple variant, found associated function `::alloc::boxed::Box::new`
22+
--> $DIR/vec-macro-in-pattern.rs:7:14
23+
|
24+
LL | Some(vec![43]) => {}
25+
| ^^^^^^^^ `fn` calls are not allowed in patterns
26+
|
27+
= help: for more information, visit https://doc.rust-lang.org/book/ch19-00-patterns.html
28+
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
29+
3030
error: aborting due to 3 previous errors
3131

32-
Some errors have detailed explanations: E0164, E0532, E0658.
32+
Some errors have detailed explanations: E0164, E0658.
3333
For more information about an error, try `rustc --explain E0164`.

tests/ui/statics/check-values-constraints.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static STATIC10: UnsafeStruct = UnsafeStruct;
7979
struct MyOwned;
8080

8181
static STATIC11: Vec<MyOwned> = vec![MyOwned];
82-
//~^ ERROR allocations are not allowed in statics
82+
//~^ ERROR cannot call non-const
8383
//~^^ ERROR cannot call non-const
8484

8585
static mut STATIC12: UnsafeStruct = UnsafeStruct;
@@ -93,28 +93,28 @@ static mut STATIC14: SafeStruct = SafeStruct {
9393
};
9494

9595
static STATIC15: &'static [Vec<MyOwned>] = &[
96-
vec![MyOwned], //~ ERROR allocations are not allowed in statics
96+
vec![MyOwned], //~ ERROR cannot call non-const
9797
//~^ ERROR cannot call non-const
98-
vec![MyOwned], //~ ERROR allocations are not allowed in statics
98+
vec![MyOwned], //~ ERROR cannot call non-const
9999
//~^ ERROR cannot call non-const
100100
];
101101

102102
static STATIC16: (&'static Vec<MyOwned>, &'static Vec<MyOwned>) = (
103-
&vec![MyOwned], //~ ERROR allocations are not allowed in statics
103+
&vec![MyOwned], //~ ERROR cannot call non-const
104104
//~^ ERROR cannot call non-const
105-
&vec![MyOwned], //~ ERROR allocations are not allowed in statics
105+
&vec![MyOwned], //~ ERROR cannot call non-const
106106
//~^ ERROR cannot call non-const
107107
);
108108

109109
static mut STATIC17: SafeEnum = SafeEnum::Variant1;
110110

111111
static STATIC19: Vec<isize> = vec![3];
112-
//~^ ERROR allocations are not allowed in statics
112+
//~^ ERROR cannot call non-const
113113
//~^^ ERROR cannot call non-const
114114

115115
pub fn main() {
116116
let y = {
117-
static x: Vec<isize> = vec![3]; //~ ERROR allocations are not allowed in statics
117+
static x: Vec<isize> = vec![3]; //~ ERROR cannot call non-const
118118
//~^ ERROR cannot call non-const
119119
x
120120
//~^ ERROR cannot move out of static

tests/ui/statics/check-values-constraints.stderr

+30-16
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ LL | | }
1111
LL | };
1212
| - value is dropped here
1313

14-
error[E0010]: allocations are not allowed in statics
14+
error[E0015]: cannot call non-const associated function `Box::<[MyOwned; 1]>::new` in statics
1515
--> $DIR/check-values-constraints.rs:81:33
1616
|
1717
LL | static STATIC11: Vec<MyOwned> = vec![MyOwned];
18-
| ^^^^^^^^^^^^^ allocation not allowed in statics
18+
| ^^^^^^^^^^^^^
1919
|
20+
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
21+
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
2022
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
2123

2224
error[E0015]: cannot call non-const method `slice::<impl [MyOwned]>::into_vec::<std::alloc::Global>` in statics
@@ -38,12 +40,14 @@ LL | field2: SafeEnum::Variant4("str".to_string()),
3840
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
3941
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
4042

41-
error[E0010]: allocations are not allowed in statics
43+
error[E0015]: cannot call non-const associated function `Box::<[MyOwned; 1]>::new` in statics
4244
--> $DIR/check-values-constraints.rs:96:5
4345
|
4446
LL | vec![MyOwned],
45-
| ^^^^^^^^^^^^^ allocation not allowed in statics
47+
| ^^^^^^^^^^^^^
4648
|
49+
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
50+
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
4751
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
4852

4953
error[E0015]: cannot call non-const method `slice::<impl [MyOwned]>::into_vec::<std::alloc::Global>` in statics
@@ -56,12 +60,14 @@ LL | vec![MyOwned],
5660
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
5761
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
5862

59-
error[E0010]: allocations are not allowed in statics
63+
error[E0015]: cannot call non-const associated function `Box::<[MyOwned; 1]>::new` in statics
6064
--> $DIR/check-values-constraints.rs:98:5
6165
|
6266
LL | vec![MyOwned],
63-
| ^^^^^^^^^^^^^ allocation not allowed in statics
67+
| ^^^^^^^^^^^^^
6468
|
69+
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
70+
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
6571
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
6672

6773
error[E0015]: cannot call non-const method `slice::<impl [MyOwned]>::into_vec::<std::alloc::Global>` in statics
@@ -74,12 +80,14 @@ LL | vec![MyOwned],
7480
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
7581
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
7682

77-
error[E0010]: allocations are not allowed in statics
83+
error[E0015]: cannot call non-const associated function `Box::<[MyOwned; 1]>::new` in statics
7884
--> $DIR/check-values-constraints.rs:103:6
7985
|
8086
LL | &vec![MyOwned],
81-
| ^^^^^^^^^^^^^ allocation not allowed in statics
87+
| ^^^^^^^^^^^^^
8288
|
89+
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
90+
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
8391
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
8492

8593
error[E0015]: cannot call non-const method `slice::<impl [MyOwned]>::into_vec::<std::alloc::Global>` in statics
@@ -92,12 +100,14 @@ LL | &vec![MyOwned],
92100
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
93101
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
94102

95-
error[E0010]: allocations are not allowed in statics
103+
error[E0015]: cannot call non-const associated function `Box::<[MyOwned; 1]>::new` in statics
96104
--> $DIR/check-values-constraints.rs:105:6
97105
|
98106
LL | &vec![MyOwned],
99-
| ^^^^^^^^^^^^^ allocation not allowed in statics
107+
| ^^^^^^^^^^^^^
100108
|
109+
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
110+
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
101111
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
102112

103113
error[E0015]: cannot call non-const method `slice::<impl [MyOwned]>::into_vec::<std::alloc::Global>` in statics
@@ -110,12 +120,14 @@ LL | &vec![MyOwned],
110120
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
111121
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
112122

113-
error[E0010]: allocations are not allowed in statics
123+
error[E0015]: cannot call non-const associated function `Box::<[isize; 1]>::new` in statics
114124
--> $DIR/check-values-constraints.rs:111:31
115125
|
116126
LL | static STATIC19: Vec<isize> = vec![3];
117-
| ^^^^^^^ allocation not allowed in statics
127+
| ^^^^^^^
118128
|
129+
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
130+
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
119131
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
120132

121133
error[E0015]: cannot call non-const method `slice::<impl [isize]>::into_vec::<std::alloc::Global>` in statics
@@ -128,12 +140,14 @@ LL | static STATIC19: Vec<isize> = vec![3];
128140
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
129141
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
130142

131-
error[E0010]: allocations are not allowed in statics
143+
error[E0015]: cannot call non-const associated function `Box::<[isize; 1]>::new` in statics
132144
--> $DIR/check-values-constraints.rs:117:32
133145
|
134146
LL | static x: Vec<isize> = vec![3];
135-
| ^^^^^^^ allocation not allowed in statics
147+
| ^^^^^^^
136148
|
149+
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
150+
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
137151
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
138152

139153
error[E0015]: cannot call non-const method `slice::<impl [isize]>::into_vec::<std::alloc::Global>` in statics
@@ -163,5 +177,5 @@ LL | x.clone()
163177

164178
error: aborting due to 17 previous errors
165179

166-
Some errors have detailed explanations: E0010, E0015, E0493, E0507.
167-
For more information about an error, try `rustc --explain E0010`.
180+
Some errors have detailed explanations: E0015, E0493, E0507.
181+
For more information about an error, try `rustc --explain E0015`.

0 commit comments

Comments
 (0)