Skip to content

Commit 64bdf1b

Browse files
committed
Set NON_ZERO_SIZED flag correctly for struct/union ctors
And for methods/functions as well, they are zero-sized now
1 parent c95b280 commit 64bdf1b

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

src/librustc_passes/consts.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use rustc_const_eval::ErrKind::{ErroneousReferencedConstant, MiscBinaryOp, NonCo
3333
use rustc_const_eval::ErrKind::UnresolvedPath;
3434
use rustc_const_eval::EvalHint::ExprTypeChecked;
3535
use rustc_const_math::{ConstMathErr, Op};
36-
use rustc::hir::def::Def;
36+
use rustc::hir::def::{Def, CtorKind};
3737
use rustc::hir::def_id::DefId;
3838
use rustc::middle::expr_use_visitor as euv;
3939
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
489489
}
490490
hir::ExprPath(..) => {
491491
match v.tcx.expect_def(e.id) {
492-
Def::VariantCtor(..) => {
493-
// Count the discriminator or function pointer.
494-
v.add_qualif(ConstQualif::NON_ZERO_SIZED);
495-
}
496-
Def::StructCtor(..) => {
497-
if let ty::TyFnDef(..) = node_ty.sty {
498-
// Count the function pointer.
499-
v.add_qualif(ConstQualif::NON_ZERO_SIZED);
500-
}
501-
}
502-
Def::Fn(..) | Def::Method(..) => {
503-
// Count the function pointer.
492+
Def::VariantCtor(_, CtorKind::Const) => {
493+
// Size is determined by the whole enum, may be non-zero.
504494
v.add_qualif(ConstQualif::NON_ZERO_SIZED);
505495
}
496+
Def::VariantCtor(..) | Def::StructCtor(..) |
497+
Def::Fn(..) | Def::Method(..) => {}
506498
Def::Static(..) => {
507499
match v.mode {
508500
Mode::Static | Mode::StaticMut => {}
@@ -539,9 +531,9 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>, e: &hir::Expr, node
539531
}
540532
// The callee is an arbitrary expression, it doesn't necessarily have a definition.
541533
let is_const = match v.tcx.expect_def_or_none(callee.id) {
542-
Some(Def::StructCtor(..)) => true,
543-
Some(Def::VariantCtor(..)) => {
544-
// Count the discriminator.
534+
Some(Def::StructCtor(_, CtorKind::Fn)) |
535+
Some(Def::VariantCtor(_, CtorKind::Fn)) => {
536+
// `NON_ZERO_SIZED` is about the call result, not about the ctor itself.
545537
v.add_qualif(ConstQualif::NON_ZERO_SIZED);
546538
true
547539
}

0 commit comments

Comments
 (0)