1
Fork 0

Add test of VEC.push on a const

This commit is contained in:
David Tolnay 2020-09-30 22:13:33 -07:00
parent 41baa090ad
commit eef5104c53
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82
2 changed files with 9 additions and 7 deletions

View file

@ -28,6 +28,7 @@ const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw_ptr:
const RAW_PTR: *mut u8 = 1 as *mut u8;
const MUTABLE: Mutable = Mutable { msg: "" };
const MUTABLE2: Mutable2 = Mutable2 { msg: "", other: String::new() };
const VEC: Vec<i32> = Vec::new();
fn main() {
ARRAY[0] = 5; //~ WARN attempting to modify
@ -48,4 +49,5 @@ fn main() {
MUTABLE.msg = "wow"; // no warning, because Drop observes the mutation
MUTABLE2.msg = "wow"; //~ WARN attempting to modify
VEC.push(0); // no warning
}

View file

@ -1,5 +1,5 @@
warning: attempting to modify a `const` item
--> $DIR/lint-const-item-mutation.rs:33:5
--> $DIR/lint-const-item-mutation.rs:34:5
|
LL | ARRAY[0] = 5;
| ^^^^^^^^^^^^
@ -13,7 +13,7 @@ LL | const ARRAY: [u8; 1] = [25];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: attempting to modify a `const` item
--> $DIR/lint-const-item-mutation.rs:34:5
--> $DIR/lint-const-item-mutation.rs:35:5
|
LL | MY_STRUCT.field = false;
| ^^^^^^^^^^^^^^^^^^^^^^^
@ -26,7 +26,7 @@ LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: attempting to modify a `const` item
--> $DIR/lint-const-item-mutation.rs:35:5
--> $DIR/lint-const-item-mutation.rs:36:5
|
LL | MY_STRUCT.inner_array[0] = 'b';
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -39,7 +39,7 @@ LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: taking a mutable reference to a `const` item
--> $DIR/lint-const-item-mutation.rs:36:5
--> $DIR/lint-const-item-mutation.rs:37:5
|
LL | MY_STRUCT.use_mut();
| ^^^^^^^^^^^^^^^^^^^
@ -58,7 +58,7 @@ LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: taking a mutable reference to a `const` item
--> $DIR/lint-const-item-mutation.rs:37:5
--> $DIR/lint-const-item-mutation.rs:38:5
|
LL | &mut MY_STRUCT;
| ^^^^^^^^^^^^^^
@ -72,7 +72,7 @@ LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: taking a mutable reference to a `const` item
--> $DIR/lint-const-item-mutation.rs:38:5
--> $DIR/lint-const-item-mutation.rs:39:5
|
LL | (&mut MY_STRUCT).use_mut();
| ^^^^^^^^^^^^^^^^
@ -86,7 +86,7 @@ LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: attempting to modify a `const` item
--> $DIR/lint-const-item-mutation.rs:50:5
--> $DIR/lint-const-item-mutation.rs:51:5
|
LL | MUTABLE2.msg = "wow";
| ^^^^^^^^^^^^^^^^^^^^