From 15d2759d909ccb4b3146654a76845ef5e1d5f6cb Mon Sep 17 00:00:00 2001 From: varkor Date: Thu, 12 Apr 2018 17:51:08 +0100 Subject: [PATCH] Rename `has_type_parameters` to `requires_monomorphization` --- src/librustc/ty/mod.rs | 8 +++++--- src/librustc_metadata/encoder.rs | 2 +- src/librustc_mir/monomorphize/collector.rs | 2 +- src/librustc_mir/transform/const_prop.rs | 6 +++--- src/librustc_trans/back/symbol_export.rs | 2 +- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 45005fd543d..218be48da24 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -819,13 +819,15 @@ impl<'a, 'gcx, 'tcx> Generics { }) } - 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 } diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index 9ebffa4c744..3de90abd966 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -929,7 +929,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, '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; diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index 8646df02e51..2bc4e651dd3 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -1076,7 +1076,7 @@ impl<'b, 'a, 'v> RootCollector<'b, 'a, 'v> { 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>, diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 111783fff7e..80603959ec2 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -184,7 +184,7 @@ impl<'b, 'a, 'tcx:'b> ConstPropagator<'b, 'a, '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 @@ impl<'b, 'a, 'tcx:'b> ConstPropagator<'b, 'a, 'tcx> { 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 @@ impl<'b, 'a, 'tcx:'b> ConstPropagator<'b, 'a, 'tcx> { 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; } diff --git a/src/librustc_trans/back/symbol_export.rs b/src/librustc_trans/back/symbol_export.rs index c4a2d179801..d7785522069 100644 --- a/src/librustc_trans/back/symbol_export.rs +++ b/src/librustc_trans/back/symbol_export.rs @@ -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) {