Skip to content

Commit 6217ee1

Browse files
committed
Add EntryKind::TypeParam and EntryKind::ConstParam
1 parent 7a23725 commit 6217ee1

File tree

3 files changed

+42
-21
lines changed

3 files changed

+42
-21
lines changed

src/librustc_metadata/decoder.rs

+2
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,8 @@ impl<'tcx> EntryKind<'tcx> {
413413
EntryKind::ForeignFn(_) => Def::Fn(did),
414414
EntryKind::Method(_) => Def::Method(did),
415415
EntryKind::Type => Def::TyAlias(did),
416+
EntryKind::TypeParam => Def::TyParam(did),
417+
EntryKind::ConstParam => Def::ConstParam(did),
416418
EntryKind::Existential => Def::Existential(did),
417419
EntryKind::AssociatedType(_) => Def::AssociatedTy(did),
418420
EntryKind::AssociatedExistential(_) => Def::AssociatedExistential(did),

src/librustc_metadata/encoder.rs

+35-20
Original file line numberDiff line numberDiff line change
@@ -1308,26 +1308,22 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
13081308
}
13091309
}
13101310

1311-
fn encode_info_for_ty_in_generic_param(
1311+
fn encode_info_for_generic_param(
13121312
&mut self,
1313-
(def_id, Untracked(encode_type)): (DefId, Untracked<bool>),
1313+
def_id: DefId,
1314+
entry_kind: EntryKind<'tcx>,
1315+
encode_type: bool,
13141316
) -> Entry<'tcx> {
1315-
debug!("IsolatedEncoder::encode_info_for_ty_in_generic_param({:?})", def_id);
13161317
let tcx = self.tcx;
13171318
Entry {
1318-
kind: EntryKind::Type,
1319+
kind: entry_kind,
13191320
visibility: self.lazy(&ty::Visibility::Public),
13201321
span: self.lazy(&tcx.def_span(def_id)),
13211322
attributes: LazySeq::empty(),
13221323
children: LazySeq::empty(),
13231324
stability: None,
13241325
deprecation: None,
1325-
1326-
ty: if encode_type {
1327-
Some(self.encode_item_type(def_id))
1328-
} else {
1329-
None
1330-
},
1326+
ty: if encode_type { Some(self.encode_item_type(def_id)) } else { None },
13311327
inherent_impls: LazySeq::empty(),
13321328
variances: LazySeq::empty(),
13331329
generics: None,
@@ -1338,6 +1334,22 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
13381334
}
13391335
}
13401336

1337+
fn encode_info_for_ty_param(
1338+
&mut self,
1339+
(def_id, Untracked(encode_type)): (DefId, Untracked<bool>),
1340+
) -> Entry<'tcx> {
1341+
debug!("IsolatedEncoder::encode_info_for_ty_param({:?})", def_id);
1342+
self.encode_info_for_generic_param(def_id, EntryKind::TypeParam, encode_type)
1343+
}
1344+
1345+
fn encode_info_for_const_param(
1346+
&mut self,
1347+
def_id: DefId,
1348+
) -> Entry<'tcx> {
1349+
debug!("IsolatedEncoder::encode_info_for_const_param({:?})", def_id);
1350+
self.encode_info_for_generic_param(def_id, EntryKind::ConstParam, true)
1351+
}
1352+
13411353
fn encode_info_for_closure(&mut self, def_id: DefId) -> Entry<'tcx> {
13421354
debug!("IsolatedEncoder::encode_info_for_closure({:?})", def_id);
13431355
let tcx = self.tcx;
@@ -1682,17 +1694,20 @@ impl<'a, 'b, 'tcx> IndexBuilder<'a, 'b, 'tcx> {
16821694

16831695
fn encode_info_for_generics(&mut self, generics: &hir::Generics) {
16841696
for param in &generics.params {
1685-
let encode_type = match param.kind {
1686-
GenericParamKind::Lifetime { .. } => continue,
1687-
GenericParamKind::Type { ref default, .. } => default.is_some(),
1688-
GenericParamKind::Const { .. } => true,
1689-
};
16901697
let def_id = self.tcx.hir().local_def_id_from_hir_id(param.hir_id);
1691-
self.record(
1692-
def_id,
1693-
IsolatedEncoder::encode_info_for_ty_in_generic_param,
1694-
(def_id, Untracked(encode_type)),
1695-
);
1698+
match param.kind {
1699+
GenericParamKind::Lifetime { .. } => continue,
1700+
GenericParamKind::Type { ref default, .. } => {
1701+
self.record(
1702+
def_id,
1703+
IsolatedEncoder::encode_info_for_ty_param,
1704+
(def_id, Untracked(default.is_some())),
1705+
);
1706+
}
1707+
GenericParamKind::Const { .. } => {
1708+
self.record(def_id, IsolatedEncoder::encode_info_for_const_param, def_id);
1709+
}
1710+
}
16961711
}
16971712
}
16981713

src/librustc_metadata/schema.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ pub enum EntryKind<'tcx> {
299299
ForeignType,
300300
GlobalAsm,
301301
Type,
302+
TypeParam,
303+
ConstParam,
302304
Existential,
303305
Enum(ReprOptions),
304306
Field,
@@ -335,7 +337,9 @@ impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for EntryKind<'gcx> {
335337
EntryKind::ForeignType |
336338
EntryKind::Field |
337339
EntryKind::Existential |
338-
EntryKind::Type => {
340+
EntryKind::Type |
341+
EntryKind::TypeParam |
342+
EntryKind::ConstParam => {
339343
// Nothing else to hash here.
340344
}
341345
EntryKind::Const(qualif, ref const_data) => {

0 commit comments

Comments
 (0)