mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 20:43:21 +00:00
Finalize Trait grammar
This commit is contained in:
parent
b2cdb0b226
commit
c83467796b
42 changed files with 92 additions and 92 deletions
|
@ -1,7 +1,7 @@
|
|||
use ra_syntax::{
|
||||
ast::{self, NameOwner, VisibilityOwner},
|
||||
AstNode,
|
||||
SyntaxKind::{CONST, ENUM, FN, MODULE, STATIC, STRUCT, TRAIT_DEF, VISIBILITY},
|
||||
SyntaxKind::{CONST, ENUM, FN, MODULE, STATIC, STRUCT, TRAIT, VISIBILITY},
|
||||
T,
|
||||
};
|
||||
use test_utils::mark;
|
||||
|
@ -36,7 +36,7 @@ fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
|
|||
|
||||
let (offset, target) = if let Some(keyword) = item_keyword {
|
||||
let parent = keyword.parent();
|
||||
let def_kws = vec![CONST, STATIC, FN, MODULE, STRUCT, ENUM, TRAIT_DEF];
|
||||
let def_kws = vec![CONST, STATIC, FN, MODULE, STRUCT, ENUM, TRAIT];
|
||||
// Parent is not a definition, can't add visibility
|
||||
if !def_kws.iter().any(|&def_kw| def_kw == parent.kind()) {
|
||||
return None;
|
||||
|
|
|
@ -38,7 +38,7 @@ pub(crate) fn move_bounds_to_where_clause(acc: &mut Assists, ctx: &AssistContext
|
|||
let anchor = match_ast! {
|
||||
match parent {
|
||||
ast::Fn(it) => it.body()?.syntax().clone().into(),
|
||||
ast::TraitDef(it) => it.assoc_item_list()?.syntax().clone().into(),
|
||||
ast::Trait(it) => it.assoc_item_list()?.syntax().clone().into(),
|
||||
ast::ImplDef(it) => it.assoc_item_list()?.syntax().clone().into(),
|
||||
ast::Enum(it) => it.variant_list()?.syntax().clone().into(),
|
||||
ast::Struct(it) => {
|
||||
|
|
|
@ -99,8 +99,8 @@ impl HasSource for Static {
|
|||
}
|
||||
}
|
||||
impl HasSource for Trait {
|
||||
type Ast = ast::TraitDef;
|
||||
fn source(self, db: &dyn HirDatabase) -> InFile<ast::TraitDef> {
|
||||
type Ast = ast::Trait;
|
||||
fn source(self, db: &dyn HirDatabase) -> InFile<ast::Trait> {
|
||||
self.id.lookup(db.upcast()).source(db.upcast())
|
||||
}
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ impl HasSource for ImplDef {
|
|||
}
|
||||
|
||||
impl HasSource for TypeParam {
|
||||
type Ast = Either<ast::TraitDef, ast::TypeParam>;
|
||||
type Ast = Either<ast::Trait, ast::TypeParam>;
|
||||
fn source(self, db: &dyn HirDatabase) -> InFile<Self::Ast> {
|
||||
let child_source = self.id.parent.child_source(db.upcast());
|
||||
child_source.map(|it| it[self.id.local_id].clone())
|
||||
|
|
|
@ -583,7 +583,7 @@ to_def_impls![
|
|||
(crate::Struct, ast::Struct, struct_to_def),
|
||||
(crate::Enum, ast::Enum, enum_to_def),
|
||||
(crate::Union, ast::Union, union_to_def),
|
||||
(crate::Trait, ast::TraitDef, trait_to_def),
|
||||
(crate::Trait, ast::Trait, trait_to_def),
|
||||
(crate::ImplDef, ast::ImplDef, impl_to_def),
|
||||
(crate::TypeAlias, ast::TypeAlias, type_alias_to_def),
|
||||
(crate::Const, ast::Const, const_to_def),
|
||||
|
|
|
@ -65,7 +65,7 @@ impl SourceToDefCtx<'_, '_> {
|
|||
Some(ModuleId { krate: parent_module.krate, local_id: child_id })
|
||||
}
|
||||
|
||||
pub(super) fn trait_to_def(&mut self, src: InFile<ast::TraitDef>) -> Option<TraitId> {
|
||||
pub(super) fn trait_to_def(&mut self, src: InFile<ast::Trait>) -> Option<TraitId> {
|
||||
self.to_def(src, keys::TRAIT)
|
||||
}
|
||||
pub(super) fn impl_to_def(&mut self, src: InFile<ast::ImplDef>) -> Option<ImplId> {
|
||||
|
@ -154,7 +154,7 @@ impl SourceToDefCtx<'_, '_> {
|
|||
let def = self.module_to_def(container.with_value(it))?;
|
||||
def.into()
|
||||
},
|
||||
ast::TraitDef(it) => {
|
||||
ast::Trait(it) => {
|
||||
let def = self.trait_to_def(container.with_value(it))?;
|
||||
def.into()
|
||||
},
|
||||
|
@ -207,7 +207,7 @@ impl SourceToDefCtx<'_, '_> {
|
|||
ast::Fn(it) => self.fn_to_def(container.with_value(it))?.into(),
|
||||
ast::Struct(it) => self.struct_to_def(container.with_value(it))?.into(),
|
||||
ast::Enum(it) => self.enum_to_def(container.with_value(it))?.into(),
|
||||
ast::TraitDef(it) => self.trait_to_def(container.with_value(it))?.into(),
|
||||
ast::Trait(it) => self.trait_to_def(container.with_value(it))?.into(),
|
||||
ast::TypeAlias(it) => self.type_alias_to_def(container.with_value(it))?.into(),
|
||||
ast::ImplDef(it) => self.impl_to_def(container.with_value(it))?.into(),
|
||||
_ => continue,
|
||||
|
|
|
@ -664,7 +664,7 @@ impl ExprCollector<'_> {
|
|||
let id = self.find_inner_item(&def)?;
|
||||
(UnionLoc { container, id }.intern(self.db).into(), def.name())
|
||||
}
|
||||
ast::Item::TraitDef(def) => {
|
||||
ast::Item::Trait(def) => {
|
||||
let id = self.find_inner_item(&def)?;
|
||||
(TraitLoc { container, id }.intern(self.db).into(), def.name())
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ pub enum WherePredicateTarget {
|
|||
TypeParam(LocalTypeParamId),
|
||||
}
|
||||
|
||||
type SourceMap = ArenaMap<LocalTypeParamId, Either<ast::TraitDef, ast::TypeParam>>;
|
||||
type SourceMap = ArenaMap<LocalTypeParamId, Either<ast::Trait, ast::TypeParam>>;
|
||||
|
||||
impl GenericParams {
|
||||
pub(crate) fn generic_params_query(
|
||||
|
@ -317,7 +317,7 @@ impl GenericParams {
|
|||
|
||||
impl HasChildSource for GenericDefId {
|
||||
type ChildId = LocalTypeParamId;
|
||||
type Value = Either<ast::TraitDef, ast::TypeParam>;
|
||||
type Value = Either<ast::Trait, ast::TypeParam>;
|
||||
fn child_source(&self, db: &dyn DefDatabase) -> InFile<SourceMap> {
|
||||
let (_, sm) = GenericParams::new(db, *self);
|
||||
sm
|
||||
|
|
|
@ -419,7 +419,7 @@ mod_items! {
|
|||
Enum in enums -> ast::Enum,
|
||||
Const in consts -> ast::Const,
|
||||
Static in statics -> ast::Static,
|
||||
Trait in traits -> ast::TraitDef,
|
||||
Trait in traits -> ast::Trait,
|
||||
Impl in impls -> ast::ImplDef,
|
||||
TypeAlias in type_aliases -> ast::TypeAlias,
|
||||
Mod in mods -> ast::Module,
|
||||
|
@ -571,7 +571,7 @@ pub struct Trait {
|
|||
pub generic_params: GenericParamsId,
|
||||
pub auto: bool,
|
||||
pub items: Box<[AssocItem]>,
|
||||
pub ast_id: FileAstId<ast::TraitDef>,
|
||||
pub ast_id: FileAstId<ast::Trait>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
|
|
|
@ -95,7 +95,7 @@ impl Ctx {
|
|||
|
||||
// These are handled in their respective `lower_X` method (since we can't just blindly
|
||||
// walk them).
|
||||
ast::Item::TraitDef(_) | ast::Item::ImplDef(_) | ast::Item::ExternBlock(_) => {}
|
||||
ast::Item::Trait(_) | ast::Item::ImplDef(_) | ast::Item::ExternBlock(_) => {}
|
||||
|
||||
// These don't have inner items.
|
||||
ast::Item::Module(_) | ast::Item::ExternCrate(_) | ast::Item::Use(_) => {}
|
||||
|
@ -111,7 +111,7 @@ impl Ctx {
|
|||
ast::Item::Static(ast) => self.lower_static(ast).map(Into::into),
|
||||
ast::Item::Const(ast) => Some(self.lower_const(ast).into()),
|
||||
ast::Item::Module(ast) => self.lower_module(ast).map(Into::into),
|
||||
ast::Item::TraitDef(ast) => self.lower_trait(ast).map(Into::into),
|
||||
ast::Item::Trait(ast) => self.lower_trait(ast).map(Into::into),
|
||||
ast::Item::ImplDef(ast) => self.lower_impl(ast).map(Into::into),
|
||||
ast::Item::Use(ast) => Some(ModItems(
|
||||
self.lower_use(ast).into_iter().map(Into::into).collect::<SmallVec<_>>(),
|
||||
|
@ -413,7 +413,7 @@ impl Ctx {
|
|||
Some(id(self.data().mods.alloc(res)))
|
||||
}
|
||||
|
||||
fn lower_trait(&mut self, trait_def: &ast::TraitDef) -> Option<FileItemTreeId<Trait>> {
|
||||
fn lower_trait(&mut self, trait_def: &ast::Trait) -> Option<FileItemTreeId<Trait>> {
|
||||
let name = trait_def.name()?.as_name();
|
||||
let visibility = self.lower_visibility(trait_def);
|
||||
let generic_params =
|
||||
|
@ -698,7 +698,7 @@ enum GenericsOwner<'a> {
|
|||
Enum,
|
||||
Union,
|
||||
/// The `TraitDef` is needed to fill the source map for the implicit `Self` parameter.
|
||||
Trait(&'a ast::TraitDef),
|
||||
Trait(&'a ast::Trait),
|
||||
TypeAlias,
|
||||
Impl,
|
||||
}
|
||||
|
|
|
@ -234,7 +234,7 @@ fn smoke() {
|
|||
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("ext_crate"))] }, input: None }]) }]
|
||||
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) }
|
||||
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("on_trait"))] }, input: None }]) }]
|
||||
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) }
|
||||
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) }
|
||||
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_ty"))] }, input: None }]) }]
|
||||
> 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) }
|
||||
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_const"))] }, input: None }]) }]
|
||||
|
@ -327,7 +327,7 @@ fn trait_attrs() {
|
|||
|
||||
top-level items:
|
||||
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("trait_attr"))] }, input: None }]) }]
|
||||
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) }
|
||||
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) }
|
||||
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_a"))] }, input: None }]) }]
|
||||
> 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) }
|
||||
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_b"))] }, input: None }]) }]
|
||||
|
|
|
@ -19,7 +19,7 @@ pub const CONST: Key<ast::Const, ConstId> = Key::new();
|
|||
pub const STATIC: Key<ast::Static, StaticId> = Key::new();
|
||||
pub const TYPE_ALIAS: Key<ast::TypeAlias, TypeAliasId> = Key::new();
|
||||
pub const IMPL: Key<ast::ImplDef, ImplId> = Key::new();
|
||||
pub const TRAIT: Key<ast::TraitDef, TraitId> = Key::new();
|
||||
pub const TRAIT: Key<ast::Trait, TraitId> = Key::new();
|
||||
pub const STRUCT: Key<ast::Struct, StructId> = Key::new();
|
||||
pub const UNION: Key<ast::Union, UnionId> = Key::new();
|
||||
pub const ENUM: Key<ast::Enum, EnumId> = Key::new();
|
||||
|
|
|
@ -15,7 +15,7 @@ pub(crate) fn has_trait_parent(element: SyntaxElement) -> bool {
|
|||
not_same_range_ancestor(element)
|
||||
.filter(|it| it.kind() == ASSOC_ITEM_LIST)
|
||||
.and_then(|it| it.parent())
|
||||
.filter(|it| it.kind() == TRAIT_DEF)
|
||||
.filter(|it| it.kind() == TRAIT)
|
||||
.is_some()
|
||||
}
|
||||
#[test]
|
||||
|
@ -113,7 +113,7 @@ fn test_if_is_prev() {
|
|||
}
|
||||
|
||||
pub(crate) fn has_trait_as_prev_sibling(element: SyntaxElement) -> bool {
|
||||
previous_sibling_or_ancestor_sibling(element).filter(|it| it.kind() == TRAIT_DEF).is_some()
|
||||
previous_sibling_or_ancestor_sibling(element).filter(|it| it.kind() == TRAIT).is_some()
|
||||
}
|
||||
#[test]
|
||||
fn test_has_trait_as_prev_sibling() {
|
||||
|
|
|
@ -382,7 +382,7 @@ pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option
|
|||
ast::Fn(it) => it.doc_comment_text(),
|
||||
ast::Struct(it) => it.doc_comment_text(),
|
||||
ast::Enum(it) => it.doc_comment_text(),
|
||||
ast::TraitDef(it) => it.doc_comment_text(),
|
||||
ast::Trait(it) => it.doc_comment_text(),
|
||||
ast::Module(it) => it.doc_comment_text(),
|
||||
ast::TypeAlias(it) => it.doc_comment_text(),
|
||||
ast::Const(it) => it.doc_comment_text(),
|
||||
|
@ -407,7 +407,7 @@ pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) ->
|
|||
ast::Fn(it) => it.short_label(),
|
||||
ast::Struct(it) => it.short_label(),
|
||||
ast::Enum(it) => it.short_label(),
|
||||
ast::TraitDef(it) => it.short_label(),
|
||||
ast::Trait(it) => it.short_label(),
|
||||
ast::Module(it) => it.short_label(),
|
||||
ast::TypeAlias(it) => it.short_label(),
|
||||
ast::Const(it) => it.short_label(),
|
||||
|
|
|
@ -31,7 +31,7 @@ impl ShortLabel for ast::Enum {
|
|||
}
|
||||
}
|
||||
|
||||
impl ShortLabel for ast::TraitDef {
|
||||
impl ShortLabel for ast::Trait {
|
||||
fn short_label(&self) -> Option<String> {
|
||||
if self.unsafe_token().is_some() {
|
||||
short_label_from_node(self, "unsafe trait ")
|
||||
|
|
|
@ -130,7 +130,7 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
|
|||
ast::Union(it) => decl(it),
|
||||
ast::Enum(it) => decl(it),
|
||||
ast::Variant(it) => decl(it),
|
||||
ast::TraitDef(it) => decl(it),
|
||||
ast::Trait(it) => decl(it),
|
||||
ast::Module(it) => decl(it),
|
||||
ast::TypeAlias(it) => {
|
||||
let ty = it.type_ref();
|
||||
|
|
|
@ -28,7 +28,7 @@ pub(crate) fn goto_implementation(
|
|||
nominal_def.syntax().text_range(),
|
||||
impls_for_def(&sema, &nominal_def, krate)?,
|
||||
));
|
||||
} else if let Some(trait_def) = find_node_at_offset::<ast::TraitDef>(&syntax, position.offset) {
|
||||
} else if let Some(trait_def) = find_node_at_offset::<ast::Trait>(&syntax, position.offset) {
|
||||
return Some(RangeInfo::new(
|
||||
trait_def.syntax().text_range(),
|
||||
impls_for_trait(&sema, &trait_def, krate)?,
|
||||
|
@ -62,7 +62,7 @@ fn impls_for_def(
|
|||
|
||||
fn impls_for_trait(
|
||||
sema: &Semantics<RootDatabase>,
|
||||
node: &ast::TraitDef,
|
||||
node: &ast::Trait,
|
||||
krate: Crate,
|
||||
) -> Option<Vec<NavigationTarget>> {
|
||||
let tr = sema.to_def(node)?;
|
||||
|
|
|
@ -1678,7 +1678,7 @@ fn main() { let s<|>t = foo(); }
|
|||
6..9,
|
||||
),
|
||||
name: "Foo",
|
||||
kind: TRAIT_DEF,
|
||||
kind: TRAIT,
|
||||
container_name: None,
|
||||
description: Some(
|
||||
"trait Foo",
|
||||
|
@ -1718,7 +1718,7 @@ fn main() { let s<|>t = foo(); }
|
|||
6..9,
|
||||
),
|
||||
name: "Foo",
|
||||
kind: TRAIT_DEF,
|
||||
kind: TRAIT,
|
||||
container_name: None,
|
||||
description: Some(
|
||||
"trait Foo",
|
||||
|
@ -1777,7 +1777,7 @@ fn main() { let s<|>t = foo(); }
|
|||
6..9,
|
||||
),
|
||||
name: "Foo",
|
||||
kind: TRAIT_DEF,
|
||||
kind: TRAIT,
|
||||
container_name: None,
|
||||
description: Some(
|
||||
"trait Foo",
|
||||
|
@ -1796,7 +1796,7 @@ fn main() { let s<|>t = foo(); }
|
|||
19..22,
|
||||
),
|
||||
name: "Bar",
|
||||
kind: TRAIT_DEF,
|
||||
kind: TRAIT,
|
||||
container_name: None,
|
||||
description: Some(
|
||||
"trait Bar",
|
||||
|
@ -1839,7 +1839,7 @@ fn main() { let s<|>t = foo(); }
|
|||
6..9,
|
||||
),
|
||||
name: "Foo",
|
||||
kind: TRAIT_DEF,
|
||||
kind: TRAIT,
|
||||
container_name: None,
|
||||
description: Some(
|
||||
"trait Foo",
|
||||
|
@ -1858,7 +1858,7 @@ fn main() { let s<|>t = foo(); }
|
|||
22..25,
|
||||
),
|
||||
name: "Bar",
|
||||
kind: TRAIT_DEF,
|
||||
kind: TRAIT,
|
||||
container_name: None,
|
||||
description: Some(
|
||||
"trait Bar",
|
||||
|
@ -1933,7 +1933,7 @@ fn foo(ar<|>g: &impl Foo) {}
|
|||
6..9,
|
||||
),
|
||||
name: "Foo",
|
||||
kind: TRAIT_DEF,
|
||||
kind: TRAIT,
|
||||
container_name: None,
|
||||
description: Some(
|
||||
"trait Foo",
|
||||
|
@ -1973,7 +1973,7 @@ fn foo(ar<|>g: &impl Foo + Bar<S>) {}
|
|||
6..9,
|
||||
),
|
||||
name: "Foo",
|
||||
kind: TRAIT_DEF,
|
||||
kind: TRAIT,
|
||||
container_name: None,
|
||||
description: Some(
|
||||
"trait Foo",
|
||||
|
@ -1992,7 +1992,7 @@ fn foo(ar<|>g: &impl Foo + Bar<S>) {}
|
|||
19..22,
|
||||
),
|
||||
name: "Bar",
|
||||
kind: TRAIT_DEF,
|
||||
kind: TRAIT,
|
||||
container_name: None,
|
||||
description: Some(
|
||||
"trait Bar",
|
||||
|
@ -2049,7 +2049,7 @@ fn foo(ar<|>g: &impl Foo<S>) {}
|
|||
6..9,
|
||||
),
|
||||
name: "Foo",
|
||||
kind: TRAIT_DEF,
|
||||
kind: TRAIT,
|
||||
container_name: None,
|
||||
description: Some(
|
||||
"trait Foo",
|
||||
|
@ -2130,7 +2130,7 @@ fn main() { let s<|>t = foo(); }
|
|||
6..9,
|
||||
),
|
||||
name: "Foo",
|
||||
kind: TRAIT_DEF,
|
||||
kind: TRAIT,
|
||||
container_name: None,
|
||||
description: Some(
|
||||
"trait Foo",
|
||||
|
@ -2167,7 +2167,7 @@ fn foo(ar<|>g: &dyn Foo) {}
|
|||
6..9,
|
||||
),
|
||||
name: "Foo",
|
||||
kind: TRAIT_DEF,
|
||||
kind: TRAIT,
|
||||
container_name: None,
|
||||
description: Some(
|
||||
"trait Foo",
|
||||
|
@ -2205,7 +2205,7 @@ fn foo(ar<|>g: &dyn Foo<S>) {}
|
|||
6..9,
|
||||
),
|
||||
name: "Foo",
|
||||
kind: TRAIT_DEF,
|
||||
kind: TRAIT,
|
||||
container_name: None,
|
||||
description: Some(
|
||||
"trait Foo",
|
||||
|
@ -2265,7 +2265,7 @@ fn foo(a<|>rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
|
|||
6..15,
|
||||
),
|
||||
name: "ImplTrait",
|
||||
kind: TRAIT_DEF,
|
||||
kind: TRAIT,
|
||||
container_name: None,
|
||||
description: Some(
|
||||
"trait ImplTrait",
|
||||
|
@ -2303,7 +2303,7 @@ fn foo(a<|>rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
|
|||
28..36,
|
||||
),
|
||||
name: "DynTrait",
|
||||
kind: TRAIT_DEF,
|
||||
kind: TRAIT,
|
||||
container_name: None,
|
||||
description: Some(
|
||||
"trait DynTrait",
|
||||
|
@ -2370,7 +2370,7 @@ fn main() { let s<|>t = test().get(); }
|
|||
6..9,
|
||||
),
|
||||
name: "Foo",
|
||||
kind: TRAIT_DEF,
|
||||
kind: TRAIT,
|
||||
container_name: None,
|
||||
description: Some(
|
||||
"trait Foo",
|
||||
|
|
|
@ -708,7 +708,7 @@ fn highlight_name_by_syntax(name: ast::Name) -> Highlight {
|
|||
STRUCT => HighlightTag::Struct,
|
||||
ENUM => HighlightTag::Enum,
|
||||
UNION => HighlightTag::Union,
|
||||
TRAIT_DEF => HighlightTag::Trait,
|
||||
TRAIT => HighlightTag::Trait,
|
||||
TYPE_ALIAS => HighlightTag::TypeAlias,
|
||||
TYPE_PARAM => HighlightTag::TypeParam,
|
||||
RECORD_FIELD => HighlightTag::Field,
|
||||
|
|
|
@ -162,7 +162,7 @@ pub fn classify_name(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Option
|
|||
let def: hir::Enum = sema.to_def(&it)?;
|
||||
Some(NameClass::Definition(Definition::ModuleDef(def.into())))
|
||||
},
|
||||
ast::TraitDef(it) => {
|
||||
ast::Trait(it) => {
|
||||
let def: hir::Trait = sema.to_def(&it)?;
|
||||
Some(NameClass::Definition(Definition::ModuleDef(def.into())))
|
||||
},
|
||||
|
|
|
@ -344,7 +344,7 @@ impl Query {
|
|||
}
|
||||
|
||||
fn is_type(kind: SyntaxKind) -> bool {
|
||||
matches!(kind, STRUCT | ENUM | TRAIT_DEF | TYPE_ALIAS)
|
||||
matches!(kind, STRUCT | ENUM | TRAIT | TYPE_ALIAS)
|
||||
}
|
||||
|
||||
/// The actual data that is stored in the index. It should be as compact as
|
||||
|
@ -400,7 +400,7 @@ fn to_symbol(node: &SyntaxNode) -> Option<(SmolStr, SyntaxNodePtr, TextRange)> {
|
|||
ast::Fn(it) => decl(it),
|
||||
ast::Struct(it) => decl(it),
|
||||
ast::Enum(it) => decl(it),
|
||||
ast::TraitDef(it) => decl(it),
|
||||
ast::Trait(it) => decl(it),
|
||||
ast::Module(it) => decl(it),
|
||||
ast::TypeAlias(it) => decl(it),
|
||||
ast::Const(it) => decl(it),
|
||||
|
|
|
@ -151,7 +151,7 @@ pub(crate) fn reparser(
|
|||
TOKEN_TREE if first_child? == T!['{'] => items::token_tree,
|
||||
ASSOC_ITEM_LIST => match parent? {
|
||||
IMPL_DEF => items::impl_item_list,
|
||||
TRAIT_DEF => items::trait_item_list,
|
||||
TRAIT => items::trait_item_list,
|
||||
_ => return None,
|
||||
},
|
||||
ITEM_LIST => items::mod_item_list,
|
||||
|
|
|
@ -193,7 +193,7 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul
|
|||
// unsafe auto trait T {}
|
||||
T![trait] => {
|
||||
traits::trait_def(p);
|
||||
m.complete(p, TRAIT_DEF);
|
||||
m.complete(p, TRAIT);
|
||||
}
|
||||
|
||||
// test unsafe_impl
|
||||
|
|
|
@ -133,7 +133,7 @@ pub enum SyntaxKind {
|
|||
USE,
|
||||
STATIC,
|
||||
CONST,
|
||||
TRAIT_DEF,
|
||||
TRAIT,
|
||||
IMPL_DEF,
|
||||
TYPE_ALIAS,
|
||||
MACRO_CALL,
|
||||
|
|
|
@ -169,15 +169,15 @@ impl Struct {
|
|||
pub fn field_list(&self) -> Option<FieldList> { support::child(&self.syntax) }
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct TraitDef {
|
||||
pub struct Trait {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
impl ast::AttrsOwner for TraitDef {}
|
||||
impl ast::NameOwner for TraitDef {}
|
||||
impl ast::VisibilityOwner for TraitDef {}
|
||||
impl ast::GenericParamsOwner for TraitDef {}
|
||||
impl ast::TypeBoundsOwner for TraitDef {}
|
||||
impl TraitDef {
|
||||
impl ast::AttrsOwner for Trait {}
|
||||
impl ast::NameOwner for Trait {}
|
||||
impl ast::VisibilityOwner for Trait {}
|
||||
impl ast::GenericParamsOwner for Trait {}
|
||||
impl ast::TypeBoundsOwner for Trait {}
|
||||
impl Trait {
|
||||
pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) }
|
||||
pub fn auto_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![auto]) }
|
||||
pub fn trait_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![trait]) }
|
||||
|
@ -1283,7 +1283,7 @@ pub enum Item {
|
|||
Module(Module),
|
||||
Static(Static),
|
||||
Struct(Struct),
|
||||
TraitDef(TraitDef),
|
||||
Trait(Trait),
|
||||
TypeAlias(TypeAlias),
|
||||
Union(Union),
|
||||
Use(Use),
|
||||
|
@ -1532,8 +1532,8 @@ impl AstNode for Struct {
|
|||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
impl AstNode for TraitDef {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == TRAIT_DEF }
|
||||
impl AstNode for Trait {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == TRAIT }
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
|
@ -2805,8 +2805,8 @@ impl From<Static> for Item {
|
|||
impl From<Struct> for Item {
|
||||
fn from(node: Struct) -> Item { Item::Struct(node) }
|
||||
}
|
||||
impl From<TraitDef> for Item {
|
||||
fn from(node: TraitDef) -> Item { Item::TraitDef(node) }
|
||||
impl From<Trait> for Item {
|
||||
fn from(node: Trait) -> Item { Item::Trait(node) }
|
||||
}
|
||||
impl From<TypeAlias> for Item {
|
||||
fn from(node: TypeAlias) -> Item { Item::TypeAlias(node) }
|
||||
|
@ -2821,7 +2821,7 @@ impl AstNode for Item {
|
|||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
CONST | ENUM | EXTERN_BLOCK | EXTERN_CRATE | FN | IMPL_DEF | MACRO_CALL | MODULE
|
||||
| STATIC | STRUCT | TRAIT_DEF | TYPE_ALIAS | UNION | USE => true,
|
||||
| STATIC | STRUCT | TRAIT | TYPE_ALIAS | UNION | USE => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -2837,7 +2837,7 @@ impl AstNode for Item {
|
|||
MODULE => Item::Module(Module { syntax }),
|
||||
STATIC => Item::Static(Static { syntax }),
|
||||
STRUCT => Item::Struct(Struct { syntax }),
|
||||
TRAIT_DEF => Item::TraitDef(TraitDef { syntax }),
|
||||
TRAIT => Item::Trait(Trait { syntax }),
|
||||
TYPE_ALIAS => Item::TypeAlias(TypeAlias { syntax }),
|
||||
UNION => Item::Union(Union { syntax }),
|
||||
USE => Item::Use(Use { syntax }),
|
||||
|
@ -2857,7 +2857,7 @@ impl AstNode for Item {
|
|||
Item::Module(it) => &it.syntax,
|
||||
Item::Static(it) => &it.syntax,
|
||||
Item::Struct(it) => &it.syntax,
|
||||
Item::TraitDef(it) => &it.syntax,
|
||||
Item::Trait(it) => &it.syntax,
|
||||
Item::TypeAlias(it) => &it.syntax,
|
||||
Item::Union(it) => &it.syntax,
|
||||
Item::Use(it) => &it.syntax,
|
||||
|
@ -3516,7 +3516,7 @@ impl std::fmt::Display for Struct {
|
|||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for TraitDef {
|
||||
impl std::fmt::Display for Trait {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
|
|
|
@ -481,7 +481,7 @@ impl ast::DocCommentsOwner for ast::RecordField {}
|
|||
impl ast::DocCommentsOwner for ast::TupleField {}
|
||||
impl ast::DocCommentsOwner for ast::Enum {}
|
||||
impl ast::DocCommentsOwner for ast::Variant {}
|
||||
impl ast::DocCommentsOwner for ast::TraitDef {}
|
||||
impl ast::DocCommentsOwner for ast::Trait {}
|
||||
impl ast::DocCommentsOwner for ast::Module {}
|
||||
impl ast::DocCommentsOwner for ast::Static {}
|
||||
impl ast::DocCommentsOwner for ast::Const {}
|
||||
|
|
|
@ -146,7 +146,7 @@ fn n_attached_trivias<'a>(
|
|||
trivias: impl Iterator<Item = (SyntaxKind, &'a str)>,
|
||||
) -> usize {
|
||||
match kind {
|
||||
MACRO_CALL | CONST | TYPE_ALIAS | STRUCT | ENUM | VARIANT | FN | TRAIT_DEF | MODULE
|
||||
MACRO_CALL | CONST | TYPE_ALIAS | STRUCT | ENUM | VARIANT | FN | TRAIT | MODULE
|
||||
| RECORD_FIELD | STATIC => {
|
||||
let mut res = 0;
|
||||
let mut trivias = trivias.enumerate().peekable();
|
||||
|
|
|
@ -133,7 +133,7 @@ SOURCE_FILE@0..112
|
|||
ERROR@96..97
|
||||
COMMA@96..97 ","
|
||||
WHITESPACE@97..98 " "
|
||||
TRAIT_DEF@98..104
|
||||
TRAIT@98..104
|
||||
TRAIT_KW@98..103 "trait"
|
||||
ERROR@103..104
|
||||
COMMA@103..104 ","
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
SOURCE_FILE@0..39
|
||||
TRAIT_DEF@0..38
|
||||
TRAIT@0..38
|
||||
TRAIT_KW@0..5 "trait"
|
||||
WHITESPACE@5..6 " "
|
||||
NAME@6..7
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
SOURCE_FILE@0..62
|
||||
TRAIT_DEF@0..61
|
||||
TRAIT@0..61
|
||||
TRAIT_KW@0..5 "trait"
|
||||
WHITESPACE@5..6 " "
|
||||
NAME@6..7
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
SOURCE_FILE@0..18
|
||||
TRAIT_DEF@0..17
|
||||
TRAIT@0..17
|
||||
UNSAFE_KW@0..6 "unsafe"
|
||||
WHITESPACE@6..7 " "
|
||||
TRAIT_KW@7..12 "trait"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
SOURCE_FILE@0..101
|
||||
TRAIT_DEF@0..41
|
||||
TRAIT@0..41
|
||||
TRAIT_KW@0..5 "trait"
|
||||
WHITESPACE@5..6 " "
|
||||
NAME@6..7
|
||||
|
@ -52,7 +52,7 @@ SOURCE_FILE@0..101
|
|||
L_CURLY@39..40 "{"
|
||||
R_CURLY@40..41 "}"
|
||||
WHITESPACE@41..42 "\n"
|
||||
TRAIT_DEF@42..100
|
||||
TRAIT@42..100
|
||||
TRAIT_KW@42..47 "trait"
|
||||
WHITESPACE@47..48 " "
|
||||
NAME@48..49
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
SOURCE_FILE@0..22
|
||||
TRAIT_DEF@0..21
|
||||
TRAIT@0..21
|
||||
TRAIT_KW@0..5 "trait"
|
||||
WHITESPACE@5..6 " "
|
||||
NAME@6..7
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
SOURCE_FILE@0..16
|
||||
TRAIT_DEF@0..15
|
||||
TRAIT@0..15
|
||||
AUTO_KW@0..4 "auto"
|
||||
WHITESPACE@4..5 " "
|
||||
TRAIT_KW@5..10 "trait"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
SOURCE_FILE@0..23
|
||||
TRAIT_DEF@0..22
|
||||
TRAIT@0..22
|
||||
UNSAFE_KW@0..6 "unsafe"
|
||||
WHITESPACE@6..7 " "
|
||||
AUTO_KW@7..11 "auto"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
SOURCE_FILE@0..83
|
||||
TRAIT_DEF@0..18
|
||||
TRAIT@0..18
|
||||
TRAIT_KW@0..5 "trait"
|
||||
WHITESPACE@5..6 " "
|
||||
NAME@6..7
|
||||
|
@ -31,7 +31,7 @@ SOURCE_FILE@0..83
|
|||
R_ANGLE@16..17 ">"
|
||||
SEMICOLON@17..18 ";"
|
||||
WHITESPACE@18..19 "\n"
|
||||
TRAIT_DEF@19..51
|
||||
TRAIT@19..51
|
||||
TRAIT_KW@19..24 "trait"
|
||||
WHITESPACE@24..25 " "
|
||||
NAME@25..26
|
||||
|
@ -82,7 +82,7 @@ SOURCE_FILE@0..83
|
|||
IDENT@46..50 "Copy"
|
||||
SEMICOLON@50..51 ";"
|
||||
WHITESPACE@51..52 "\n"
|
||||
TRAIT_DEF@52..82
|
||||
TRAIT@52..82
|
||||
TRAIT_KW@52..57 "trait"
|
||||
WHITESPACE@57..58 " "
|
||||
NAME@58..59
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
SOURCE_FILE@0..96
|
||||
TRAIT_DEF@0..36
|
||||
TRAIT@0..36
|
||||
TRAIT_KW@0..5 "trait"
|
||||
WHITESPACE@5..6 " "
|
||||
NAME@6..14
|
||||
|
@ -20,7 +20,7 @@ SOURCE_FILE@0..96
|
|||
WHITESPACE@34..35 "\n"
|
||||
R_CURLY@35..36 "}"
|
||||
WHITESPACE@36..38 "\n\n"
|
||||
TRAIT_DEF@38..95
|
||||
TRAIT@38..95
|
||||
TRAIT_KW@38..43 "trait"
|
||||
WHITESPACE@43..44 " "
|
||||
NAME@44..57
|
||||
|
|
|
@ -186,7 +186,7 @@ SOURCE_FILE@0..519
|
|||
L_CURLY@170..171 "{"
|
||||
R_CURLY@171..172 "}"
|
||||
WHITESPACE@172..174 "\n\n"
|
||||
TRAIT_DEF@174..236
|
||||
TRAIT@174..236
|
||||
TRAIT_KW@174..179 "trait"
|
||||
WHITESPACE@179..180 " "
|
||||
NAME@180..183
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
SOURCE_FILE@0..170
|
||||
TRAIT_DEF@0..169
|
||||
TRAIT@0..169
|
||||
TRAIT_KW@0..5 "trait"
|
||||
WHITESPACE@5..6 " "
|
||||
NAME@6..7
|
||||
|
|
|
@ -924,7 +924,7 @@ pub(crate) fn handle_code_lens(
|
|||
.filter(|it| {
|
||||
matches!(
|
||||
it.kind,
|
||||
SyntaxKind::TRAIT_DEF
|
||||
SyntaxKind::TRAIT
|
||||
| SyntaxKind::STRUCT
|
||||
| SyntaxKind::ENUM
|
||||
| SyntaxKind::UNION
|
||||
|
|
|
@ -35,7 +35,7 @@ pub(crate) fn symbol_kind(syntax_kind: SyntaxKind) -> lsp_types::SymbolKind {
|
|||
SyntaxKind::STRUCT => lsp_types::SymbolKind::Struct,
|
||||
SyntaxKind::ENUM => lsp_types::SymbolKind::Enum,
|
||||
SyntaxKind::VARIANT => lsp_types::SymbolKind::EnumMember,
|
||||
SyntaxKind::TRAIT_DEF => lsp_types::SymbolKind::Interface,
|
||||
SyntaxKind::TRAIT => lsp_types::SymbolKind::Interface,
|
||||
SyntaxKind::MACRO_CALL => lsp_types::SymbolKind::Function,
|
||||
SyntaxKind::MODULE => lsp_types::SymbolKind::Module,
|
||||
SyntaxKind::TYPE_ALIAS => lsp_types::SymbolKind::TypeParameter,
|
||||
|
|
|
@ -103,7 +103,7 @@ pub(crate) const KINDS_SRC: KindsSrc = KindsSrc {
|
|||
"USE",
|
||||
"STATIC",
|
||||
"CONST",
|
||||
"TRAIT_DEF",
|
||||
"TRAIT",
|
||||
"IMPL_DEF",
|
||||
"TYPE_ALIAS",
|
||||
"MACRO_CALL",
|
||||
|
|
|
@ -14,7 +14,7 @@ Item =
|
|||
| Module
|
||||
| Static
|
||||
| Struct
|
||||
| TraitDef
|
||||
| Trait
|
||||
| TypeAlias
|
||||
| Union
|
||||
| Use
|
||||
|
@ -123,7 +123,7 @@ Static =
|
|||
Attr* Visibility? 'static'? 'mut'? Name ':' ascribed_type:TypeRef
|
||||
'=' body:Expr ';'
|
||||
|
||||
TraitDef =
|
||||
Trait =
|
||||
Attr* Visibility? 'unsafe'? 'auto'? 'trait' Name GenericParamList
|
||||
(':' TypeBoundList?)? WhereClause
|
||||
AssocItemList
|
||||
|
|
Loading…
Reference in a new issue