mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
cleanup casts
This commit is contained in:
parent
8718a47088
commit
5c594bcb48
6 changed files with 975 additions and 850 deletions
|
@ -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),
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue