mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-19 03:03:21 +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);
|
let generics = self.tcx.generics_of(did);
|
||||||
// Account for the case where `did` corresponds to `Self`, which doesn't have
|
// Account for the case where `did` corresponds to `Self`, which doesn't have
|
||||||
// the expected type argument.
|
// the expected type argument.
|
||||||
if generics.types.len() > 0 {
|
if let Some(type_param) = generics.type_param(param, self.tcx) {
|
||||||
let type_param = generics.type_param(param, self.tcx);
|
|
||||||
let hir = &self.tcx.hir;
|
let hir = &self.tcx.hir;
|
||||||
hir.as_local_node_id(type_param.def_id).map(|id| {
|
hir.as_local_node_id(type_param.def_id).map(|id| {
|
||||||
// Get the `hir::TyParam` to verify wether it already has any bounds.
|
// 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,
|
pub fn type_param(&'tcx self,
|
||||||
param: &ParamTy,
|
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) {
|
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 {
|
} else {
|
||||||
tcx.generics_of(self.parent.expect("parent_count>0 but no parent?"))
|
tcx.generics_of(self.parent.expect("parent_count>0 but no parent?"))
|
||||||
.type_param(param, tcx)
|
.type_param(param, tcx)
|
||||||
|
@ -519,7 +519,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||||||
} else if let Some(&ty::TyS {
|
} else if let Some(&ty::TyS {
|
||||||
sty: ty::TypeVariants::TyParam(ref pt), ..
|
sty: ty::TypeVariants::TyParam(ref pt), ..
|
||||||
}) = k.as_type() {
|
}) = 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 {
|
} else {
|
||||||
// not a type or region param - this should be reported
|
// not a type or region param - this should be reported
|
||||||
// as an error.
|
// as an error.
|
||||||
|
Loading…
Reference in New Issue
Block a user