diff options
| author | Oliver Schneider <github35764891676564198441@oli-obk.de> | 2018-06-03 19:00:22 +0200 |
|---|---|---|
| committer | Oliver Schneider <github35764891676564198441@oli-obk.de> | 2018-06-03 19:06:31 +0200 |
| commit | 9d613c27b74e7192d21e52ba7f552ce9c542c585 (patch) | |
| tree | 610257c0c637c5932683218d0cacf631dc84d729 /src/librustc_mir/transform | |
| parent | 3575be60eab140e69e5a75fe5c3b4119c2a17179 (diff) | |
| download | rust-9d613c27b74e7192d21e52ba7f552ce9c542c585.tar.gz rust-9d613c27b74e7192d21e52ba7f552ce9c542c585.zip | |
Do not promote union field accesses
Diffstat (limited to 'src/librustc_mir/transform')
| -rw-r--r-- | src/librustc_mir/transform/qualify_consts.rs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 03ca85faaff..f3fba5b47be 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -566,8 +566,14 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { ProjectionElem::Field(..) | ProjectionElem::Index(_) => { - if this.mode != Mode::Fn && - this.qualif.intersects(Qualif::STATIC) { + if this.mode == Mode::Fn { + let base_ty = proj.base.ty(this.mir, this.tcx).to_ty(this.tcx); + if let Some(def) = base_ty.ty_adt_def() { + if def.is_union() { + this.not_const(); + } + } + } else if this.qualif.intersects(Qualif::STATIC) { span_err!(this.tcx.sess, this.span, E0494, "cannot refer to the interior of another \ static, use a constant instead"); |
