cleanup casts

This commit is contained in:
Aleksey Kladov 2019-07-19 18:22:00 +03:00
parent 8718a47088
commit 5c594bcb48
6 changed files with 975 additions and 850 deletions

View file

@ -25,6 +25,12 @@ impl<A, B> Either<A, B> {
Either::B(b) => Either::B(f2(b)),
}
}
pub fn map_a<U, F>(self, f: F) -> Either<U, B>
where
F: FnOnce(A) -> U,
{
self.map(f, |it| it)
}
pub fn a(self) -> Option<A> {
match self {
Either::A(it) => Some(it),

View file

@ -309,15 +309,11 @@ impl SourceAnalyzer {
crate::Resolution::LocalBinding(it) => {
// We get a `PatId` from resolver, but it actually can only
// point at `BindPat`, and not at the arbitrary pattern.
let pat_ptr = self.body_source_map.as_ref()?.pat_syntax(it)?;
let pat_ptr = match pat_ptr {
Either::A(pat) => {
let pat: AstPtr<ast::BindPat> =
pat.cast_checking_kind(|kind| kind == BIND_PAT).unwrap();
Either::A(pat)
}
Either::B(self_param) => Either::B(self_param),
};
let pat_ptr = self
.body_source_map
.as_ref()?
.pat_syntax(it)?
.map_a(|ptr| ptr.cast::<ast::BindPat>().unwrap());
PathResolution::LocalBinding(pat_ptr)
}
crate::Resolution::GenericParam(it) => PathResolution::GenericParam(it),