Fix return type of self_type_parameter

This commit is contained in:
Florian Diebold 2021-04-07 20:41:52 +02:00
parent 6777a4975d
commit 9b4ecd3723
4 changed files with 10 additions and 10 deletions

View file

@ -199,12 +199,12 @@ impl TyExt for Ty {
.map(|pred| pred.clone().substitute(&Interner, &substs)) .map(|pred| pred.clone().substitute(&Interner, &substs))
.filter(|wc| match &wc.skip_binders() { .filter(|wc| match &wc.skip_binders() {
WhereClause::Implemented(tr) => { WhereClause::Implemented(tr) => {
tr.self_type_parameter(&Interner) == self &tr.self_type_parameter(&Interner) == self
} }
WhereClause::AliasEq(AliasEq { WhereClause::AliasEq(AliasEq {
alias: AliasTy::Projection(proj), alias: AliasTy::Projection(proj),
ty: _, ty: _,
}) => proj.self_type_parameter(&Interner) == self, }) => &proj.self_type_parameter(&Interner) == self,
_ => false, _ => false,
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();

View file

@ -616,12 +616,12 @@ impl HirDisplay for Ty {
.map(|pred| pred.clone().substitute(&Interner, &substs)) .map(|pred| pred.clone().substitute(&Interner, &substs))
.filter(|wc| match &wc.skip_binders() { .filter(|wc| match &wc.skip_binders() {
WhereClause::Implemented(tr) => { WhereClause::Implemented(tr) => {
tr.self_type_parameter(&Interner) == self &tr.self_type_parameter(&Interner) == self
} }
WhereClause::AliasEq(AliasEq { WhereClause::AliasEq(AliasEq {
alias: AliasTy::Projection(proj), alias: AliasTy::Projection(proj),
ty: _, ty: _,
}) => proj.self_type_parameter(&Interner) == self, }) => &proj.self_type_parameter(&Interner) == self,
_ => false, _ => false,
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();

View file

@ -509,7 +509,7 @@ pub(super) fn generic_predicate_to_inline_bound(
let (pred, binders) = pred.as_ref().into_value_and_skipped_binders(); let (pred, binders) = pred.as_ref().into_value_and_skipped_binders();
match pred { match pred {
WhereClause::Implemented(trait_ref) => { WhereClause::Implemented(trait_ref) => {
if trait_ref.self_type_parameter(&Interner) != &self_ty_shifted_in { if trait_ref.self_type_parameter(&Interner) != self_ty_shifted_in {
// we can only convert predicates back to type bounds if they // we can only convert predicates back to type bounds if they
// have the expected self type // have the expected self type
return None; return None;
@ -522,7 +522,7 @@ pub(super) fn generic_predicate_to_inline_bound(
Some(chalk_ir::Binders::new(binders, rust_ir::InlineBound::TraitBound(trait_bound))) Some(chalk_ir::Binders::new(binders, rust_ir::InlineBound::TraitBound(trait_bound)))
} }
WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => { WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => {
if projection_ty.self_type_parameter(&Interner) != &self_ty_shifted_in { if projection_ty.self_type_parameter(&Interner) != self_ty_shifted_in {
return None; return None;
} }
let trait_ = projection_ty.trait_(db); let trait_ = projection_ty.trait_(db);

View file

@ -30,8 +30,8 @@ pub struct ProjectionTy {
} }
impl ProjectionTy { impl ProjectionTy {
pub fn self_type_parameter(&self, interner: &Interner) -> &Ty { pub fn self_type_parameter(&self, interner: &Interner) -> Ty {
&self.substitution.interned()[0].assert_ty_ref(interner) self.substitution.interned()[0].assert_ty_ref(interner).clone()
} }
} }
@ -413,8 +413,8 @@ pub struct TraitRef {
} }
impl TraitRef { impl TraitRef {
pub fn self_type_parameter(&self, interner: &Interner) -> &Ty { pub fn self_type_parameter(&self, interner: &Interner) -> Ty {
&self.substitution.at(interner, 0).assert_ty_ref(interner) self.substitution.at(interner, 0).assert_ty_ref(interner).clone()
} }
} }