mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-16 09:48:10 +00:00
Flip generics
This commit is contained in:
parent
a71bb70f0a
commit
7e70fc22a7
1 changed files with 12 additions and 12 deletions
|
@ -52,16 +52,16 @@ impl<DB: HirDatabase> SourceBinder<'_, DB> {
|
||||||
SourceAnalyzer::new_for_resolver(resolver, src)
|
SourceAnalyzer::new_for_resolver(resolver, src)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_def<D, ID>(&mut self, src: InFile<ID::Ast>) -> Option<D>
|
pub fn to_def<D, T>(&mut self, src: InFile<T>) -> Option<D>
|
||||||
where
|
where
|
||||||
D: From<ID>,
|
D: From<T::ID>,
|
||||||
ID: ToId,
|
T: ToId,
|
||||||
{
|
{
|
||||||
let id: ID = self.to_id(src)?;
|
let id: T::ID = self.to_id(src)?;
|
||||||
Some(id.into())
|
Some(id.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_id<D: ToId>(&mut self, src: InFile<D::Ast>) -> Option<D> {
|
fn to_id<T: ToId>(&mut self, src: InFile<T>) -> Option<T::ID> {
|
||||||
let container = self.find_container(src.as_ref().map(|it| it.syntax()))?;
|
let container = self.find_container(src.as_ref().map(|it| it.syntax()))?;
|
||||||
let db = self.db;
|
let db = self.db;
|
||||||
let dyn_map =
|
let dyn_map =
|
||||||
|
@ -73,7 +73,7 @@ impl<DB: HirDatabase> SourceBinder<'_, DB> {
|
||||||
ChildContainer::EnumId(it) => it.child_by_source(db),
|
ChildContainer::EnumId(it) => it.child_by_source(db),
|
||||||
ChildContainer::VariantId(it) => it.child_by_source(db),
|
ChildContainer::VariantId(it) => it.child_by_source(db),
|
||||||
});
|
});
|
||||||
dyn_map[D::KEY].get(&src).copied()
|
dyn_map[T::KEY].get(&src).copied()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_container(&mut self, src: InFile<&SyntaxNode>) -> Option<ChildContainer> {
|
fn find_container(&mut self, src: InFile<&SyntaxNode>) -> Option<ChildContainer> {
|
||||||
|
@ -144,16 +144,16 @@ impl_froms! {
|
||||||
VariantId,
|
VariantId,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ToId: Sized + Copy + 'static {
|
pub trait ToId: Sized + AstNode + 'static {
|
||||||
type Ast: AstNode + 'static;
|
type ID: Sized + Copy + 'static;
|
||||||
const KEY: Key<Self::Ast, Self>;
|
const KEY: Key<Self, Self::ID>;
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! to_id_impls {
|
macro_rules! to_id_impls {
|
||||||
($(($id:ident, $ast:path, $key:path)),* ,) => {$(
|
($(($id:ident, $ast:path, $key:path)),* ,) => {$(
|
||||||
impl ToId for $id {
|
impl ToId for $ast {
|
||||||
type Ast = $ast;
|
type ID = $id;
|
||||||
const KEY: Key<Self::Ast, Self> = $key;
|
const KEY: Key<Self, Self::ID> = $key;
|
||||||
}
|
}
|
||||||
)*}
|
)*}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue