Skip to content

Commit e148689

Browse files
committed
do not encode constness for constructors
since they are always const
1 parent a6525d5 commit e148689

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::any::Any;
22
use std::mem;
33
use std::sync::Arc;
44

5+
use rustc_hir::Constness;
56
use rustc_hir::attrs::Deprecation;
67
use rustc_hir::def::{CtorKind, DefKind};
78
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LOCAL_CRATE};
@@ -255,7 +256,13 @@ provide! { tcx, def_id, other, cdata,
255256
def_kind => { cdata.def_kind(tcx, def_id.index) }
256257
impl_parent => { table }
257258
defaultness => { table_direct }
258-
constness => { table_direct }
259+
constness => {
260+
if let DefKind::Ctor(_, CtorKind::Fn) = cdata.def_kind(tcx, def_id.index) {
261+
Constness::Const
262+
} else {
263+
cdata.root.tables.constness.get((cdata, tcx), def_id.index)
264+
}
265+
}
259266
const_conditions => { table }
260267
explicit_implied_const_bounds => { table_defaulted_array }
261268
coerce_unsized_info => {

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,11 +1306,9 @@ fn should_encode_fn_sig(def_kind: DefKind) -> bool {
13061306

13071307
fn should_encode_constness(def_kind: DefKind) -> bool {
13081308
match def_kind {
1309-
DefKind::Fn
1310-
| DefKind::AssocFn
1311-
| DefKind::Closure
1312-
| DefKind::Ctor(_, CtorKind::Fn)
1313-
| DefKind::Impl { of_trait: false } => true,
1309+
DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::Impl { of_trait: false } => {
1310+
true
1311+
}
13141312

13151313
DefKind::Struct
13161314
| DefKind::Union
@@ -1337,7 +1335,7 @@ fn should_encode_constness(def_kind: DefKind) -> bool {
13371335
| DefKind::LifetimeParam
13381336
| DefKind::GlobalAsm
13391337
| DefKind::ExternCrate
1340-
| DefKind::Ctor(_, CtorKind::Const)
1338+
| DefKind::Ctor(..)
13411339
| DefKind::Variant
13421340
| DefKind::SyntheticCoroutineBody => false,
13431341
}

0 commit comments

Comments
 (0)