Skip to content

Commit 8f1f5a7

Browse files
committed
Move source-related traits to a separate module
1 parent 2c7f6b5 commit 8f1f5a7

File tree

10 files changed

+77
-60
lines changed

10 files changed

+77
-60
lines changed

crates/ra_hir/src/code_model/src.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
//! FIXME: write short doc here
22
3-
use hir_def::{AstItemDef, HasChildSource, HasSource as _, Lookup, VariantId};
3+
use hir_def::{
4+
src::{HasChildSource, HasSource as _},
5+
AstItemDef, Lookup, VariantId,
6+
};
47
use hir_expand::either::Either;
58
use ra_syntax::ast;
69

crates/ra_hir_def/src/adt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use ra_arena::{map::ArenaMap, Arena};
1111
use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner};
1212

1313
use crate::{
14-
db::DefDatabase, trace::Trace, type_ref::TypeRef, AstItemDef, EnumId, HasChildSource,
14+
db::DefDatabase, src::HasChildSource, trace::Trace, type_ref::TypeRef, AstItemDef, EnumId,
1515
LocalEnumVariantId, LocalStructFieldId, StructId, UnionId, VariantId,
1616
};
1717

crates/ra_hir_def/src/attr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ use ra_syntax::{
1111
use tt::Subtree;
1212

1313
use crate::{
14-
db::DefDatabase, path::Path, AdtId, AstItemDef, AttrDefId, HasChildSource, HasSource, Lookup,
14+
db::DefDatabase, path::Path, src::HasChildSource, src::HasSource, AdtId, AstItemDef, AttrDefId,
15+
Lookup,
1516
};
1617

1718
#[derive(Default, Debug, Clone, PartialEq, Eq)]

crates/ra_hir_def/src/body.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ use crate::{
1717
expr::{Expr, ExprId, Pat, PatId},
1818
nameres::CrateDefMap,
1919
path::Path,
20-
DefWithBodyId, HasModule, HasSource, Lookup, ModuleId,
20+
src::HasSource,
21+
DefWithBodyId, HasModule, Lookup, ModuleId,
2122
};
2223

2324
struct Expander {

crates/ra_hir_def/src/data.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner};
1010

1111
use crate::{
1212
db::DefDatabase,
13+
src::HasSource,
1314
type_ref::{Mutability, TypeRef},
14-
AssocItemId, AstItemDef, ConstId, ConstLoc, ContainerId, FunctionId, FunctionLoc, HasSource,
15-
ImplId, Intern, Lookup, StaticId, TraitId, TypeAliasId, TypeAliasLoc,
15+
AssocItemId, AstItemDef, ConstId, ConstLoc, ContainerId, FunctionId, FunctionLoc, ImplId,
16+
Intern, Lookup, StaticId, TraitId, TypeAliasId, TypeAliasLoc,
1617
};
1718

1819
#[derive(Debug, Clone, PartialEq, Eq)]

crates/ra_hir_def/src/docs.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ use std::sync::Arc;
88
use hir_expand::either::Either;
99
use ra_syntax::ast;
1010

11-
use crate::{db::DefDatabase, AdtId, AstItemDef, AttrDefId, HasChildSource, HasSource, Lookup};
11+
use crate::{
12+
db::DefDatabase,
13+
src::{HasChildSource, HasSource},
14+
AdtId, AstItemDef, AttrDefId, Lookup,
15+
};
1216

1317
/// Holds documentation
1418
#[derive(Debug, Clone, PartialEq, Eq)]

crates/ra_hir_def/src/generics.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ use ra_syntax::ast::{self, NameOwner, TypeBoundsOwner, TypeParamsOwner};
99

1010
use crate::{
1111
db::DefDatabase,
12+
src::HasSource,
1213
type_ref::{TypeBound, TypeRef},
13-
AdtId, AstItemDef, ContainerId, GenericDefId, HasSource, Lookup,
14+
AdtId, AstItemDef, ContainerId, GenericDefId, Lookup,
1415
};
1516

1617
/// Data about a generic parameter (to a function, struct, impl, ...).

crates/ra_hir_def/src/lib.rs

Lines changed: 3 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ pub mod resolver;
2929
mod trace;
3030
pub mod nameres;
3131

32+
pub mod src;
33+
3234
#[cfg(test)]
3335
mod test_db;
3436
#[cfg(test)]
@@ -37,7 +39,7 @@ mod marks;
3739
use std::hash::{Hash, Hasher};
3840

3941
use hir_expand::{ast_id_map::FileAstId, db::AstDatabase, AstId, HirFileId, InFile, MacroDefId};
40-
use ra_arena::{impl_arena_id, map::ArenaMap, RawId};
42+
use ra_arena::{impl_arena_id, RawId};
4143
use ra_db::{impl_intern_key, salsa, CrateId};
4244
use ra_syntax::{ast, AstNode};
4345

@@ -514,53 +516,3 @@ impl HasModule for StaticLoc {
514516
self.container
515517
}
516518
}
517-
518-
pub trait HasSource {
519-
type Value;
520-
fn source(&self, db: &impl db::DefDatabase) -> InFile<Self::Value>;
521-
}
522-
523-
impl HasSource for FunctionLoc {
524-
type Value = ast::FnDef;
525-
526-
fn source(&self, db: &impl db::DefDatabase) -> InFile<ast::FnDef> {
527-
let node = self.ast_id.to_node(db);
528-
InFile::new(self.ast_id.file_id, node)
529-
}
530-
}
531-
532-
impl HasSource for TypeAliasLoc {
533-
type Value = ast::TypeAliasDef;
534-
535-
fn source(&self, db: &impl db::DefDatabase) -> InFile<ast::TypeAliasDef> {
536-
let node = self.ast_id.to_node(db);
537-
InFile::new(self.ast_id.file_id, node)
538-
}
539-
}
540-
541-
impl HasSource for ConstLoc {
542-
type Value = ast::ConstDef;
543-
544-
fn source(&self, db: &impl db::DefDatabase) -> InFile<ast::ConstDef> {
545-
let node = self.ast_id.to_node(db);
546-
InFile::new(self.ast_id.file_id, node)
547-
}
548-
}
549-
550-
impl HasSource for StaticLoc {
551-
type Value = ast::StaticDef;
552-
553-
fn source(&self, db: &impl db::DefDatabase) -> InFile<ast::StaticDef> {
554-
let node = self.ast_id.to_node(db);
555-
InFile::new(self.ast_id.file_id, node)
556-
}
557-
}
558-
559-
pub trait HasChildSource {
560-
type ChildId;
561-
type Value;
562-
fn child_source(
563-
&self,
564-
db: &impl db::DefDatabase,
565-
) -> InFile<ArenaMap<Self::ChildId, Self::Value>>;
566-
}

