aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-10-28 17:30:22 +0000
committerGitHub <[email protected]>2019-10-28 17:30:22 +0000
commit52c34c614b561096b239bddf59aa741270b2177e (patch)
tree9c75065f4fbb2e93d02dbefe8516f6ad1b902655 /crates
parent1ca41f2118fca17ee5ad0f586218489fa5d883af (diff)
parent54d3e47318930c7a443b1498ff88d365920abe39 (diff)
Merge #2110
2110: weaken requirements of AstDef r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/ids.rs46
1 files changed, 23 insertions, 23 deletions
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs
index 499dcafea..518ea32e9 100644
--- a/crates/ra_hir/src/ids.rs
+++ b/crates/ra_hir/src/ids.rs
@@ -11,7 +11,7 @@ use ra_prof::profile;
11use ra_syntax::{ast, AstNode, Parse, SyntaxNode}; 11use ra_syntax::{ast, AstNode, Parse, SyntaxNode};
12 12
13use crate::{ 13use crate::{
14 db::{AstDatabase, DefDatabase, InternDatabase}, 14 db::{AstDatabase, InternDatabase},
15 AstId, Crate, FileAstId, Module, Source, 15 AstId, Crate, FileAstId, Module, Source,
16}; 16};
17 17
@@ -238,13 +238,13 @@ pub(crate) struct LocationCtx<DB> {
238 file_id: HirFileId, 238 file_id: HirFileId,
239} 239}
240 240
241impl<'a, DB: DefDatabase> LocationCtx<&'a DB> { 241impl<'a, DB> LocationCtx<&'a DB> {
242 pub(crate) fn new(db: &'a DB, module: Module, file_id: HirFileId) -> LocationCtx<&'a DB> { 242 pub(crate) fn new(db: &'a DB, module: Module, file_id: HirFileId) -> LocationCtx<&'a DB> {
243 LocationCtx { db, module, file_id } 243 LocationCtx { db, module, file_id }
244 } 244 }
245} 245}
246 246
247impl<'a, DB: DefDatabase + AstDatabase> LocationCtx<&'a DB> { 247impl<'a, DB: AstDatabase> LocationCtx<&'a DB> {
248 pub(crate) fn to_def<N, DEF>(self, ast: &N) -> DEF 248 pub(crate) fn to_def<N, DEF>(self, ast: &N) -> DEF
249 where 249 where
250 N: AstNode, 250 N: AstNode,
@@ -255,24 +255,24 @@ impl<'a, DB: DefDatabase + AstDatabase> LocationCtx<&'a DB> {
255} 255}
256 256
257pub(crate) trait AstItemDef<N: AstNode>: salsa::InternKey + Clone { 257pub(crate) trait AstItemDef<N: AstNode>: salsa::InternKey + Clone {
258 fn intern(db: &impl DefDatabase, loc: ItemLoc<N>) -> Self; 258 fn intern(db: &impl InternDatabase, loc: ItemLoc<N>) -> Self;
259 fn lookup_intern(self, db: &impl DefDatabase) -> ItemLoc<N>; 259 fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<N>;
260 260
261 fn from_ast(ctx: LocationCtx<&(impl AstDatabase + DefDatabase)>, ast: &N) -> Self { 261 fn from_ast(ctx: LocationCtx<&impl AstDatabase>, ast: &N) -> Self {
262 let items = ctx.db.ast_id_map(ctx.file_id); 262 let items = ctx.db.ast_id_map(ctx.file_id);
263 let item_id = items.ast_id(ast); 263 let item_id = items.ast_id(ast);
264 Self::from_ast_id(ctx, item_id) 264 Self::from_ast_id(ctx, item_id)
265 } 265 }
266 fn from_ast_id(ctx: LocationCtx<&impl DefDatabase>, ast_id: FileAstId<N>) -> Self { 266 fn from_ast_id(ctx: LocationCtx<&impl InternDatabase>, ast_id: FileAstId<N>) -> Self {
267 let loc = ItemLoc { module: ctx.module, ast_id: ast_id.with_file_id(ctx.file_id) }; 267 let loc = ItemLoc { module: ctx.module, ast_id: ast_id.with_file_id(ctx.file_id) };
268 Self::intern(ctx.db, loc) 268 Self::intern(ctx.db, loc)
269 } 269 }
270 fn source(self, db: &(impl AstDatabase + DefDatabase)) -> Source<N> { 270 fn source(self, db: &impl AstDatabase) -> Source<N> {
271 let loc = self.lookup_intern(db); 271 let loc = self.lookup_intern(db);
272 let ast = loc.ast_id.to_node(db); 272 let ast = loc.ast_id.to_node(db);
273 Source { file_id: loc.ast_id.file_id(), ast } 273 Source { file_id: loc.ast_id.file_id(), ast }
274 } 274 }
275 fn module(self, db: &impl DefDatabase) -> Module { 275 fn module(self, db: &impl InternDatabase) -> Module {
276 let loc = self.lookup_intern(db); 276 let loc = self.lookup_intern(db);
277 loc.module 277 loc.module
278 } 278 }
@@ -283,10 +283,10 @@ pub struct FunctionId(salsa::InternId);
283impl_intern_key!(FunctionId); 283impl_intern_key!(FunctionId);
284 284
285impl AstItemDef<ast::FnDef> for FunctionId { 285impl AstItemDef<ast::FnDef> for FunctionId {
286 fn intern(db: &impl DefDatabase, loc: ItemLoc<ast::FnDef>) -> Self { 286 fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::FnDef>) -> Self {
287 db.intern_function(loc) 287 db.intern_function(loc)
288 } 288 }
289 fn lookup_intern(self, db: &impl DefDatabase) -> ItemLoc<ast::FnDef> { 289 fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::FnDef> {
290 db.lookup_intern_function(self) 290 db.lookup_intern_function(self)
291 } 291 }
292} 292}
@@ -295,10 +295,10 @@ impl AstItemDef<ast::FnDef> for FunctionId {
295pub struct StructId(salsa::InternId); 295pub struct StructId(salsa::InternId);
296impl_intern_key!(StructId); 296impl_intern_key!(StructId);
297impl AstItemDef<ast::StructDef> for StructId { 297impl AstItemDef<ast::StructDef> for StructId {
298 fn intern(db: &impl DefDatabase, loc: ItemLoc<ast::StructDef>) -> Self { 298 fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::StructDef>) -> Self {
299 db.intern_struct(loc) 299 db.intern_struct(loc)
300 } 300 }
301 fn lookup_intern(self, db: &impl DefDatabase) -> ItemLoc<ast::StructDef> { 301 fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::StructDef> {
302 db.lookup_intern_struct(self) 302 db.lookup_intern_struct(self)
303 } 303 }
304} 304}
@@ -307,10 +307,10 @@ impl AstItemDef<ast::StructDef> for StructId {
307pub struct EnumId(salsa::InternId); 307pub struct EnumId(salsa::InternId);
308impl_intern_key!(EnumId); 308impl_intern_key!(EnumId);
309impl AstItemDef<ast::EnumDef> for EnumId { 309impl AstItemDef<ast::EnumDef> for EnumId {
310 fn intern(db: &impl DefDatabase, loc: ItemLoc<ast::EnumDef>) -> Self { 310 fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::EnumDef>) -> Self {
311 db.intern_enum(loc) 311 db.intern_enum(loc)
312 } 312 }
313 fn lookup_intern(self, db: &impl DefDatabase) -> ItemLoc<ast::EnumDef> { 313 fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::EnumDef> {
314 db.lookup_intern_enum(self) 314 db.lookup_intern_enum(self)
315 } 315 }
316} 316}
@@ -319,10 +319,10 @@ impl AstItemDef<ast::EnumDef> for EnumId {
319pub struct ConstId(salsa::InternId); 319pub struct ConstId(salsa::InternId);
320impl_intern_key!(ConstId); 320impl_intern_key!(ConstId);
321impl AstItemDef<ast::ConstDef> for ConstId { 321impl AstItemDef<ast::ConstDef> for ConstId {
322 fn intern(db: &impl DefDatabase, loc: ItemLoc<ast::ConstDef>) -> Self { 322 fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::ConstDef>) -> Self {
323 db.intern_const(loc) 323 db.intern_const(loc)
324 } 324 }
325 fn lookup_intern(self, db: &impl DefDatabase) -> ItemLoc<ast::ConstDef> { 325 fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::ConstDef> {
326 db.lookup_intern_const(self) 326 db.lookup_intern_const(self)
327 } 327 }
328} 328}
@@ -331,10 +331,10 @@ impl AstItemDef<ast::ConstDef> for ConstId {
331pub struct StaticId(salsa::InternId); 331pub struct StaticId(salsa::InternId);
332impl_intern_key!(StaticId); 332impl_intern_key!(StaticId);
333impl AstItemDef<ast::StaticDef> for StaticId { 333impl AstItemDef<ast::StaticDef> for StaticId {
334 fn intern(db: &impl DefDatabase, loc: ItemLoc<ast::StaticDef>) -> Self { 334 fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::StaticDef>) -> Self {
335 db.intern_static(loc) 335 db.intern_static(loc)
336 } 336 }
337 fn lookup_intern(self, db: &impl DefDatabase) -> ItemLoc<ast::StaticDef> { 337 fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::StaticDef> {
338 db.lookup_intern_static(self) 338 db.lookup_intern_static(self)
339 } 339 }
340} 340}
@@ -343,10 +343,10 @@ impl AstItemDef<ast::StaticDef> for StaticId {
343pub struct TraitId(salsa::InternId); 343pub struct TraitId(salsa::InternId);
344impl_intern_key!(TraitId); 344impl_intern_key!(TraitId);
345impl AstItemDef<ast::TraitDef> for TraitId { 345impl AstItemDef<ast::TraitDef> for TraitId {
346 fn intern(db: &impl DefDatabase, loc: ItemLoc<ast::TraitDef>) -> Self { 346 fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::TraitDef>) -> Self {
347 db.intern_trait(loc) 347 db.intern_trait(loc)
348 } 348 }
349 fn lookup_intern(self, db: &impl DefDatabase) -> ItemLoc<ast::TraitDef> { 349 fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::TraitDef> {
350 db.lookup_intern_trait(self) 350 db.lookup_intern_trait(self)
351 } 351 }
352} 352}
@@ -355,10 +355,10 @@ impl AstItemDef<ast::TraitDef> for TraitId {
355pub struct TypeAliasId(salsa::InternId); 355pub struct TypeAliasId(salsa::InternId);
356impl_intern_key!(TypeAliasId); 356impl_intern_key!(TypeAliasId);
357impl AstItemDef<ast::TypeAliasDef> for TypeAliasId { 357impl AstItemDef<ast::TypeAliasDef> for TypeAliasId {
358 fn intern(db: &impl DefDatabase, loc: ItemLoc<ast::TypeAliasDef>) -> Self { 358 fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::TypeAliasDef>) -> Self {
359 db.intern_type_alias(loc) 359 db.intern_type_alias(loc)
360 } 360 }
361 fn lookup_intern(self, db: &impl DefDatabase) -> ItemLoc<ast::TypeAliasDef> { 361 fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::TypeAliasDef> {
362 db.lookup_intern_type_alias(self) 362 db.lookup_intern_type_alias(self)
363 } 363 }
364} 364}