提交 15d2759d 编写于 作者: V varkor

Rename `has_type_parameters` to `requires_monomorphization`

上级 a9622dc5
......@@ -819,13 +819,15 @@ pub fn types(&self) -> impl DoubleEndedIterator<Item = &TypeParameterDef> {
})
}
pub fn has_type_parameters(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> bool {
if self.types().count() != 0 {
pub fn requires_monomorphization(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> bool {
if self.params.iter().any(|p| {
if let GenericParam::Type(_) = p { true } else { false }
}) {
return true;
}
if let Some(parent_def_id) = self.parent {
let parent = tcx.generics_of(parent_def_id);
parent.has_type_parameters(tcx)
parent.requires_monomorphization(tcx)
} else {
false
}
......
......@@ -929,7 +929,7 @@ fn encode_info_for_impl_item(&mut self, def_id: DefId) -> Entry<'tcx> {
hir::ImplItemKind::Const(..) => true,
hir::ImplItemKind::Method(ref sig, _) => {
let generics = self.tcx.generics_of(def_id);
let needs_inline = (generics.has_type_parameters(self.tcx) ||
let needs_inline = (generics.requires_monomorphization(self.tcx) ||
tcx.trans_fn_attrs(def_id).requests_inline()) &&
!self.metadata_output_only();
let is_const_fn = sig.constness == hir::Constness::Const;
......
......@@ -1076,7 +1076,7 @@ fn push_extra_entry_roots(&mut self) {
fn item_has_type_parameters<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> bool {
let generics = tcx.generics_of(def_id);
generics.has_type_parameters(tcx)
generics.requires_monomorphization(tcx)
}
fn create_mono_items_for_default_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
......
......@@ -184,7 +184,7 @@ fn eval_constant(&mut self, c: &Constant<'tcx>) -> Option<Const<'tcx>> {
// evaluate the promoted and replace the constant with the evaluated result
Literal::Promoted { index } => {
let generics = self.tcx.generics_of(self.source.def_id);
if generics.has_type_parameters(self.tcx) {
if generics.requires_monomorphization(self.tcx) {
// FIXME: can't handle code with generics
return None;
}
......@@ -295,7 +295,7 @@ fn const_prop(
self.source.def_id
};
let generics = self.tcx.generics_of(def_id);
if generics.has_type_parameters(self.tcx) {
if generics.requires_monomorphization(self.tcx) {
// FIXME: can't handle code with generics
return None;
}
......@@ -317,7 +317,7 @@ fn const_prop(
self.source.def_id
};
let generics = self.tcx.generics_of(def_id);
if generics.has_type_parameters(self.tcx) {
if generics.requires_monomorphization(self.tcx) {
// FIXME: can't handle code with generics
return None;
}
......
......@@ -117,7 +117,7 @@ fn reachable_non_generics_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
}) => {
let def_id = tcx.hir.local_def_id(node_id);
let generics = tcx.generics_of(def_id);
if !generics.has_type_parameters(tcx) &&
if !generics.requires_monomorphization(tcx) &&
// Functions marked with #[inline] are only ever translated
// with "internal" linkage and are never exported.
!Instance::mono(tcx, def_id).def.requires_local(tcx) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册