Refactor generic parameter encoder functions
This commit is contained in:
parent
719b0d9849
commit
b524ade782
1 changed files with 18 additions and 42 deletions
|
|
@ -7,6 +7,7 @@ use rustc::middle::cstore::{LinkagePreference, NativeLibrary,
|
|||
EncodedMetadata, ForeignModule};
|
||||
use rustc::hir::def::CtorKind;
|
||||
use rustc::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefIndex, DefId, LocalDefId, LOCAL_CRATE};
|
||||
use rustc::hir::GenericParamKind;
|
||||
use rustc::hir::map::definitions::DefPathTable;
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
use rustc::middle::dependency_format::Linkage;
|
||||
|
|
@ -1307,10 +1308,11 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn encode_info_for_ty_param(&mut self,
|
||||
(def_id, Untracked(has_default)): (DefId, Untracked<bool>))
|
||||
-> Entry<'tcx> {
|
||||
debug!("IsolatedEncoder::encode_info_for_ty_param({:?})", def_id);
|
||||
fn encode_info_for_generic_param(
|
||||
&mut self,
|
||||
(def_id, Untracked(encode_type)): (DefId, Untracked<bool>),
|
||||
) -> Entry<'tcx> {
|
||||
debug!("IsolatedEncoder::encode_info_for_generic_param({:?})", def_id);
|
||||
let tcx = self.tcx;
|
||||
Entry {
|
||||
kind: EntryKind::Type,
|
||||
|
|
@ -1321,7 +1323,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
|
|||
stability: None,
|
||||
deprecation: None,
|
||||
|
||||
ty: if has_default {
|
||||
ty: if encode_type {
|
||||
Some(self.encode_item_type(def_id))
|
||||
} else {
|
||||
None
|
||||
|
|
@ -1336,29 +1338,6 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn encode_info_for_const_param(&mut self, def_id: DefId) -> Entry<'tcx> {
|
||||
debug!("IsolatedEncoder::encode_info_for_const_param({:?})", def_id);
|
||||
let tcx = self.tcx;
|
||||
Entry {
|
||||
kind: EntryKind::Type,
|
||||
visibility: self.lazy(&ty::Visibility::Public),
|
||||
span: self.lazy(&tcx.def_span(def_id)),
|
||||
attributes: LazySeq::empty(),
|
||||
children: LazySeq::empty(),
|
||||
stability: None,
|
||||
deprecation: None,
|
||||
|
||||
ty: Some(self.encode_item_type(def_id)),
|
||||
inherent_impls: LazySeq::empty(),
|
||||
variances: LazySeq::empty(),
|
||||
generics: None,
|
||||
predicates: None,
|
||||
predicates_defined_on: None,
|
||||
|
||||
mir: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn encode_info_for_closure(&mut self, def_id: DefId) -> Entry<'tcx> {
|
||||
debug!("IsolatedEncoder::encode_info_for_closure({:?})", def_id);
|
||||
let tcx = self.tcx;
|
||||
|
|
@ -1703,20 +1682,17 @@ impl<'a, 'b, 'tcx> IndexBuilder<'a, 'b, 'tcx> {
|
|||
|
||||
fn encode_info_for_generics(&mut self, generics: &hir::Generics) {
|
||||
for param in &generics.params {
|
||||
match param.kind {
|
||||
hir::GenericParamKind::Lifetime { .. } => {}
|
||||
hir::GenericParamKind::Type { ref default, .. } => {
|
||||
let def_id = self.tcx.hir().local_def_id_from_hir_id(param.hir_id);
|
||||
let has_default = Untracked(default.is_some());
|
||||
let encode_info = IsolatedEncoder::encode_info_for_ty_param;
|
||||
self.record(def_id, encode_info, (def_id, has_default));
|
||||
}
|
||||
hir::GenericParamKind::Const { .. } => {
|
||||
let def_id = self.tcx.hir().local_def_id_from_hir_id(param.hir_id);
|
||||
let encode_info = IsolatedEncoder::encode_info_for_const_param;
|
||||
self.record(def_id, encode_info, def_id);
|
||||
}
|
||||
}
|
||||
let encode_type = match param.kind {
|
||||
GenericParamKind::Lifetime { .. } => continue,
|
||||
GenericParamKind::Type { ref default, .. } => default.is_some(),
|
||||
GenericParamKind::Const { .. } => true,
|
||||
};
|
||||
let def_id = self.tcx.hir().local_def_id_from_hir_id(param.hir_id);
|
||||
self.record(
|
||||
def_id,
|
||||
IsolatedEncoder::encode_info_for_generic_param,
|
||||
(def_id, Untracked(encode_type)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue