Closed bgamari closed 10 years ago
I've tried looking at this unfortunately it appears to be a bit deep for the time I have available. I found this patch to be somewhat helpful for debugging. It produces,
test.rs:1:1: 1:1 error: internal compiler error: Type parameter out of range when substituting in region 'a (root type='aRegValue<u32,AReg1<'a>>)
test.rs:1 use std::ty::Unsafe;
Unfortunately I'm not familiar enough with the relevant code to know why this might be the case.
Here is a more minimal test case,
use std::ty::Unsafe;
struct AReg1<'a>(&'a u32);
impl<'a> Drop for AReg1<'a> {
fn drop(&mut self) {}
}
If one comments out the impl Drop
the crash does not occur.
Here is a rough call graph that I've worked out
driver::driver::phase_3_run_analysis_passes
middle::typeck::check_crate
middle::typeck::collect::collect_item_types
collect::convert
ItemStruct generics has region
collect::ty_of_item
in ItemStruct case
collect::ty_generics_for_type
collect::ty_generics
converts ItemStruct to PolyTy
PolyTy generics still has region
collect::convert_struct
converts ast::StructDef to ty::t
mk_item_substs
ty::mk_struct
Somewhere in here Subst on struct is dropped
middle::kind::check_crate
middle::kind::check_item
middle::ty::type_contents
match on `get(ty).sty`
find `ty_struct(did, substs)`
middle::ty::struct_fields
middle::ty::lookup_field_type
middle::subst::Subst::subst_spanned
middle::subst::TypeFolder::fold_region(r: ty::Region)
match on `r`
find ty::ReEarlyBound(_, space, i, region_name)
match on `substs.regions`
find NonerasedRegions(regions)
look for region index `i` in substitutions for space `space`
fail
The problem appears to be here where a new ty::t
is created with an empty Substs
. When the substitution engine then goes to perform a substitution for 'a
, it finds none and crashes.
Perhaps the check,
if !struct_tpt.generics.has_type_params(subst::TypeSpace) { ... }
is supposed to read,
if !struct_tpt.generics.has_type_params(subst::TypeSpace)
&& !struct_tpt.generics.has_region_params(subst::TypeSpace) { ... }
Closing in favor of the pull request.
Compiling this program results in the following error with rustc 00cdd639a93ec1dcad85cebc52214eeba0441c93,