Unfork struct and union ids

This commit is contained in:
Aleksey Kladov 2019-11-09 15:34:00 +03:00
parent defc7ad772
commit 6294fd5ec9
10 changed files with 51 additions and 53 deletions

View file

@ -1,5 +1,6 @@
//! FIXME: write short doc here
use hir_def::{StructId, StructOrUnionId, UnionId};
use hir_expand::name::AsName;
use ra_syntax::ast::{self, AstNode, NameOwner};
@ -15,18 +16,19 @@ pub trait FromSource: Sized {
fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self>;
}
// FIXIME: these two impls are wrong, `ast::StructDef` might produce either a struct or a union
impl FromSource for Struct {
type Ast = ast::StructDef;
fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> {
let id = from_source(db, src)?;
Some(Struct { id })
let id: StructOrUnionId = from_source(db, src)?;
Some(Struct { id: StructId(id) })
}
}
impl FromSource for Union {
type Ast = ast::StructDef;
fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> {
let id = from_source(db, src)?;
Some(Union { id })
let id: StructOrUnionId = from_source(db, src)?;
Some(Union { id: UnionId(id) })
}
}
impl FromSource for Enum {