diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index f8ecd963457..51e590fe292 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -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; } diff --git a/src/test/ui/consts/partial_qualif.rs b/src/test/ui/consts/partial_qualif.rs new file mode 100644 index 00000000000..bb3fc92d4fb --- /dev/null +++ b/src/test/ui/consts/partial_qualif.rs @@ -0,0 +1,11 @@ +#![feature(const_let)] + +use std::cell::Cell; + +const FOO: &(Cell, 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() {} \ No newline at end of file diff --git a/src/test/ui/consts/partial_qualif.stderr b/src/test/ui/consts/partial_qualif.stderr new file mode 100644 index 00000000000..d695f64e2c3 --- /dev/null +++ b/src/test/ui/consts/partial_qualif.stderr @@ -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`.