mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
Simplify subst / subst_bound_vars a bit
This commit is contained in:
parent
f43e69a64e
commit
19fbd91998
1 changed files with 2 additions and 12 deletions
|
@ -411,11 +411,7 @@ impl Ty {
|
||||||
pub fn subst(self, substs: &Substs) -> Ty {
|
pub fn subst(self, substs: &Substs) -> Ty {
|
||||||
self.fold(&mut |ty| match ty {
|
self.fold(&mut |ty| match ty {
|
||||||
Ty::Param { idx, name } => {
|
Ty::Param { idx, name } => {
|
||||||
if (idx as usize) < substs.len() {
|
substs.get(idx as usize).cloned().unwrap_or(Ty::Param { idx, name })
|
||||||
substs[idx as usize].clone()
|
|
||||||
} else {
|
|
||||||
Ty::Param { idx, name }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ty => ty,
|
ty => ty,
|
||||||
})
|
})
|
||||||
|
@ -424,13 +420,7 @@ impl Ty {
|
||||||
/// Substitutes `Ty::Bound` vars (as opposed to type parameters).
|
/// Substitutes `Ty::Bound` vars (as opposed to type parameters).
|
||||||
pub fn subst_bound_vars(self, substs: &Substs) -> Ty {
|
pub fn subst_bound_vars(self, substs: &Substs) -> Ty {
|
||||||
self.fold(&mut |ty| match ty {
|
self.fold(&mut |ty| match ty {
|
||||||
Ty::Bound(idx) => {
|
Ty::Bound(idx) => substs.get(idx as usize).cloned().unwrap_or(Ty::Bound(idx)),
|
||||||
if (idx as usize) < substs.len() {
|
|
||||||
substs[idx as usize].clone()
|
|
||||||
} else {
|
|
||||||
Ty::Bound(idx)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ty => ty,
|
ty => ty,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue