From 56219870ee3478c337f8faf104bb7cb1929000dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Tue, 29 Jun 2021 00:00:00 +0000 Subject: [PATCH] Include terminators in instance size estimate For example, drop glue generated for struct below, doesn't have any statements, only terminators. Previously it received an estimate of 0, the new estimate is 13 (6+5 drop terminators, +1 resume, +1 return). struct S { a: String, b: String, c: String, d: String, e: String, f: String, } Originally reported in https://github.com/rust-lang/rust/issues/69382#issue-569392141 --- compiler/rustc_ty_utils/src/ty.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index ebc7b0d0d99..0373033bd28 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -402,7 +402,7 @@ fn instance_def_size_estimate<'tcx>( match instance_def { InstanceDef::Item(..) | InstanceDef::DropGlue(..) => { let mir = tcx.instance_mir(instance_def); - mir.basic_blocks().iter().map(|bb| bb.statements.len()).sum() + mir.basic_blocks().iter().map(|bb| bb.statements.len() + 1).sum() } // Estimate the size of other compiler-generated shims to be 1. _ => 1,