]> git.lizzy.rs Git - rust.git/commitdiff
Add own_requires_monomorphization
authorvarkor <github@varkor.com>
Wed, 17 Apr 2019 22:09:22 +0000 (23:09 +0100)
committervarkor <github@varkor.com>
Wed, 17 Apr 2019 23:30:50 +0000 (00:30 +0100)
src/librustc/ty/mod.rs
src/librustc_mir/monomorphize/collector.rs
src/librustc_mir/transform/check_unsafety.rs

index 4aca01d9411c79c47f0a41716acc268895ec2a6b..56fafacd722be19da753720e98683c4f4e0c8651 100644 (file)
@@ -934,12 +934,10 @@ pub fn own_counts(&self) -> GenericParamCount {
     }
 
     pub fn requires_monomorphization(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> bool {
-        for param in &self.params {
-            match param.kind {
-                GenericParamDefKind::Type { .. } | GenericParamDefKind::Const => return true,
-                GenericParamDefKind::Lifetime => {}
-            }
+        if self.own_requires_monomorphization() {
+            return true;
         }
+
         if let Some(parent_def_id) = self.parent {
             let parent = tcx.generics_of(parent_def_id);
             parent.requires_monomorphization(tcx)
@@ -948,6 +946,16 @@ pub fn requires_monomorphization(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> bool {
         }
     }
 
+    pub fn own_requires_monomorphization(&self) -> bool {
+        for param in &self.params {
+            match param.kind {
+                GenericParamDefKind::Type { .. } | GenericParamDefKind::Const => return true,
+                GenericParamDefKind::Lifetime => {}
+            }
+        }
+        false
+    }
+
     pub fn region_param(&'tcx self,
                         param: &EarlyBoundRegion,
                         tcx: TyCtxt<'a, 'gcx, 'tcx>)
index af875c2f9e8a183ea13bbb3a93797849421b3005..1815c53aa126f45c091c2cbbd45f8d356c54f0f8 100644 (file)
@@ -1135,8 +1135,7 @@ fn create_mono_items_for_default_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
                         continue;
                     }
 
-                    let counts = tcx.generics_of(method.def_id).own_counts();
-                    if counts.types + counts.consts != 0 {
+                    if tcx.generics_of(method.def_id).own_requires_monomorphization() {
                         continue;
                     }
 
index 93f3afe1aea6b85f6c94af606ae2489c075801bb..c9cccb2b03ac4ec9dad19cdd7e8c3d5af9a60cd1 100644 (file)
@@ -560,8 +560,7 @@ fn unsafe_derive_on_repr_packed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: D
 
     // FIXME: when we make this a hard error, this should have its
     // own error code.
-    let counts = tcx.generics_of(def_id).own_counts();
-    let message = if counts.types + counts.consts != 0 {
+    let message = if tcx.generics_of(def_id).own_requires_monomorphization() {
         "#[derive] can't be used on a #[repr(packed)] struct with \
          type or const parameters (error E0133)".to_string()
     } else {