crates/ra_hir_def/src/src.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//! Utilities for mapping between hir IDs and the surface syntax.
2+
3+
use hir_expand::InFile;
4+
use ra_arena::map::ArenaMap;
5+
use ra_syntax::ast;
6+
7+
use crate::{db::DefDatabase, ConstLoc, FunctionLoc, StaticLoc, TypeAliasLoc};
8+
9+
pub trait HasSource {
10+
type Value;
11+
fn source(&self, db: &impl DefDatabase) -> InFile<Self::Value>;
12+
}
13+
14+
impl HasSource for FunctionLoc {
15+
type Value = ast::FnDef;
16+
17+
fn source(&self, db: &impl DefDatabase) -> InFile<ast::FnDef> {
18+
let node = self.ast_id.to_node(db);
19+
InFile::new(self.ast_id.file_id, node)
20+
}
21+
}
22+
23+
impl HasSource for TypeAliasLoc {
24+
type Value = ast::TypeAliasDef;
25+
26+
fn source(&self, db: &impl DefDatabase) -> InFile<ast::TypeAliasDef> {
27+
let node = self.ast_id.to_node(db);
28+
InFile::new(self.ast_id.file_id, node)
29+
}
30+
}
31+
32+
impl HasSource for ConstLoc {
33+
type Value = ast::ConstDef;
34+
35+
fn source(&self, db: &impl DefDatabase) -> InFile<ast::ConstDef> {
36+
let node = self.ast_id.to_node(db);
37+
InFile::new(self.ast_id.file_id, node)
38+
}
39+
}
40+
41+
impl HasSource for StaticLoc {
42+
type Value = ast::StaticDef;
43+
44+
fn source(&self, db: &impl DefDatabase) -> InFile<ast::StaticDef> {
45+
let node = self.ast_id.to_node(db);
46+
InFile::new(self.ast_id.file_id, node)
47+
}
48+
}
49+
50+
pub trait HasChildSource {
51+
type ChildId;
52+
type Value;
53+
fn child_source(&self, db: &impl DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>>;
54+
}

crates/ra_hir_ty/src/infer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ impl Expectation {
693693
}
694694

695695
mod diagnostics {
696-
use hir_def::{expr::ExprId, FunctionId, HasSource, Lookup};
696+
use hir_def::{expr::ExprId, src::HasSource, FunctionId, Lookup};
697697
use hir_expand::diagnostics::DiagnosticSink;
698698

699699
use crate::{db::HirDatabase, diagnostics::NoSuchField};

0 commit comments

Comments
 (0)