Skip to content

Commit 352ce8b

Browse files
committed
Test a type with drop glue but no Drop impl
1 parent 0f6284c commit 352ce8b

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

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

+7
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,16 @@ impl Drop for Mutable {
1818
}
1919
}
2020

21+
struct Mutable2 { // this one has drop glue but not a Drop impl
22+
msg: &'static str,
23+
other: String,
24+
}
25+
2126
const ARRAY: [u8; 1] = [25];
2227
const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw_ptr: 2 as *mut u8 };
2328
const RAW_PTR: *mut u8 = 1 as *mut u8;
2429
const MUTABLE: Mutable = Mutable { msg: "" };
30+
const MUTABLE2: Mutable2 = Mutable2 { msg: "", other: String::new() };
2531

2632
fn main() {
2733
ARRAY[0] = 5; //~ WARN attempting to modify
@@ -41,4 +47,5 @@ fn main() {
4147
}
4248

4349
MUTABLE.msg = "wow"; // no warning, because Drop observes the mutation
50+
MUTABLE2.msg = "wow"; //~ WARN attempting to modify
4451
}
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
warning: attempting to modify a `const` item
2-
--> $DIR/lint-const-item-mutation.rs:27:5
2+
--> $DIR/lint-const-item-mutation.rs:33:5
33
|
44
LL | ARRAY[0] = 5;
55
| ^^^^^^^^^^^^
66
|
77
= note: `#[warn(const_item_mutation)]` on by default
88
= note: each usage of a `const` item creates a new temporary - the original `const` item will not be modified
99
note: `const` item defined here
10-
--> $DIR/lint-const-item-mutation.rs:21:1
10+
--> $DIR/lint-const-item-mutation.rs:26:1
1111
|
1212
LL | const ARRAY: [u8; 1] = [25];
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1414

1515
warning: attempting to modify a `const` item
16-
--> $DIR/lint-const-item-mutation.rs:28:5
16+
--> $DIR/lint-const-item-mutation.rs:34:5
1717
|
1818
LL | MY_STRUCT.field = false;
1919
| ^^^^^^^^^^^^^^^^^^^^^^^
2020
|
2121
= note: each usage of a `const` item creates a new temporary - the original `const` item will not be modified
2222
note: `const` item defined here
23-
--> $DIR/lint-const-item-mutation.rs:22:1
23+
--> $DIR/lint-const-item-mutation.rs:27:1
2424
|
2525
LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw_ptr: 2 as *mut u8 };
2626
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2727

2828
warning: attempting to modify a `const` item
29-
--> $DIR/lint-const-item-mutation.rs:29:5
29+
--> $DIR/lint-const-item-mutation.rs:35:5
3030
|
3131
LL | MY_STRUCT.inner_array[0] = 'b';
3232
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3333
|
3434
= note: each usage of a `const` item creates a new temporary - the original `const` item will not be modified
3535
note: `const` item defined here
36-
--> $DIR/lint-const-item-mutation.rs:22:1
36+
--> $DIR/lint-const-item-mutation.rs:27:1
3737
|
3838
LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw_ptr: 2 as *mut u8 };
3939
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4040

4141
warning: taking a mutable reference to a `const` item
42-
--> $DIR/lint-const-item-mutation.rs:30:5
42+
--> $DIR/lint-const-item-mutation.rs:36:5
4343
|
4444
LL | MY_STRUCT.use_mut();
4545
| ^^^^^^^^^^^^^^^^^^^
@@ -52,38 +52,51 @@ note: mutable reference created due to call to this method
5252
LL | fn use_mut(&mut self) {}
5353
| ^^^^^^^^^^^^^^^^^^^^^
5454
note: `const` item defined here
55-
--> $DIR/lint-const-item-mutation.rs:22:1
55+
--> $DIR/lint-const-item-mutation.rs:27:1
5656
|
5757
LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw_ptr: 2 as *mut u8 };
5858
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5959

6060
warning: taking a mutable reference to a `const` item
61-
--> $DIR/lint-const-item-mutation.rs:31:5
61+
--> $DIR/lint-const-item-mutation.rs:37:5
6262
|
6363
LL | &mut MY_STRUCT;
6464
| ^^^^^^^^^^^^^^
6565
|
6666
= note: each usage of a `const` item creates a new temporary
6767
= note: the mutable reference will refer to this temporary, not the original `const` item
6868
note: `const` item defined here
69-
--> $DIR/lint-const-item-mutation.rs:22:1
69+
--> $DIR/lint-const-item-mutation.rs:27:1
7070
|
7171
LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw_ptr: 2 as *mut u8 };
7272
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7373

7474
warning: taking a mutable reference to a `const` item
75-
--> $DIR/lint-const-item-mutation.rs:32:5
75+
--> $DIR/lint-const-item-mutation.rs:38:5
7676
|
7777
LL | (&mut MY_STRUCT).use_mut();
7878
| ^^^^^^^^^^^^^^^^
7979
|
8080
= note: each usage of a `const` item creates a new temporary
8181
= note: the mutable reference will refer to this temporary, not the original `const` item
8282
note: `const` item defined here
83-
--> $DIR/lint-const-item-mutation.rs:22:1
83+
--> $DIR/lint-const-item-mutation.rs:27:1
8484
|
8585
LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw_ptr: 2 as *mut u8 };
8686
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8787

88-
warning: 6 warnings emitted
88+
warning: attempting to modify a `const` item
89+
--> $DIR/lint-const-item-mutation.rs:50:5
90+
|
91+
LL | MUTABLE2.msg = "wow";
92+
| ^^^^^^^^^^^^^^^^^^^^
93+
|
94+
= note: each usage of a `const` item creates a new temporary - the original `const` item will not be modified
95+
note: `const` item defined here
96+
--> $DIR/lint-const-item-mutation.rs:30:1
97+
|
98+
LL | const MUTABLE2: Mutable2 = Mutable2 { msg: "", other: String::new() };
99+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
100+
101+
warning: 7 warnings emitted
89102

0 commit comments

Comments
 (0)