diff options
| author | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2018-11-21 10:37:18 +0100 |
|---|---|---|
| committer | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2018-11-21 10:37:18 +0100 |
| commit | 301ce8b2aa6156ae8dc535ca234e95b04e7c4e4b (patch) | |
| tree | e25b0f8b90b0f01151ae9c76662395c6316dd443 | |
| parent | 37fcd5cad5c314632aede576ae5fbbb1c3ede228 (diff) | |
| download | rust-301ce8b2aa6156ae8dc535ca234e95b04e7c4e4b.tar.gz rust-301ce8b2aa6156ae8dc535ca234e95b04e7c4e4b.zip | |
Properly assign to aggregate fields
| -rw-r--r-- | src/librustc_mir/transform/qualify_consts.rs | 7 | ||||
| -rw-r--r-- | src/test/ui/consts/partial_qualif.rs | 11 | ||||
| -rw-r--r-- | src/test/ui/consts/partial_qualif.stderr | 9 |
3 files changed, 26 insertions, 1 deletions
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 @@ impl<'a, 'tcx> Qualifier<'a, 'tcx, 'tcx> { } }; 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<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() {} \ 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`. |
