11warning: attempting to modify a `const` item
2- --> $DIR/lint-const-item-mutation.rs:17 :5
2+ --> $DIR/lint-const-item-mutation.rs:34 :5
33 |
44LL | 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
99note: `const` item defined here
10- --> $DIR/lint-const-item-mutation.rs:12 :1
10+ --> $DIR/lint-const-item-mutation.rs:26 :1
1111 |
1212LL | const ARRAY: [u8; 1] = [25];
1313 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1414
1515warning: attempting to modify a `const` item
16- --> $DIR/lint-const-item-mutation.rs:18 :5
16+ --> $DIR/lint-const-item-mutation.rs:35 :5
1717 |
1818LL | 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
2222note: `const` item defined here
23- --> $DIR/lint-const-item-mutation.rs:13 :1
23+ --> $DIR/lint-const-item-mutation.rs:27 :1
2424 |
2525LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw_ptr: 2 as *mut u8 };
2626 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2727
2828warning: attempting to modify a `const` item
29- --> $DIR/lint-const-item-mutation.rs:19 :5
29+ --> $DIR/lint-const-item-mutation.rs:36 :5
3030 |
3131LL | 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
3535note: `const` item defined here
36- --> $DIR/lint-const-item-mutation.rs:13 :1
36+ --> $DIR/lint-const-item-mutation.rs:27 :1
3737 |
3838LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw_ptr: 2 as *mut u8 };
3939 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4040
4141warning: taking a mutable reference to a `const` item
42- --> $DIR/lint-const-item-mutation.rs:20 :5
42+ --> $DIR/lint-const-item-mutation.rs:37 :5
4343 |
4444LL | MY_STRUCT.use_mut();
4545 | ^^^^^^^^^^^^^^^^^^^
@@ -52,38 +52,76 @@ note: mutable reference created due to call to this method
5252LL | fn use_mut(&mut self) {}
5353 | ^^^^^^^^^^^^^^^^^^^^^
5454note: `const` item defined here
55- --> $DIR/lint-const-item-mutation.rs:13 :1
55+ --> $DIR/lint-const-item-mutation.rs:27 :1
5656 |
5757LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw_ptr: 2 as *mut u8 };
5858 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5959
6060warning: taking a mutable reference to a `const` item
61- --> $DIR/lint-const-item-mutation.rs:21 :5
61+ --> $DIR/lint-const-item-mutation.rs:38 :5
6262 |
6363LL | &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
6868note: `const` item defined here
69- --> $DIR/lint-const-item-mutation.rs:13 :1
69+ --> $DIR/lint-const-item-mutation.rs:27 :1
7070 |
7171LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw_ptr: 2 as *mut u8 };
7272 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7373
7474warning: taking a mutable reference to a `const` item
75- --> $DIR/lint-const-item-mutation.rs:22 :5
75+ --> $DIR/lint-const-item-mutation.rs:39 :5
7676 |
7777LL | (&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
8282note: `const` item defined here
83- --> $DIR/lint-const-item-mutation.rs:13 :1
83+ --> $DIR/lint-const-item-mutation.rs:27 :1
8484 |
8585LL | 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:51: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: taking a mutable reference to a `const` item
102+ --> $DIR/lint-const-item-mutation.rs:52:5
103+ |
104+ LL | VEC.push(0);
105+ | ^^^^^^^^^^^
106+ |
107+ = note: each usage of a `const` item creates a new temporary
108+ = note: the mutable reference will refer to this temporary, not the original `const` item
109+ note: mutable reference created due to call to this method
110+ --> $SRC_DIR/alloc/src/vec.rs:LL:COL
111+ |
112+ LL | / pub fn push(&mut self, value: T) {
113+ LL | | // This will panic or abort if we would allocate > isize::MAX bytes
114+ LL | | // or if the length increment would overflow for zero-sized types.
115+ LL | | if self.len == self.buf.capacity() {
116+ ... |
117+ LL | | }
118+ LL | | }
119+ | |_____^
120+ note: `const` item defined here
121+ --> $DIR/lint-const-item-mutation.rs:31:1
122+ |
123+ LL | const VEC: Vec<i32> = Vec::new();
124+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
125+
126+ warning: 8 warnings emitted
89127
0 commit comments