Add own_requires_monomorphization
This commit is contained in:
parent
6ed6f1461d
commit
a759e2cc12
3 changed files with 15 additions and 9 deletions
|
@ -934,12 +934,10 @@ impl<'a, 'gcx, 'tcx> Generics {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn requires_monomorphization(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> bool {
|
pub fn requires_monomorphization(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> bool {
|
||||||
for param in &self.params {
|
if self.own_requires_monomorphization() {
|
||||||
match param.kind {
|
return true;
|
||||||
GenericParamDefKind::Type { .. } | GenericParamDefKind::Const => return true,
|
|
||||||
GenericParamDefKind::Lifetime => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(parent_def_id) = self.parent {
|
if let Some(parent_def_id) = self.parent {
|
||||||
let parent = tcx.generics_of(parent_def_id);
|
let parent = tcx.generics_of(parent_def_id);
|
||||||
parent.requires_monomorphization(tcx)
|
parent.requires_monomorphization(tcx)
|
||||||
|
@ -948,6 +946,16 @@ impl<'a, 'gcx, 'tcx> Generics {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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,
|
pub fn region_param(&'tcx self,
|
||||||
param: &EarlyBoundRegion,
|
param: &EarlyBoundRegion,
|
||||||
tcx: TyCtxt<'a, 'gcx, 'tcx>)
|
tcx: TyCtxt<'a, 'gcx, 'tcx>)
|
||||||
|
|
|
@ -1135,8 +1135,7 @@ fn create_mono_items_for_default_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let counts = tcx.generics_of(method.def_id).own_counts();
|
if tcx.generics_of(method.def_id).own_requires_monomorphization() {
|
||||||
if counts.types + counts.consts != 0 {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
// FIXME: when we make this a hard error, this should have its
|
||||||
// own error code.
|
// own error code.
|
||||||
let counts = tcx.generics_of(def_id).own_counts();
|
let message = if tcx.generics_of(def_id).own_requires_monomorphization() {
|
||||||
let message = if counts.types + counts.consts != 0 {
|
|
||||||
"#[derive] can't be used on a #[repr(packed)] struct with \
|
"#[derive] can't be used on a #[repr(packed)] struct with \
|
||||||
type or const parameters (error E0133)".to_string()
|
type or const parameters (error E0133)".to_string()
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue