Properly assign to aggregate fields

This commit is contained in:
Oliver Scherer 2018-11-21 10:37:18 +01:00
parent 37fcd5cad5
commit 301ce8b2aa
3 changed files with 26 additions and 1 deletions

View File

@ -267,7 +267,12 @@ fn assign(&mut self, dest: &Place<'tcx>, location: Location) {
}
};
debug!("store to var {:?}", index);
self.local_qualif[index] = Some(self.qualif);
match &mut self.local_qualif[index] {
// update
Some(ref mut qualif) => *qualif = *qualif | self.qualif,
// or insert
qualif @ None => *qualif = Some(self.qualif),
}
return;
}

View File

@ -0,0 +1,11 @@
#![feature(const_let)]
use std::cell::Cell;
const FOO: &(Cell<usize>, bool) = {
let mut a = (Cell::new(0), false);
a.1 = true; // resets `qualif(a)` to `qualif(true)`
&{a} //~ ERROR cannot borrow a constant which may contain interior mutability
};
fn main() {}

View File

@ -0,0 +1,9 @@
error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead
--> $DIR/partial_qualif.rs:8:5
|
LL | &{a} //~ ERROR cannot borrow a constant which may contain interior mutability
| ^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0492`.