-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #77324 - Aaron1011:fix/const-item-mutation-ptr, r=pet…
…rochenkov Don't fire `const_item_mutation` lint on writes through a pointer Fixes #77321
- Loading branch information
Showing
3 changed files
with
44 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,89 @@ | ||
warning: attempting to modify a `const` item | ||
--> $DIR/lint-const-item-mutation.rs:15:5 | ||
--> $DIR/lint-const-item-mutation.rs:17:5 | ||
| | ||
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:11:1 | ||
--> $DIR/lint-const-item-mutation.rs:12:1 | ||
| | ||
LL | const ARRAY: [u8; 1] = [25]; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
warning: attempting to modify a `const` item | ||
--> $DIR/lint-const-item-mutation.rs:16:5 | ||
--> $DIR/lint-const-item-mutation.rs:18: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:12:1 | ||
--> $DIR/lint-const-item-mutation.rs:13:1 | ||
| | ||
LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'] }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
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:17:5 | ||
--> $DIR/lint-const-item-mutation.rs:19: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:12:1 | ||
--> $DIR/lint-const-item-mutation.rs:13:1 | ||
| | ||
LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'] }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
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:18:5 | ||
--> $DIR/lint-const-item-mutation.rs:20:5 | ||
| | ||
LL | 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: mutable reference created due to call to this method | ||
--> $DIR/lint-const-item-mutation.rs:8:5 | ||
--> $DIR/lint-const-item-mutation.rs:9:5 | ||
| | ||
LL | fn use_mut(&mut self) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
note: `const` item defined here | ||
--> $DIR/lint-const-item-mutation.rs:12:1 | ||
--> $DIR/lint-const-item-mutation.rs:13:1 | ||
| | ||
LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'] }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
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:19:5 | ||
--> $DIR/lint-const-item-mutation.rs:21:5 | ||
| | ||
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:12:1 | ||
--> $DIR/lint-const-item-mutation.rs:13:1 | ||
| | ||
LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'] }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
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:20:5 | ||
--> $DIR/lint-const-item-mutation.rs:22:5 | ||
| | ||
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:12:1 | ||
--> $DIR/lint-const-item-mutation.rs:13:1 | ||
| | ||
LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'] }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw_ptr: 2 as *mut u8 }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
warning: 6 warnings emitted | ||
|