Skip to content

Commit c834677

Browse files
committed
Finalize Trait grammar
1 parent b2cdb0b commit c834677

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+92
-92
lines changed

crates/ra_assists/src/handlers/change_visibility.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use ra_syntax::{
22
ast::{self, NameOwner, VisibilityOwner},
33
AstNode,
4-
SyntaxKind::{CONST, ENUM, FN, MODULE, STATIC, STRUCT, TRAIT_DEF, VISIBILITY},
4+
SyntaxKind::{CONST, ENUM, FN, MODULE, STATIC, STRUCT, TRAIT, VISIBILITY},
55
T,
66
};
77
use test_utils::mark;
@@ -36,7 +36,7 @@ fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
3636

3737
let (offset, target) = if let Some(keyword) = item_keyword {
3838
let parent = keyword.parent();
39-
let def_kws = vec![CONST, STATIC, FN, MODULE, STRUCT, ENUM, TRAIT_DEF];
39+
let def_kws = vec![CONST, STATIC, FN, MODULE, STRUCT, ENUM, TRAIT];
4040
// Parent is not a definition, can't add visibility
4141
if !def_kws.iter().any(|&def_kw| def_kw == parent.kind()) {
4242
return None;

crates/ra_assists/src/handlers/move_bounds.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub(crate) fn move_bounds_to_where_clause(acc: &mut Assists, ctx: &AssistContext
3838
let anchor = match_ast! {
3939
match parent {
4040
ast::Fn(it) => it.body()?.syntax().clone().into(),
41-
ast::TraitDef(it) => it.assoc_item_list()?.syntax().clone().into(),
41+
ast::Trait(it) => it.assoc_item_list()?.syntax().clone().into(),
4242
ast::ImplDef(it) => it.assoc_item_list()?.syntax().clone().into(),
4343
ast::Enum(it) => it.variant_list()?.syntax().clone().into(),
4444
ast::Struct(it) => {

crates/ra_hir/src/has_source.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ impl HasSource for Static {
9999
}
100100
}
101101
impl HasSource for Trait {
102-
type Ast = ast::TraitDef;
103-
fn source(self, db: &dyn HirDatabase) -> InFile<ast::TraitDef> {
102+
type Ast = ast::Trait;
103+
fn source(self, db: &dyn HirDatabase) -> InFile<ast::Trait> {
104104
self.id.lookup(db.upcast()).source(db.upcast())
105105
}
106106
}
@@ -127,7 +127,7 @@ impl HasSource for ImplDef {
127127
}
128128

129129
impl HasSource for TypeParam {
130-
type Ast = Either<ast::TraitDef, ast::TypeParam>;
130+
type Ast = Either<ast::Trait, ast::TypeParam>;
131131
fn source(self, db: &dyn HirDatabase) -> InFile<Self::Ast> {
132132
let child_source = self.id.parent.child_source(db.upcast());
133133
child_source.map(|it| it[self.id.local_id].clone())

crates/ra_hir/src/semantics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ to_def_impls![
583583
(crate::Struct, ast::Struct, struct_to_def),
584584
(crate::Enum, ast::Enum, enum_to_def),
585585
(crate::Union, ast::Union, union_to_def),
586-
(crate::Trait, ast::TraitDef, trait_to_def),
586+
(crate::Trait, ast::Trait, trait_to_def),
587587
(crate::ImplDef, ast::ImplDef, impl_to_def),
588588
(crate::TypeAlias, ast::TypeAlias, type_alias_to_def),
589589
(crate::Const, ast::Const, const_to_def),

crates/ra_hir/src/semantics/source_to_def.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl SourceToDefCtx<'_, '_> {
6565
Some(ModuleId { krate: parent_module.krate, local_id: child_id })
6666
}
6767

68-
pub(super) fn trait_to_def(&mut self, src: InFile<ast::TraitDef>) -> Option<TraitId> {
68+
pub(super) fn trait_to_def(&mut self, src: InFile<ast::Trait>) -> Option<TraitId> {
6969
self.to_def(src, keys::TRAIT)
7070
}
7171
pub(super) fn impl_to_def(&mut self, src: InFile<ast::ImplDef>) -> Option<ImplId> {
@@ -154,7 +154,7 @@ impl SourceToDefCtx<'_, '_> {
154154
let def = self.module_to_def(container.with_value(it))?;
155155
def.into()
156156
},
157-
ast::TraitDef(it) => {
157+
ast::Trait(it) => {
158158
let def = self.trait_to_def(container.with_value(it))?;
159159
def.into()
160160
},
@@ -207,7 +207,7 @@ impl SourceToDefCtx<'_, '_> {
207207
ast::Fn(it) => self.fn_to_def(container.with_value(it))?.into(),
208208
ast::Struct(it) => self.struct_to_def(container.with_value(it))?.into(),
209209
ast::Enum(it) => self.enum_to_def(container.with_value(it))?.into(),
210-
ast::TraitDef(it) => self.trait_to_def(container.with_value(it))?.into(),
210+
ast::Trait(it) => self.trait_to_def(container.with_value(it))?.into(),
211211
ast::TypeAlias(it) => self.type_alias_to_def(container.with_value(it))?.into(),
212212
ast::ImplDef(it) => self.impl_to_def(container.with_value(it))?.into(),
213213
_ => continue,

crates/ra_hir_def/src/body/lower.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ impl ExprCollector<'_> {
664664
let id = self.find_inner_item(&def)?;
665665
(UnionLoc { container, id }.intern(self.db).into(), def.name())
666666
}
667-
ast::Item::TraitDef(def) => {
667+
ast::Item::Trait(def) => {
668668
let id = self.find_inner_item(&def)?;
669669
(TraitLoc { container, id }.intern(self.db).into(), def.name())
670670
}

crates/ra_hir_def/src/generics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub enum WherePredicateTarget {
6666
TypeParam(LocalTypeParamId),
6767
}
6868

69-
type SourceMap = ArenaMap<LocalTypeParamId, Either<ast::TraitDef, ast::TypeParam>>;
69+
type SourceMap = ArenaMap<LocalTypeParamId, Either<ast::Trait, ast::TypeParam>>;
7070

7171
impl GenericParams {
7272
pub(crate) fn generic_params_query(
@@ -317,7 +317,7 @@ impl GenericParams {
317317

318318
impl HasChildSource for GenericDefId {
319319
type ChildId = LocalTypeParamId;
320-
type Value = Either<ast::TraitDef, ast::TypeParam>;
320+
type Value = Either<ast::Trait, ast::TypeParam>;
321321
fn child_source(&self, db: &dyn DefDatabase) -> InFile<SourceMap> {
322322
let (_, sm) = GenericParams::new(db, *self);
323323
sm

crates/ra_hir_def/src/item_tree.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ mod_items! {
419419
Enum in enums -> ast::Enum,
420420
Const in consts -> ast::Const,
421421
Static in statics -> ast::Static,
422-
Trait in traits -> ast::TraitDef,
422+
Trait in traits -> ast::Trait,
423423
Impl in impls -> ast::ImplDef,
424424
TypeAlias in type_aliases -> ast::TypeAlias,
425425
Mod in mods -> ast::Module,
@@ -571,7 +571,7 @@ pub struct Trait {
571571
pub generic_params: GenericParamsId,
572572
pub auto: bool,
573573
pub items: Box<[AssocItem]>,
574-
pub ast_id: FileAstId<ast::TraitDef>,
574+
pub ast_id: FileAstId<ast::Trait>,
575575
}
576576

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

crates/ra_hir_def/src/item_tree/lower.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl Ctx {
9595

9696
// These are handled in their respective `lower_X` method (since we can't just blindly
9797
// walk them).
98-
ast::Item::TraitDef(_) | ast::Item::ImplDef(_) | ast::Item::ExternBlock(_) => {}
98+
ast::Item::Trait(_) | ast::Item::ImplDef(_) | ast::Item::ExternBlock(_) => {}
9999

100100
// These don't have inner items.
101101
ast::Item::Module(_) | ast::Item::ExternCrate(_) | ast::Item::Use(_) => {}
@@ -111,7 +111,7 @@ impl Ctx {
111111
ast::Item::Static(ast) => self.lower_static(ast).map(Into::into),
112112
ast::Item::Const(ast) => Some(self.lower_const(ast).into()),
113113
ast::Item::Module(ast) => self.lower_module(ast).map(Into::into),
114-
ast::Item::TraitDef(ast) => self.lower_trait(ast).map(Into::into),
114+
ast::Item::Trait(ast) => self.lower_trait(ast).map(Into::into),
115115
ast::Item::ImplDef(ast) => self.lower_impl(ast).map(Into::into),
116116
ast::Item::Use(ast) => Some(ModItems(
117117
self.lower_use(ast).into_iter().map(Into::into).collect::<SmallVec<_>>(),
@@ -413,7 +413,7 @@ impl Ctx {
413413
Some(id(self.data().mods.alloc(res)))
414414
}
415415

416-
fn lower_trait(&mut self, trait_def: &ast::TraitDef) -> Option<FileItemTreeId<Trait>> {
416+
fn lower_trait(&mut self, trait_def: &ast::Trait) -> Option<FileItemTreeId<Trait>> {
417417
let name = trait_def.name()?.as_name();
418418
let visibility = self.lower_visibility(trait_def);
419419
let generic_params =
@@ -698,7 +698,7 @@ enum GenericsOwner<'a> {
698698
Enum,
699699
Union,
700700
/// The `TraitDef` is needed to fill the source map for the implicit `Self` parameter.
701-
Trait(&'a ast::TraitDef),
701+
Trait(&'a ast::Trait),
702702
TypeAlias,
703703
Impl,
704704
}

crates/ra_hir_def/src/item_tree/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ fn smoke() {
234234
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("ext_crate"))] }, input: None }]) }]
235235
ExternCrate { path: ModPath { kind: Plain, segments: [Name(Text("krate"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_macro_use: false, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::ExternCrate>(1) }
236236
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("on_trait"))] }, input: None }]) }]
237-
Trait { name: Name(Text("Tr")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(0), auto: false, items: [TypeAlias(Idx::<TypeAlias>(0)), Const(Idx::<Const>(0)), Function(Idx::<Function>(0)), Function(Idx::<Function>(1))], ast_id: FileAstId::<ra_syntax::ast::generated::nodes::TraitDef>(2) }
237+
Trait { name: Name(Text("Tr")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(0), auto: false, items: [TypeAlias(Idx::<TypeAlias>(0)), Const(Idx::<Const>(0)), Function(Idx::<Function>(0)), Function(Idx::<Function>(1))], ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Trait>(2) }
238238
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_ty"))] }, input: None }]) }]
239239
> TypeAlias { name: Name(Text("AssocTy")), visibility: RawVisibilityId("pub(self)"), bounds: [Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Tr"))] }, generic_args: [Some(GenericArgs { args: [Type(Tuple([]))], has_self_type: false, bindings: [] })] })], generic_params: GenericParamsId(4294967295), type_ref: None, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::TypeAlias>(8) }
240240
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_const"))] }, input: None }]) }]
@@ -327,7 +327,7 @@ fn trait_attrs() {
327327
328328
top-level items:
329329
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("trait_attr"))] }, input: None }]) }]
330-
Trait { name: Name(Text("Tr")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(0), auto: false, items: [Function(Idx::<Function>(0)), Function(Idx::<Function>(1))], ast_id: FileAstId::<ra_syntax::ast::generated::nodes::TraitDef>(0) }
330+
Trait { name: Name(Text("Tr")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(0), auto: false, items: [Function(Idx::<Function>(0)), Function(Idx::<Function>(1))], ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Trait>(0) }
331331
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_a"))] }, input: None }]) }]
332332
> Function { name: Name(Text("a")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(1) }
333333
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_b"))] }, input: None }]) }]

0 commit comments

Comments
 (0)