Skip to content

Commit eef5104

Browse files
committed
Add test of VEC.push on a const
1 parent 41baa09 commit eef5104

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/test/ui/lint/lint-const-item-mutation.rs

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw_ptr:
2828
const RAW_PTR: *mut u8 = 1 as *mut u8;
2929
const MUTABLE: Mutable = Mutable { msg: "" };
3030
const MUTABLE2: Mutable2 = Mutable2 { msg: "", other: String::new() };
31+
const VEC: Vec<i32> = Vec::new();
3132

3233
fn main() {
3334
ARRAY[0] = 5; //~ WARN attempting to modify
@@ -48,4 +49,5 @@ fn main() {
4849

4950
MUTABLE.msg = "wow"; // no warning, because Drop observes the mutation
5051
MUTABLE2.msg = "wow"; //~ WARN attempting to modify
52+
VEC.push(0); // no warning
5153
}

src/test/ui/lint/lint-const-item-mutation.stderr

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: attempting to modify a `const` item
2-
--> $DIR/lint-const-item-mutation.rs:33:5
2+
--> $DIR/lint-const-item-mutation.rs:34:5
33
|
44
LL | ARRAY[0] = 5;
55
| ^^^^^^^^^^^^
@@ -13,7 +13,7 @@ LL | const ARRAY: [u8; 1] = [25];
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1414

1515
warning: attempting to modify a `const` item
16-
--> $DIR/lint-const-item-mutation.rs:34:5
16+
--> $DIR/lint-const-item-mutation.rs:35:5
1717
|
1818
LL | MY_STRUCT.field = false;
1919
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -26,7 +26,7 @@ LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw
2626
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2727

2828
warning: attempting to modify a `const` item
29-
--> $DIR/lint-const-item-mutation.rs:35:5
29+
--> $DIR/lint-const-item-mutation.rs:36:5
3030
|
3131
LL | MY_STRUCT.inner_array[0] = 'b';
3232
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -39,7 +39,7 @@ LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw
3939
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4040

4141
warning: taking a mutable reference to a `const` item
42-
--> $DIR/lint-const-item-mutation.rs:36:5
42+
--> $DIR/lint-const-item-mutation.rs:37:5
4343
|
4444
LL | MY_STRUCT.use_mut();
4545
| ^^^^^^^^^^^^^^^^^^^
@@ -58,7 +58,7 @@ LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw
5858
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5959

6060
warning: taking a mutable reference to a `const` item
61-
--> $DIR/lint-const-item-mutation.rs:37:5
61+
--> $DIR/lint-const-item-mutation.rs:38:5
6262
|
6363
LL | &mut MY_STRUCT;
6464
| ^^^^^^^^^^^^^^
@@ -72,7 +72,7 @@ LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw
7272
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7373

7474
warning: taking a mutable reference to a `const` item
75-
--> $DIR/lint-const-item-mutation.rs:38:5
75+
--> $DIR/lint-const-item-mutation.rs:39:5
7676
|
7777
LL | (&mut MY_STRUCT).use_mut();
7878
| ^^^^^^^^^^^^^^^^
@@ -86,7 +86,7 @@ LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw
8686
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8787

8888
warning: attempting to modify a `const` item
89-
--> $DIR/lint-const-item-mutation.rs:50:5
89+
--> $DIR/lint-const-item-mutation.rs:51:5
9090
|
9191
LL | MUTABLE2.msg = "wow";
9292
| ^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)