Skip to content

Commit 6867d91

Browse files
committed
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.
1 parent c6c1a22 commit 6867d91

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/librustc/middle/kind.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ fn check_struct_safe_for_destructor(cx: &mut Context,
8787
span: Span,
8888
struct_did: DefId) {
8989
let struct_tpt = ty::lookup_item_type(cx.tcx, struct_did);
90-
if !struct_tpt.generics.has_type_params(subst::TypeSpace) {
90+
if !struct_tpt.generics.has_type_params(subst::TypeSpace)
91+
&& !struct_tpt.generics.has_region_params(subst::TypeSpace) {
9192
let struct_ty = ty::mk_struct(cx.tcx, struct_did,
9293
subst::Substs::empty());
9394
if !ty::type_is_sendable(cx.tcx, struct_ty) {

src/librustc/middle/ty.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,10 @@ impl Generics {
984984
pub fn has_type_params(&self, space: subst::ParamSpace) -> bool {
985985
!self.types.is_empty_in(space)
986986
}
987+
988+
pub fn has_region_params(&self, space: subst::ParamSpace) -> bool {
989+
!self.regions.is_empty_in(space)
990+
}
987991
}
988992

989993
/// When type checking, we use the `ParameterEnvironment` to track

0 commit comments

Comments
 (0)