Skip to content

Commit a759e2c

Browse files
committed
Add own_requires_monomorphization
1 parent 6ed6f14 commit a759e2c

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

src/librustc/ty/mod.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -934,12 +934,10 @@ impl<'a, 'gcx, 'tcx> Generics {
934934
}
935935

936936
pub fn requires_monomorphization(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> bool {
937-
for param in &self.params {
938-
match param.kind {
939-
GenericParamDefKind::Type { .. } | GenericParamDefKind::Const => return true,
940-
GenericParamDefKind::Lifetime => {}
941-
}
937+
if self.own_requires_monomorphization() {
938+
return true;
942939
}
940+
943941
if let Some(parent_def_id) = self.parent {
944942
let parent = tcx.generics_of(parent_def_id);
945943
parent.requires_monomorphization(tcx)
@@ -948,6 +946,16 @@ impl<'a, 'gcx, 'tcx> Generics {
948946
}
949947
}
950948

949+
pub fn own_requires_monomorphization(&self) -> bool {
950+
for param in &self.params {
951+
match param.kind {
952+
GenericParamDefKind::Type { .. } | GenericParamDefKind::Const => return true,
953+
GenericParamDefKind::Lifetime => {}
954+
}
955+
}
956+
false
957+
}
958+
951959
pub fn region_param(&'tcx self,
952960
param: &EarlyBoundRegion,
953961
tcx: TyCtxt<'a, 'gcx, 'tcx>)

src/librustc_mir/monomorphize/collector.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,8 +1135,7 @@ fn create_mono_items_for_default_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
11351135
continue;
11361136
}
11371137

1138-
let counts = tcx.generics_of(method.def_id).own_counts();
1139-
if counts.types + counts.consts != 0 {
1138+
if tcx.generics_of(method.def_id).own_requires_monomorphization() {
11401139
continue;
11411140
}
11421141

src/librustc_mir/transform/check_unsafety.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,7 @@ fn unsafe_derive_on_repr_packed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: D
560560

561561
// FIXME: when we make this a hard error, this should have its
562562
// own error code.
563-
let counts = tcx.generics_of(def_id).own_counts();
564-
let message = if counts.types + counts.consts != 0 {
563+
let message = if tcx.generics_of(def_id).own_requires_monomorphization() {
565564
"#[derive] can't be used on a #[repr(packed)] struct with \
566565
type or const parameters (error E0133)".to_string()
567566
} else {

0 commit comments

Comments
 (0)