mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-18 18:53:04 +00:00
fix handling of Self
This commit is contained in:
parent
622a78cd54
commit
ad9986605f
@ -794,8 +794,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
let generics = self.tcx.generics_of(did);
|
||||
// Account for the case where `did` corresponds to `Self`, which doesn't have
|
||||
// the expected type argument.
|
||||
if generics.types.len() > 0 {
|
||||
let type_param = generics.type_param(param, self.tcx);
|
||||
if let Some(type_param) = generics.type_param(param, self.tcx) {
|
||||
let hir = &self.tcx.hir;
|
||||
hir.as_local_node_id(type_param.def_id).map(|id| {
|
||||
// Get the `hir::TyParam` to verify wether it already has any bounds.
|
||||
|
@ -755,11 +755,19 @@ impl<'a, 'gcx, 'tcx> Generics {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the `TypeParameterDef` associated with this `ParamTy`, or `None`
|
||||
/// if `param` is `self`.
|
||||
pub fn type_param(&'tcx self,
|
||||
param: &ParamTy,
|
||||
tcx: TyCtxt<'a, 'gcx, 'tcx>) -> &TypeParameterDef {
|
||||
tcx: TyCtxt<'a, 'gcx, 'tcx>)
|
||||
-> Option<&TypeParameterDef> {
|
||||
if let Some(idx) = param.idx.checked_sub(self.parent_count() as u32) {
|
||||
&self.types[idx as usize - self.has_self as usize - self.regions.len()]
|
||||
let type_param_start = (self.has_self as usize) + self.regions.len();
|
||||
if let Some(idx) = (idx as usize).checked_sub(type_param_start) {
|
||||
Some(&self.types[idx])
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
tcx.generics_of(self.parent.expect("parent_count>0 but no parent?"))
|
||||
.type_param(param, tcx)
|
||||
|
@ -519,7 +519,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
} else if let Some(&ty::TyS {
|
||||
sty: ty::TypeVariants::TyParam(ref pt), ..
|
||||
}) = k.as_type() {
|
||||
!impl_generics.type_param(pt, self).pure_wrt_drop
|
||||
!impl_generics.type_param(pt, self)
|
||||
.expect("drop impl param doesn't have a ParameterDef?")
|
||||
.pure_wrt_drop
|
||||
} else {
|
||||
// not a type or region param - this should be reported
|
||||
// as an error.
|
||||
|
Loading…
Reference in New Issue
Block a user