about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2016-09-15 00:51:46 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2016-10-04 22:20:38 +0300
commit64bdf1b74b8b2df8b13f51201277e35d948b154a (patch)
tree273bec7e46e16899e9b89c0418cbff6aade06a33
parentc95b280d723ae6a6243b04ac06be100c622634b4 (diff)
downloadrust-64bdf1b74b8b2df8b13f51201277e35d948b154a.tar.gz
rust-64bdf1b74b8b2df8b13f51201277e35d948b154a.zip
Set `NON_ZERO_SIZED` flag correctly for struct/union ctors
And for methods/functions as well, they are zero-sized now
-rw-r--r--src/librustc_passes/consts.rs24
1 files changed, 8 insertions, 16 deletions
diff --git a/src/librustc_passes/consts.rs b/src/librustc_passes/consts.rs
index 3d4add0769a..ee731dd042e 100644
--- a/src/librustc_passes/consts.rs
+++ b/src/librustc_passes/consts.rs
@@ -33,7 +33,7 @@ use rustc_const_eval::ErrKind::{ErroneousReferencedConstant, MiscBinaryOp, NonCo
 use rustc_const_eval::ErrKind::UnresolvedPath;
 use rustc_const_eval::EvalHint::ExprTypeChecked;
 use rustc_const_math::{ConstMathErr, Op};
-use rustc::hir::def::Def;
+use rustc::hir::def::{Def, CtorKind};
 use rustc::hir::def_id::DefId;
 use rustc::middle::expr_use_visitor as euv;
 use rustc::middle::mem_categorization as mc;
@@ -489,20 +489,12 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>, e: &hir::Expr, node
         }
         hir::ExprPath(..) => {
             match v.tcx.expect_def(e.id) {
-                Def::VariantCtor(..) => {
-                    // Count the discriminator or function pointer.
-                    v.add_qualif(ConstQualif::NON_ZERO_SIZED);
-                }
-                Def::StructCtor(..) => {
-                    if let ty::TyFnDef(..) = node_ty.sty {
-                        // Count the function pointer.
-                        v.add_qualif(ConstQualif::NON_ZERO_SIZED);
-                    }
-                }
-                Def::Fn(..) | Def::Method(..) => {
-                    // Count the function pointer.
+                Def::VariantCtor(_, CtorKind::Const) => {
+                    // Size is determined by the whole enum, may be non-zero.
                     v.add_qualif(ConstQualif::NON_ZERO_SIZED);
                 }
+                Def::VariantCtor(..) | Def::StructCtor(..) |
+                Def::Fn(..) | Def::Method(..) => {}
                 Def::Static(..) => {
                     match v.mode {
                         Mode::Static | Mode::StaticMut => {}
@@ -539,9 +531,9 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>, e: &hir::Expr, node
             }
             // The callee is an arbitrary expression, it doesn't necessarily have a definition.
             let is_const = match v.tcx.expect_def_or_none(callee.id) {
-                Some(Def::StructCtor(..)) => true,
-                Some(Def::VariantCtor(..)) => {
-                    // Count the discriminator.
+                Some(Def::StructCtor(_, CtorKind::Fn)) |
+                Some(Def::VariantCtor(_, CtorKind::Fn)) => {
+                    // `NON_ZERO_SIZED` is about the call result, not about the ctor itself.
                     v.add_qualif(ConstQualif::NON_ZERO_SIZED);
                     true
                 }