Skip to content

Commit 301ce8b

Browse files
committed
Properly assign to aggregate fields
1 parent 37fcd5c commit 301ce8b

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/librustc_mir/transform/qualify_consts.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,12 @@ impl<'a, 'tcx> Qualifier<'a, 'tcx, 'tcx> {
267267
}
268268
};
269269
debug!("store to var {:?}", index);
270-
self.local_qualif[index] = Some(self.qualif);
270+
match &mut self.local_qualif[index] {
271+
// update
272+
Some(ref mut qualif) => *qualif = *qualif | self.qualif,
273+
// or insert
274+
qualif @ None => *qualif = Some(self.qualif),
275+
}
271276
return;
272277
}
273278

src/test/ui/consts/partial_qualif.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![feature(const_let)]
2+
3+
use std::cell::Cell;
4+
5+
const FOO: &(Cell<usize>, bool) = {
6+
let mut a = (Cell::new(0), false);
7+
a.1 = true; // resets `qualif(a)` to `qualif(true)`
8+
&{a} //~ ERROR cannot borrow a constant which may contain interior mutability
9+
};
10+
11+
fn main() {}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead
2+
--> $DIR/partial_qualif.rs:8:5
3+
|
4+
LL | &{a} //~ ERROR cannot borrow a constant which may contain interior mutability
5+
| ^^^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0492`.

0 commit comments

Comments
 (0)