middle::kind: Don't crash when checking safety of Drop
To verify that a type can satisfy Send `check_struct_safe_for_destructor` attempts to construct a new `ty::t` an empty substitution list. Previously the function would verify that the function has no type parameters before attempting this. Unfortunately this check would not catch functions with only regions parameters. In this case, the type would eventually find its way to the substition engine which would attempt to perform a substitution on the region parameters. As the constructed substitution list is empty, this would fail, leading to a compiler crash. We fix this by verifying that types have both no type and region parameters.
This commit is contained in:
parent
c6c1a22c56
commit
6867d91d20
2 changed files with 6 additions and 1 deletions
|
|
@ -87,7 +87,8 @@ fn check_struct_safe_for_destructor(cx: &mut Context,
|
|||
span: Span,
|
||||
struct_did: DefId) {
|
||||
let struct_tpt = ty::lookup_item_type(cx.tcx, struct_did);
|
||||
if !struct_tpt.generics.has_type_params(subst::TypeSpace) {
|
||||
if !struct_tpt.generics.has_type_params(subst::TypeSpace)
|
||||
&& !struct_tpt.generics.has_region_params(subst::TypeSpace) {
|
||||
let struct_ty = ty::mk_struct(cx.tcx, struct_did,
|
||||
subst::Substs::empty());
|
||||
if !ty::type_is_sendable(cx.tcx, struct_ty) {
|
||||
|
|
|
|||
|
|
@ -984,6 +984,10 @@ impl Generics {
|
|||
pub fn has_type_params(&self, space: subst::ParamSpace) -> bool {
|
||||
!self.types.is_empty_in(space)
|
||||
}
|
||||
|
||||
pub fn has_region_params(&self, space: subst::ParamSpace) -> bool {
|
||||
!self.regions.is_empty_in(space)
|
||||
}
|
||||
}
|
||||
|
||||
/// When type checking, we use the `ParameterEnvironment` to track
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue