Test a type with drop glue but no Drop impl
This commit is contained in:
parent
0f6284c88d
commit
352ce8b299
@ -18,10 +18,16 @@ impl Drop for Mutable {
|
||||
}
|
||||
}
|
||||
|
||||
struct Mutable2 { // this one has drop glue but not a Drop impl
|
||||
msg: &'static str,
|
||||
other: String,
|
||||
}
|
||||
|
||||
const ARRAY: [u8; 1] = [25];
|
||||
const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw_ptr: 2 as *mut u8 };
|
||||
const RAW_PTR: *mut u8 = 1 as *mut u8;
|
||||
const MUTABLE: Mutable = Mutable { msg: "" };
|
||||
const MUTABLE2: Mutable2 = Mutable2 { msg: "", other: String::new() };
|
||||
|
||||
fn main() {
|
||||
ARRAY[0] = 5; //~ WARN attempting to modify
|
||||
@ -41,4 +47,5 @@ fn main() {
|
||||
}
|
||||
|
||||
MUTABLE.msg = "wow"; // no warning, because Drop observes the mutation
|
||||
MUTABLE2.msg = "wow"; //~ WARN attempting to modify
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
warning: attempting to modify a `const` item
|
||||
--> $DIR/lint-const-item-mutation.rs:27:5
|
||||
--> $DIR/lint-const-item-mutation.rs:33:5
|
||||
|
|
||||
LL | ARRAY[0] = 5;
|
||||
| ^^^^^^^^^^^^
|
||||
@ -7,39 +7,39 @@ LL | ARRAY[0] = 5;
|
||||
= note: `#[warn(const_item_mutation)]` on by default
|
||||
= note: each usage of a `const` item creates a new temporary - the original `const` item will not be modified
|
||||
note: `const` item defined here
|
||||
--> $DIR/lint-const-item-mutation.rs:21:1
|
||||
--> $DIR/lint-const-item-mutation.rs:26:1
|
||||
|
|
||||
LL | const ARRAY: [u8; 1] = [25];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: attempting to modify a `const` item
|
||||
--> $DIR/lint-const-item-mutation.rs:28:5
|
||||
--> $DIR/lint-const-item-mutation.rs:34:5
|
||||
|
|
||||
LL | MY_STRUCT.field = false;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: each usage of a `const` item creates a new temporary - the original `const` item will not be modified
|
||||
note: `const` item defined here
|
||||
--> $DIR/lint-const-item-mutation.rs:22:1
|
||||
--> $DIR/lint-const-item-mutation.rs:27:1
|
||||
|
|
||||
LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw_ptr: 2 as *mut u8 };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: attempting to modify a `const` item
|
||||
--> $DIR/lint-const-item-mutation.rs:29:5
|
||||
--> $DIR/lint-const-item-mutation.rs:35:5
|
||||
|
|
||||
LL | MY_STRUCT.inner_array[0] = 'b';
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: each usage of a `const` item creates a new temporary - the original `const` item will not be modified
|
||||
note: `const` item defined here
|
||||
--> $DIR/lint-const-item-mutation.rs:22:1
|
||||
--> $DIR/lint-const-item-mutation.rs:27:1
|
||||
|
|
||||
LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw_ptr: 2 as *mut u8 };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: taking a mutable reference to a `const` item
|
||||
--> $DIR/lint-const-item-mutation.rs:30:5
|
||||
--> $DIR/lint-const-item-mutation.rs:36:5
|
||||
|
|
||||
LL | MY_STRUCT.use_mut();
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
@ -52,13 +52,13 @@ note: mutable reference created due to call to this method
|
||||
LL | fn use_mut(&mut self) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
note: `const` item defined here
|
||||
--> $DIR/lint-const-item-mutation.rs:22:1
|
||||
--> $DIR/lint-const-item-mutation.rs:27:1
|
||||
|
|
||||
LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw_ptr: 2 as *mut u8 };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: taking a mutable reference to a `const` item
|
||||
--> $DIR/lint-const-item-mutation.rs:31:5
|
||||
--> $DIR/lint-const-item-mutation.rs:37:5
|
||||
|
|
||||
LL | &mut MY_STRUCT;
|
||||
| ^^^^^^^^^^^^^^
|
||||
@ -66,13 +66,13 @@ LL | &mut MY_STRUCT;
|
||||
= note: each usage of a `const` item creates a new temporary
|
||||
= note: the mutable reference will refer to this temporary, not the original `const` item
|
||||
note: `const` item defined here
|
||||
--> $DIR/lint-const-item-mutation.rs:22:1
|
||||
--> $DIR/lint-const-item-mutation.rs:27:1
|
||||
|
|
||||
LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw_ptr: 2 as *mut u8 };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: taking a mutable reference to a `const` item
|
||||
--> $DIR/lint-const-item-mutation.rs:32:5
|
||||
--> $DIR/lint-const-item-mutation.rs:38:5
|
||||
|
|
||||
LL | (&mut MY_STRUCT).use_mut();
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
@ -80,10 +80,23 @@ LL | (&mut MY_STRUCT).use_mut();
|
||||
= note: each usage of a `const` item creates a new temporary
|
||||
= note: the mutable reference will refer to this temporary, not the original `const` item
|
||||
note: `const` item defined here
|
||||
--> $DIR/lint-const-item-mutation.rs:22:1
|
||||
--> $DIR/lint-const-item-mutation.rs:27:1
|
||||
|
|
||||
LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw_ptr: 2 as *mut u8 };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: 6 warnings emitted
|
||||
warning: attempting to modify a `const` item
|
||||
--> $DIR/lint-const-item-mutation.rs:50:5
|
||||
|
|
||||
LL | MUTABLE2.msg = "wow";
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: each usage of a `const` item creates a new temporary - the original `const` item will not be modified
|
||||
note: `const` item defined here
|
||||
--> $DIR/lint-const-item-mutation.rs:30:1
|
||||
|
|
||||
LL | const MUTABLE2: Mutable2 = Mutable2 { msg: "", other: String::new() };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: 7 warnings emitted
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user