Skip to content

Commit b524ade

Browse files
committed
Refactor generic parameter encoder functions
1 parent 719b0d9 commit b524ade

File tree

1 file changed

+18
-42
lines changed

1 file changed

+18
-42
lines changed

src/librustc_metadata/encoder.rs

+18-42
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc::middle::cstore::{LinkagePreference, NativeLibrary,
77
EncodedMetadata, ForeignModule};
88
use rustc::hir::def::CtorKind;
99
use rustc::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefIndex, DefId, LocalDefId, LOCAL_CRATE};
10+
use rustc::hir::GenericParamKind;
1011
use rustc::hir::map::definitions::DefPathTable;
1112
use rustc_data_structures::fingerprint::Fingerprint;
1213
use rustc::middle::dependency_format::Linkage;
@@ -1307,10 +1308,11 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
13071308
}
13081309
}
13091310

1310-
fn encode_info_for_ty_param(&mut self,
1311-
(def_id, Untracked(has_default)): (DefId, Untracked<bool>))
1312-
-> Entry<'tcx> {
1313-
debug!("IsolatedEncoder::encode_info_for_ty_param({:?})", def_id);
1311+
fn encode_info_for_generic_param(
1312+
&mut self,
1313+
(def_id, Untracked(encode_type)): (DefId, Untracked<bool>),
1314+
) -> Entry<'tcx> {
1315+
debug!("IsolatedEncoder::encode_info_for_generic_param({:?})", def_id);
13141316
let tcx = self.tcx;
13151317
Entry {
13161318
kind: EntryKind::Type,
@@ -1321,7 +1323,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
13211323
stability: None,
13221324
deprecation: None,
13231325

1324-
ty: if has_default {
1326+
ty: if encode_type {
13251327
Some(self.encode_item_type(def_id))
13261328
} else {
13271329
None
@@ -1336,29 +1338,6 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
13361338
}
13371339
}
13381340

1339-
fn encode_info_for_const_param(&mut self, def_id: DefId) -> Entry<'tcx> {
1340-
debug!("IsolatedEncoder::encode_info_for_const_param({:?})", def_id);
1341-
let tcx = self.tcx;
1342-
Entry {
1343-
kind: EntryKind::Type,
1344-
visibility: self.lazy(&ty::Visibility::Public),
1345-
span: self.lazy(&tcx.def_span(def_id)),
1346-
attributes: LazySeq::empty(),
1347-
children: LazySeq::empty(),
1348-
stability: None,
1349-
deprecation: None,
1350-
1351-
ty: Some(self.encode_item_type(def_id)),
1352-
inherent_impls: LazySeq::empty(),
1353-
variances: LazySeq::empty(),
1354-
generics: None,
1355-
predicates: None,
1356-
predicates_defined_on: None,
1357-
1358-
mir: None,
1359-
}
1360-
}
1361-
13621341
fn encode_info_for_closure(&mut self, def_id: DefId) -> Entry<'tcx> {
13631342
debug!("IsolatedEncoder::encode_info_for_closure({:?})", def_id);
13641343
let tcx = self.tcx;
@@ -1703,20 +1682,17 @@ impl<'a, 'b, 'tcx> IndexBuilder<'a, 'b, 'tcx> {
17031682

17041683
fn encode_info_for_generics(&mut self, generics: &hir::Generics) {
17051684
for param in &generics.params {
1706-
match param.kind {
1707-
hir::GenericParamKind::Lifetime { .. } => {}
1708-
hir::GenericParamKind::Type { ref default, .. } => {
1709-
let def_id = self.tcx.hir().local_def_id_from_hir_id(param.hir_id);
1710-
let has_default = Untracked(default.is_some());
1711-
let encode_info = IsolatedEncoder::encode_info_for_ty_param;
1712-
self.record(def_id, encode_info, (def_id, has_default));
1713-
}
1714-
hir::GenericParamKind::Const { .. } => {
1715-
let def_id = self.tcx.hir().local_def_id_from_hir_id(param.hir_id);
1716-
let encode_info = IsolatedEncoder::encode_info_for_const_param;
1717-
self.record(def_id, encode_info, def_id);
1718-
}
1719-
}
1685+
let encode_type = match param.kind {
1686+
GenericParamKind::Lifetime { .. } => continue,
1687+
GenericParamKind::Type { ref default, .. } => default.is_some(),
1688+
GenericParamKind::Const { .. } => true,
1689+
};
1690+
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_generic_param,
1694+
(def_id, Untracked(encode_type)),
1695+
);
17201696
}
17211697
}
17221698

0 commit comments

Comments
 (0)