mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 12:33:33 +00:00
Merge #5578
5578: Rename ModuleItem -> Item r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
9da454bcc2
19 changed files with 553 additions and 557 deletions
|
@ -627,53 +627,53 @@ impl ExprCollector<'_> {
|
|||
.items()
|
||||
.filter_map(|item| {
|
||||
let (def, name): (ModuleDefId, Option<ast::Name>) = match item {
|
||||
ast::ModuleItem::FnDef(def) => {
|
||||
ast::Item::FnDef(def) => {
|
||||
let id = self.find_inner_item(&def)?;
|
||||
(
|
||||
FunctionLoc { container: container.into(), id }.intern(self.db).into(),
|
||||
def.name(),
|
||||
)
|
||||
}
|
||||
ast::ModuleItem::TypeAliasDef(def) => {
|
||||
ast::Item::TypeAliasDef(def) => {
|
||||
let id = self.find_inner_item(&def)?;
|
||||
(
|
||||
TypeAliasLoc { container: container.into(), id }.intern(self.db).into(),
|
||||
def.name(),
|
||||
)
|
||||
}
|
||||
ast::ModuleItem::ConstDef(def) => {
|
||||
ast::Item::ConstDef(def) => {
|
||||
let id = self.find_inner_item(&def)?;
|
||||
(
|
||||
ConstLoc { container: container.into(), id }.intern(self.db).into(),
|
||||
def.name(),
|
||||
)
|
||||
}
|
||||
ast::ModuleItem::StaticDef(def) => {
|
||||
ast::Item::StaticDef(def) => {
|
||||
let id = self.find_inner_item(&def)?;
|
||||
(StaticLoc { container, id }.intern(self.db).into(), def.name())
|
||||
}
|
||||
ast::ModuleItem::StructDef(def) => {
|
||||
ast::Item::StructDef(def) => {
|
||||
let id = self.find_inner_item(&def)?;
|
||||
(StructLoc { container, id }.intern(self.db).into(), def.name())
|
||||
}
|
||||
ast::ModuleItem::EnumDef(def) => {
|
||||
ast::Item::EnumDef(def) => {
|
||||
let id = self.find_inner_item(&def)?;
|
||||
(EnumLoc { container, id }.intern(self.db).into(), def.name())
|
||||
}
|
||||
ast::ModuleItem::UnionDef(def) => {
|
||||
ast::Item::UnionDef(def) => {
|
||||
let id = self.find_inner_item(&def)?;
|
||||
(UnionLoc { container, id }.intern(self.db).into(), def.name())
|
||||
}
|
||||
ast::ModuleItem::TraitDef(def) => {
|
||||
ast::Item::TraitDef(def) => {
|
||||
let id = self.find_inner_item(&def)?;
|
||||
(TraitLoc { container, id }.intern(self.db).into(), def.name())
|
||||
}
|
||||
ast::ModuleItem::ExternBlock(_) => return None, // FIXME: collect from extern blocks
|
||||
ast::ModuleItem::ImplDef(_)
|
||||
| ast::ModuleItem::UseItem(_)
|
||||
| ast::ModuleItem::ExternCrateItem(_)
|
||||
| ast::ModuleItem::Module(_)
|
||||
| ast::ModuleItem::MacroCall(_) => return None,
|
||||
ast::Item::ExternBlock(_) => return None, // FIXME: collect from extern blocks
|
||||
ast::Item::ImplDef(_)
|
||||
| ast::Item::UseItem(_)
|
||||
| ast::Item::ExternCrateItem(_)
|
||||
| ast::Item::Module(_)
|
||||
| ast::Item::MacroCall(_) => return None,
|
||||
};
|
||||
|
||||
Some((def, name))
|
||||
|
|
|
@ -70,7 +70,7 @@ impl GenericParamsId {
|
|||
pub struct ItemTree {
|
||||
top_level: SmallVec<[ModItem; 1]>,
|
||||
attrs: FxHashMap<AttrOwner, Attrs>,
|
||||
inner_items: FxHashMap<FileAstId<ast::ModuleItem>, SmallVec<[ModItem; 1]>>,
|
||||
inner_items: FxHashMap<FileAstId<ast::Item>, SmallVec<[ModItem; 1]>>,
|
||||
|
||||
data: Option<Box<ItemTreeData>>,
|
||||
}
|
||||
|
@ -187,7 +187,7 @@ impl ItemTree {
|
|||
///
|
||||
/// Most AST items are lowered to a single `ModItem`, but some (eg. `use` items) may be lowered
|
||||
/// to multiple items in the `ItemTree`.
|
||||
pub fn inner_items(&self, ast: FileAstId<ast::ModuleItem>) -> &[ModItem] {
|
||||
pub fn inner_items(&self, ast: FileAstId<ast::Item>) -> &[ModItem] {
|
||||
&self.inner_items[&ast]
|
||||
}
|
||||
|
||||
|
@ -310,7 +310,7 @@ from_attrs!(ModItem(ModItem), Variant(Idx<Variant>), Field(Idx<Field>));
|
|||
|
||||
/// Trait implemented by all item nodes in the item tree.
|
||||
pub trait ItemTreeNode: Clone {
|
||||
type Source: AstNode + Into<ast::ModuleItem>;
|
||||
type Source: AstNode + Into<ast::Item>;
|
||||
|
||||
fn ast_id(&self) -> FileAstId<Self::Source>;
|
||||
|
||||
|
|
|
@ -70,19 +70,19 @@ impl Ctx {
|
|||
self.tree.data_mut()
|
||||
}
|
||||
|
||||
fn lower_mod_item(&mut self, item: &ast::ModuleItem, inner: bool) -> Option<ModItems> {
|
||||
fn lower_mod_item(&mut self, item: &ast::Item, inner: bool) -> Option<ModItems> {
|
||||
assert!(inner || self.inner_items.is_empty());
|
||||
|
||||
// Collect inner items for 1-to-1-lowered items.
|
||||
match item {
|
||||
ast::ModuleItem::StructDef(_)
|
||||
| ast::ModuleItem::UnionDef(_)
|
||||
| ast::ModuleItem::EnumDef(_)
|
||||
| ast::ModuleItem::FnDef(_)
|
||||
| ast::ModuleItem::TypeAliasDef(_)
|
||||
| ast::ModuleItem::ConstDef(_)
|
||||
| ast::ModuleItem::StaticDef(_)
|
||||
| ast::ModuleItem::MacroCall(_) => {
|
||||
ast::Item::StructDef(_)
|
||||
| ast::Item::UnionDef(_)
|
||||
| ast::Item::EnumDef(_)
|
||||
| ast::Item::FnDef(_)
|
||||
| ast::Item::TypeAliasDef(_)
|
||||
| ast::Item::ConstDef(_)
|
||||
| ast::Item::StaticDef(_)
|
||||
| ast::Item::MacroCall(_) => {
|
||||
// Skip this if we're already collecting inner items. We'll descend into all nodes
|
||||
// already.
|
||||
if !inner {
|
||||
|
@ -92,34 +92,30 @@ impl Ctx {
|
|||
|
||||
// These are handled in their respective `lower_X` method (since we can't just blindly
|
||||
// walk them).
|
||||
ast::ModuleItem::TraitDef(_)
|
||||
| ast::ModuleItem::ImplDef(_)
|
||||
| ast::ModuleItem::ExternBlock(_) => {}
|
||||
ast::Item::TraitDef(_) | ast::Item::ImplDef(_) | ast::Item::ExternBlock(_) => {}
|
||||
|
||||
// These don't have inner items.
|
||||
ast::ModuleItem::Module(_)
|
||||
| ast::ModuleItem::ExternCrateItem(_)
|
||||
| ast::ModuleItem::UseItem(_) => {}
|
||||
ast::Item::Module(_) | ast::Item::ExternCrateItem(_) | ast::Item::UseItem(_) => {}
|
||||
};
|
||||
|
||||
let attrs = Attrs::new(item, &self.hygiene);
|
||||
let items = match item {
|
||||
ast::ModuleItem::StructDef(ast) => self.lower_struct(ast).map(Into::into),
|
||||
ast::ModuleItem::UnionDef(ast) => self.lower_union(ast).map(Into::into),
|
||||
ast::ModuleItem::EnumDef(ast) => self.lower_enum(ast).map(Into::into),
|
||||
ast::ModuleItem::FnDef(ast) => self.lower_function(ast).map(Into::into),
|
||||
ast::ModuleItem::TypeAliasDef(ast) => self.lower_type_alias(ast).map(Into::into),
|
||||
ast::ModuleItem::StaticDef(ast) => self.lower_static(ast).map(Into::into),
|
||||
ast::ModuleItem::ConstDef(ast) => Some(self.lower_const(ast).into()),
|
||||
ast::ModuleItem::Module(ast) => self.lower_module(ast).map(Into::into),
|
||||
ast::ModuleItem::TraitDef(ast) => self.lower_trait(ast).map(Into::into),
|
||||
ast::ModuleItem::ImplDef(ast) => self.lower_impl(ast).map(Into::into),
|
||||
ast::ModuleItem::UseItem(ast) => Some(ModItems(
|
||||
ast::Item::StructDef(ast) => self.lower_struct(ast).map(Into::into),
|
||||
ast::Item::UnionDef(ast) => self.lower_union(ast).map(Into::into),
|
||||
ast::Item::EnumDef(ast) => self.lower_enum(ast).map(Into::into),
|
||||
ast::Item::FnDef(ast) => self.lower_function(ast).map(Into::into),
|
||||
ast::Item::TypeAliasDef(ast) => self.lower_type_alias(ast).map(Into::into),
|
||||
ast::Item::StaticDef(ast) => self.lower_static(ast).map(Into::into),
|
||||
ast::Item::ConstDef(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::ImplDef(ast) => self.lower_impl(ast).map(Into::into),
|
||||
ast::Item::UseItem(ast) => Some(ModItems(
|
||||
self.lower_use(ast).into_iter().map(Into::into).collect::<SmallVec<_>>(),
|
||||
)),
|
||||
ast::ModuleItem::ExternCrateItem(ast) => self.lower_extern_crate(ast).map(Into::into),
|
||||
ast::ModuleItem::MacroCall(ast) => self.lower_macro_call(ast).map(Into::into),
|
||||
ast::ModuleItem::ExternBlock(ast) => {
|
||||
ast::Item::ExternCrateItem(ast) => self.lower_extern_crate(ast).map(Into::into),
|
||||
ast::Item::MacroCall(ast) => self.lower_macro_call(ast).map(Into::into),
|
||||
ast::Item::ExternBlock(ast) => {
|
||||
Some(ModItems(self.lower_extern_block(ast).into_iter().collect::<SmallVec<_>>()))
|
||||
}
|
||||
};
|
||||
|
@ -147,22 +143,22 @@ impl Ctx {
|
|||
fn collect_inner_items(&mut self, container: &SyntaxNode) {
|
||||
let forced_vis = self.forced_visibility.take();
|
||||
let mut inner_items = mem::take(&mut self.tree.inner_items);
|
||||
inner_items.extend(
|
||||
container.descendants().skip(1).filter_map(ast::ModuleItem::cast).filter_map(|item| {
|
||||
inner_items.extend(container.descendants().skip(1).filter_map(ast::Item::cast).filter_map(
|
||||
|item| {
|
||||
let ast_id = self.source_ast_id_map.ast_id(&item);
|
||||
Some((ast_id, self.lower_mod_item(&item, true)?.0))
|
||||
}),
|
||||
);
|
||||
},
|
||||
));
|
||||
self.tree.inner_items = inner_items;
|
||||
self.forced_visibility = forced_vis;
|
||||
}
|
||||
|
||||
fn lower_assoc_item(&mut self, item: &ast::ModuleItem) -> Option<AssocItem> {
|
||||
fn lower_assoc_item(&mut self, item: &ast::Item) -> Option<AssocItem> {
|
||||
match item {
|
||||
ast::ModuleItem::FnDef(ast) => self.lower_function(ast).map(Into::into),
|
||||
ast::ModuleItem::TypeAliasDef(ast) => self.lower_type_alias(ast).map(Into::into),
|
||||
ast::ModuleItem::ConstDef(ast) => Some(self.lower_const(ast).into()),
|
||||
ast::ModuleItem::MacroCall(ast) => self.lower_macro_call(ast).map(Into::into),
|
||||
ast::Item::FnDef(ast) => self.lower_function(ast).map(Into::into),
|
||||
ast::Item::TypeAliasDef(ast) => self.lower_type_alias(ast).map(Into::into),
|
||||
ast::Item::ConstDef(ast) => Some(self.lower_const(ast).into()),
|
||||
ast::Item::MacroCall(ast) => self.lower_macro_call(ast).map(Into::into),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ fn test_inner_items(ra_fixture: &str) {
|
|||
let mut outer_items = FxHashSet::default();
|
||||
let mut worklist = tree.top_level_items().to_vec();
|
||||
while let Some(item) = worklist.pop() {
|
||||
let node: ast::ModuleItem = match item {
|
||||
let node: ast::Item = match item {
|
||||
ModItem::Import(it) => tree.source(&db, InFile::new(file_id, it)).into(),
|
||||
ModItem::ExternCrate(it) => tree.source(&db, InFile::new(file_id, it)).into(),
|
||||
ModItem::Function(it) => tree.source(&db, InFile::new(file_id, it)).into(),
|
||||
|
@ -53,7 +53,7 @@ fn test_inner_items(ra_fixture: &str) {
|
|||
|
||||
// Now descend the root node and check that all `ast::ModuleItem`s are either recorded above, or
|
||||
// registered as inner items.
|
||||
for item in root.descendants().skip(1).filter_map(ast::ModuleItem::cast) {
|
||||
for item in root.descendants().skip(1).filter_map(ast::Item::cast) {
|
||||
if outer_items.contains(&item) {
|
||||
continue;
|
||||
}
|
||||
|
@ -279,7 +279,7 @@ fn simple_inner_items() {
|
|||
|
||||
inner items:
|
||||
|
||||
for AST FileAstId::<ra_syntax::ast::generated::nodes::ModuleItem>(2):
|
||||
for AST FileAstId::<ra_syntax::ast::generated::nodes::Item>(2):
|
||||
Function { name: Name(Text("end")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(1), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::FnDef>(2) }
|
||||
|
||||
"#]],
|
||||
|
@ -412,7 +412,7 @@ fn inner_item_attrs() {
|
|||
|
||||
inner items:
|
||||
|
||||
for AST FileAstId::<ra_syntax::ast::generated::nodes::ModuleItem>(1):
|
||||
for AST FileAstId::<ra_syntax::ast::generated::nodes::Item>(1):
|
||||
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("on_inner"))] }, input: None }]) }]
|
||||
Function { name: Name(Text("inner")), 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::FnDef>(1) }
|
||||
|
||||
|
|
|
@ -521,7 +521,7 @@ impl AsMacroCall for AstIdWithPath<ast::MacroCall> {
|
|||
}
|
||||
}
|
||||
|
||||
impl AsMacroCall for AstIdWithPath<ast::ModuleItem> {
|
||||
impl AsMacroCall for AstIdWithPath<ast::Item> {
|
||||
fn as_call_id(
|
||||
&self,
|
||||
db: &dyn db::DefDatabase,
|
||||
|
|
|
@ -170,7 +170,7 @@ struct MacroDirective {
|
|||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
struct DeriveDirective {
|
||||
module_id: LocalModuleId,
|
||||
ast_id: AstIdWithPath<ast::ModuleItem>,
|
||||
ast_id: AstIdWithPath<ast::Item>,
|
||||
}
|
||||
|
||||
struct DefData<'a> {
|
||||
|
@ -1100,7 +1100,7 @@ impl ModCollector<'_, '_> {
|
|||
res
|
||||
}
|
||||
|
||||
fn collect_derives(&mut self, attrs: &Attrs, ast_id: FileAstId<ast::ModuleItem>) {
|
||||
fn collect_derives(&mut self, attrs: &Attrs, ast_id: FileAstId<ast::Item>) {
|
||||
for derive_subtree in attrs.by_key("derive").tt_values() {
|
||||
// for #[derive(Copy, Clone)], `derive_subtree` is the `(Copy, Clone)` subtree
|
||||
for tt in &derive_subtree.token_trees {
|
||||
|
|
|
@ -73,7 +73,7 @@ impl AstIdMap {
|
|||
// change parent's id. This means that, say, adding a new function to a
|
||||
// trait does not change ids of top-level items, which helps caching.
|
||||
bfs(node, |it| {
|
||||
if let Some(module_item) = ast::ModuleItem::cast(it) {
|
||||
if let Some(module_item) = ast::Item::cast(it) {
|
||||
res.alloc(module_item.syntax());
|
||||
}
|
||||
});
|
||||
|
|
|
@ -276,7 +276,7 @@ mod tests {
|
|||
let file_id = file_pos.file_id;
|
||||
let parsed = db.parse(file_id);
|
||||
let items: Vec<_> =
|
||||
parsed.syntax_node().descendants().filter_map(ast::ModuleItem::cast).collect();
|
||||
parsed.syntax_node().descendants().filter_map(ast::Item::cast).collect();
|
||||
|
||||
let ast_id_map = db.ast_id_map(file_id.into());
|
||||
|
||||
|
|
|
@ -159,7 +159,7 @@ impl HirFileId {
|
|||
}
|
||||
|
||||
/// Indicate it is macro file generated for builtin derive
|
||||
pub fn is_builtin_derive(&self, db: &dyn db::AstDatabase) -> Option<InFile<ast::ModuleItem>> {
|
||||
pub fn is_builtin_derive(&self, db: &dyn db::AstDatabase) -> Option<InFile<ast::Item>> {
|
||||
match self.0 {
|
||||
HirFileIdRepr::FileId(_) => None,
|
||||
HirFileIdRepr::MacroFile(macro_file) => {
|
||||
|
@ -174,7 +174,7 @@ impl HirFileId {
|
|||
MacroDefKind::BuiltInDerive(_) => loc.kind.node(db),
|
||||
_ => return None,
|
||||
};
|
||||
Some(item.with_value(ast::ModuleItem::cast(item.value.clone())?))
|
||||
Some(item.with_value(ast::Item::cast(item.value.clone())?))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -258,7 +258,7 @@ pub struct MacroCallLoc {
|
|||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum MacroCallKind {
|
||||
FnLike(AstId<ast::MacroCall>),
|
||||
Attr(AstId<ast::ModuleItem>, String),
|
||||
Attr(AstId<ast::Item>, String),
|
||||
}
|
||||
|
||||
impl MacroCallKind {
|
||||
|
|
|
@ -28,7 +28,7 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)
|
|||
}
|
||||
};
|
||||
for item in items {
|
||||
if let ast::ModuleItem::FnDef(func) = item {
|
||||
if let ast::Item::FnDef(func) = item {
|
||||
if Some(&func) == me.as_ref() {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -246,12 +246,12 @@ fn has_test_function_or_multiple_test_submodules(module: &ast::Module) -> bool {
|
|||
|
||||
for item in item_list.items() {
|
||||
match item {
|
||||
ast::ModuleItem::FnDef(f) => {
|
||||
ast::Item::FnDef(f) => {
|
||||
if has_test_related_attribute(&f) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
ast::ModuleItem::Module(submodule) => {
|
||||
ast::Item::Module(submodule) => {
|
||||
if has_test_function_or_multiple_test_submodules(&submodule) {
|
||||
number_of_test_submodules += 1;
|
||||
}
|
||||
|
|
|
@ -362,4 +362,4 @@ impl SyntaxKind {
|
|||
}
|
||||
}
|
||||
#[macro_export]
|
||||
macro_rules ! T { [ ; ] => { $ crate :: SyntaxKind :: SEMICOLON } ; [ , ] => { $ crate :: SyntaxKind :: COMMA } ; [ '(' ] => { $ crate :: SyntaxKind :: L_PAREN } ; [ ')' ] => { $ crate :: SyntaxKind :: R_PAREN } ; [ '{' ] => { $ crate :: SyntaxKind :: L_CURLY } ; [ '}' ] => { $ crate :: SyntaxKind :: R_CURLY } ; [ '[' ] => { $ crate :: SyntaxKind :: L_BRACK } ; [ ']' ] => { $ crate :: SyntaxKind :: R_BRACK } ; [ < ] => { $ crate :: SyntaxKind :: L_ANGLE } ; [ > ] => { $ crate :: SyntaxKind :: R_ANGLE } ; [ @ ] => { $ crate :: SyntaxKind :: AT } ; [ # ] => { $ crate :: SyntaxKind :: POUND } ; [ ~ ] => { $ crate :: SyntaxKind :: TILDE } ; [ ? ] => { $ crate :: SyntaxKind :: QUESTION } ; [ $ ] => { $ crate :: SyntaxKind :: DOLLAR } ; [ & ] => { $ crate :: SyntaxKind :: AMP } ; [ | ] => { $ crate :: SyntaxKind :: PIPE } ; [ + ] => { $ crate :: SyntaxKind :: PLUS } ; [ * ] => { $ crate :: SyntaxKind :: STAR } ; [ / ] => { $ crate :: SyntaxKind :: SLASH } ; [ ^ ] => { $ crate :: SyntaxKind :: CARET } ; [ % ] => { $ crate :: SyntaxKind :: PERCENT } ; [ _ ] => { $ crate :: SyntaxKind :: UNDERSCORE } ; [ . ] => { $ crate :: SyntaxKind :: DOT } ; [ .. ] => { $ crate :: SyntaxKind :: DOT2 } ; [ ... ] => { $ crate :: SyntaxKind :: DOT3 } ; [ ..= ] => { $ crate :: SyntaxKind :: DOT2EQ } ; [ : ] => { $ crate :: SyntaxKind :: COLON } ; [ :: ] => { $ crate :: SyntaxKind :: COLON2 } ; [ = ] => { $ crate :: SyntaxKind :: EQ } ; [ == ] => { $ crate :: SyntaxKind :: EQ2 } ; [ => ] => { $ crate :: SyntaxKind :: FAT_ARROW } ; [ ! ] => { $ crate :: SyntaxKind :: BANG } ; [ != ] => { $ crate :: SyntaxKind :: NEQ } ; [ - ] => { $ crate :: SyntaxKind :: MINUS } ; [ -> ] => { $ crate :: SyntaxKind :: THIN_ARROW } ; [ <= ] => { $ crate :: SyntaxKind :: LTEQ } ; [ >= ] => { $ crate :: SyntaxKind :: GTEQ } ; [ += ] => { $ crate :: SyntaxKind :: PLUSEQ } ; [ -= ] => { $ crate :: SyntaxKind :: MINUSEQ } ; [ |= ] => { $ crate :: SyntaxKind :: PIPEEQ } ; [ &= ] => { $ crate :: SyntaxKind :: AMPEQ } ; [ ^= ] => { $ crate :: SyntaxKind :: CARETEQ } ; [ /= ] => { $ crate :: SyntaxKind :: SLASHEQ } ; [ *= ] => { $ crate :: SyntaxKind :: STAREQ } ; [ %= ] => { $ crate :: SyntaxKind :: PERCENTEQ } ; [ && ] => { $ crate :: SyntaxKind :: AMP2 } ; [ || ] => { $ crate :: SyntaxKind :: PIPE2 } ; [ << ] => { $ crate :: SyntaxKind :: SHL } ; [ >> ] => { $ crate :: SyntaxKind :: SHR } ; [ <<= ] => { $ crate :: SyntaxKind :: SHLEQ } ; [ >>= ] => { $ crate :: SyntaxKind :: SHREQ } ; [ as ] => { $ crate :: SyntaxKind :: AS_KW } ; [ async ] => { $ crate :: SyntaxKind :: ASYNC_KW } ; [ await ] => { $ crate :: SyntaxKind :: AWAIT_KW } ; [ box ] => { $ crate :: SyntaxKind :: BOX_KW } ; [ break ] => { $ crate :: SyntaxKind :: BREAK_KW } ; [ const ] => { $ crate :: SyntaxKind :: CONST_KW } ; [ continue ] => { $ crate :: SyntaxKind :: CONTINUE_KW } ; [ crate ] => { $ crate :: SyntaxKind :: CRATE_KW } ; [ dyn ] => { $ crate :: SyntaxKind :: DYN_KW } ; [ else ] => { $ crate :: SyntaxKind :: ELSE_KW } ; [ enum ] => { $ crate :: SyntaxKind :: ENUM_KW } ; [ extern ] => { $ crate :: SyntaxKind :: EXTERN_KW } ; [ false ] => { $ crate :: SyntaxKind :: FALSE_KW } ; [ fn ] => { $ crate :: SyntaxKind :: FN_KW } ; [ for ] => { $ crate :: SyntaxKind :: FOR_KW } ; [ if ] => { $ crate :: SyntaxKind :: IF_KW } ; [ impl ] => { $ crate :: SyntaxKind :: IMPL_KW } ; [ in ] => { $ crate :: SyntaxKind :: IN_KW } ; [ let ] => { $ crate :: SyntaxKind :: LET_KW } ; [ loop ] => { $ crate :: SyntaxKind :: LOOP_KW } ; [ macro ] => { $ crate :: SyntaxKind :: MACRO_KW } ; [ match ] => { $ crate :: SyntaxKind :: MATCH_KW } ; [ mod ] => { $ crate :: SyntaxKind :: MOD_KW } ; [ move ] => { $ crate :: SyntaxKind :: MOVE_KW } ; [ mut ] => { $ crate :: SyntaxKind :: MUT_KW } ; [ pub ] => { $ crate :: SyntaxKind :: PUB_KW } ; [ ref ] => { $ crate :: SyntaxKind :: REF_KW } ; [ return ] => { $ crate :: SyntaxKind :: RETURN_KW } ; [ self ] => { $ crate :: SyntaxKind :: SELF_KW } ; [ static ] => { $ crate :: SyntaxKind :: STATIC_KW } ; [ struct ] => { $ crate :: SyntaxKind :: STRUCT_KW } ; [ super ] => { $ crate :: SyntaxKind :: SUPER_KW } ; [ trait ] => { $ crate :: SyntaxKind :: TRAIT_KW } ; [ true ] => { $ crate :: SyntaxKind :: TRUE_KW } ; [ try ] => { $ crate :: SyntaxKind :: TRY_KW } ; [ type ] => { $ crate :: SyntaxKind :: TYPE_KW } ; [ unsafe ] => { $ crate :: SyntaxKind :: UNSAFE_KW } ; [ use ] => { $ crate :: SyntaxKind :: USE_KW } ; [ where ] => { $ crate :: SyntaxKind :: WHERE_KW } ; [ while ] => { $ crate :: SyntaxKind :: WHILE_KW } ; [ auto ] => { $ crate :: SyntaxKind :: AUTO_KW } ; [ default ] => { $ crate :: SyntaxKind :: DEFAULT_KW } ; [ existential ] => { $ crate :: SyntaxKind :: EXISTENTIAL_KW } ; [ union ] => { $ crate :: SyntaxKind :: UNION_KW } ; [ raw ] => { $ crate :: SyntaxKind :: RAW_KW } ; [ lifetime ] => { $ crate :: SyntaxKind :: LIFETIME } ; [ ident ] => { $ crate :: SyntaxKind :: IDENT } ; }
|
||||
macro_rules ! T { [ ; ] => { $ crate :: SyntaxKind :: SEMICOLON } ; [ , ] => { $ crate :: SyntaxKind :: COMMA } ; [ '(' ] => { $ crate :: SyntaxKind :: L_PAREN } ; [ ')' ] => { $ crate :: SyntaxKind :: R_PAREN } ; [ '{' ] => { $ crate :: SyntaxKind :: L_CURLY } ; [ '}' ] => { $ crate :: SyntaxKind :: R_CURLY } ; [ '[' ] => { $ crate :: SyntaxKind :: L_BRACK } ; [ ']' ] => { $ crate :: SyntaxKind :: R_BRACK } ; [ < ] => { $ crate :: SyntaxKind :: L_ANGLE } ; [ > ] => { $ crate :: SyntaxKind :: R_ANGLE } ; [ @ ] => { $ crate :: SyntaxKind :: AT } ; [ # ] => { $ crate :: SyntaxKind :: POUND } ; [ ~ ] => { $ crate :: SyntaxKind :: TILDE } ; [ ? ] => { $ crate :: SyntaxKind :: QUESTION } ; [ $ ] => { $ crate :: SyntaxKind :: DOLLAR } ; [ & ] => { $ crate :: SyntaxKind :: AMP } ; [ | ] => { $ crate :: SyntaxKind :: PIPE } ; [ + ] => { $ crate :: SyntaxKind :: PLUS } ; [ * ] => { $ crate :: SyntaxKind :: STAR } ; [ / ] => { $ crate :: SyntaxKind :: SLASH } ; [ ^ ] => { $ crate :: SyntaxKind :: CARET } ; [ % ] => { $ crate :: SyntaxKind :: PERCENT } ; [ _ ] => { $ crate :: SyntaxKind :: UNDERSCORE } ; [ . ] => { $ crate :: SyntaxKind :: DOT } ; [ .. ] => { $ crate :: SyntaxKind :: DOT2 } ; [ ... ] => { $ crate :: SyntaxKind :: DOT3 } ; [ ..= ] => { $ crate :: SyntaxKind :: DOT2EQ } ; [ : ] => { $ crate :: SyntaxKind :: COLON } ; [ :: ] => { $ crate :: SyntaxKind :: COLON2 } ; [ = ] => { $ crate :: SyntaxKind :: EQ } ; [ == ] => { $ crate :: SyntaxKind :: EQ2 } ; [ => ] => { $ crate :: SyntaxKind :: FAT_ARROW } ; [ ! ] => { $ crate :: SyntaxKind :: BANG } ; [ != ] => { $ crate :: SyntaxKind :: NEQ } ; [ - ] => { $ crate :: SyntaxKind :: MINUS } ; [ -> ] => { $ crate :: SyntaxKind :: THIN_ARROW } ; [ <= ] => { $ crate :: SyntaxKind :: LTEQ } ; [ >= ] => { $ crate :: SyntaxKind :: GTEQ } ; [ += ] => { $ crate :: SyntaxKind :: PLUSEQ } ; [ -= ] => { $ crate :: SyntaxKind :: MINUSEQ } ; [ |= ] => { $ crate :: SyntaxKind :: PIPEEQ } ; [ &= ] => { $ crate :: SyntaxKind :: AMPEQ } ; [ ^= ] => { $ crate :: SyntaxKind :: CARETEQ } ; [ /= ] => { $ crate :: SyntaxKind :: SLASHEQ } ; [ *= ] => { $ crate :: SyntaxKind :: STAREQ } ; [ %= ] => { $ crate :: SyntaxKind :: PERCENTEQ } ; [ && ] => { $ crate :: SyntaxKind :: AMP2 } ; [ || ] => { $ crate :: SyntaxKind :: PIPE2 } ; [ << ] => { $ crate :: SyntaxKind :: SHL } ; [ >> ] => { $ crate :: SyntaxKind :: SHR } ; [ <<= ] => { $ crate :: SyntaxKind :: SHLEQ } ; [ >>= ] => { $ crate :: SyntaxKind :: SHREQ } ; [ as ] => { $ crate :: SyntaxKind :: AS_KW } ; [ async ] => { $ crate :: SyntaxKind :: ASYNC_KW } ; [ await ] => { $ crate :: SyntaxKind :: AWAIT_KW } ; [ box ] => { $ crate :: SyntaxKind :: BOX_KW } ; [ break ] => { $ crate :: SyntaxKind :: BREAK_KW } ; [ const ] => { $ crate :: SyntaxKind :: CONST_KW } ; [ continue ] => { $ crate :: SyntaxKind :: CONTINUE_KW } ; [ crate ] => { $ crate :: SyntaxKind :: CRATE_KW } ; [ dyn ] => { $ crate :: SyntaxKind :: DYN_KW } ; [ else ] => { $ crate :: SyntaxKind :: ELSE_KW } ; [ enum ] => { $ crate :: SyntaxKind :: ENUM_KW } ; [ extern ] => { $ crate :: SyntaxKind :: EXTERN_KW } ; [ false ] => { $ crate :: SyntaxKind :: FALSE_KW } ; [ fn ] => { $ crate :: SyntaxKind :: FN_KW } ; [ for ] => { $ crate :: SyntaxKind :: FOR_KW } ; [ if ] => { $ crate :: SyntaxKind :: IF_KW } ; [ impl ] => { $ crate :: SyntaxKind :: IMPL_KW } ; [ in ] => { $ crate :: SyntaxKind :: IN_KW } ; [ let ] => { $ crate :: SyntaxKind :: LET_KW } ; [ loop ] => { $ crate :: SyntaxKind :: LOOP_KW } ; [ macro ] => { $ crate :: SyntaxKind :: MACRO_KW } ; [ match ] => { $ crate :: SyntaxKind :: MATCH_KW } ; [ mod ] => { $ crate :: SyntaxKind :: MOD_KW } ; [ move ] => { $ crate :: SyntaxKind :: MOVE_KW } ; [ mut ] => { $ crate :: SyntaxKind :: MUT_KW } ; [ pub ] => { $ crate :: SyntaxKind :: PUB_KW } ; [ ref ] => { $ crate :: SyntaxKind :: REF_KW } ; [ return ] => { $ crate :: SyntaxKind :: RETURN_KW } ; [ self ] => { $ crate :: SyntaxKind :: SELF_KW } ; [ static ] => { $ crate :: SyntaxKind :: STATIC_KW } ; [ struct ] => { $ crate :: SyntaxKind :: STRUCT_KW } ; [ super ] => { $ crate :: SyntaxKind :: SUPER_KW } ; [ trait ] => { $ crate :: SyntaxKind :: TRAIT_KW } ; [ true ] => { $ crate :: SyntaxKind :: TRUE_KW } ; [ try ] => { $ crate :: SyntaxKind :: TRY_KW } ; [ type ] => { $ crate :: SyntaxKind :: TYPE_KW } ; [ unsafe ] => { $ crate :: SyntaxKind :: UNSAFE_KW } ; [ use ] => { $ crate :: SyntaxKind :: USE_KW } ; [ where ] => { $ crate :: SyntaxKind :: WHERE_KW } ; [ while ] => { $ crate :: SyntaxKind :: WHILE_KW } ; [ auto ] => { $ crate :: SyntaxKind :: AUTO_KW } ; [ default ] => { $ crate :: SyntaxKind :: DEFAULT_KW } ; [ existential ] => { $ crate :: SyntaxKind :: EXISTENTIAL_KW } ; [ union ] => { $ crate :: SyntaxKind :: UNION_KW } ; [ raw ] => { $ crate :: SyntaxKind :: RAW_KW } ; [ lifetime ] => { $ crate :: SyntaxKind :: LIFETIME } ; [ ident ] => { $ crate :: SyntaxKind :: IDENT } ; [ shebang ] => { $ crate :: SyntaxKind :: SHEBANG } ; }
|
||||
|
|
|
@ -71,10 +71,7 @@ impl ParsedRule {
|
|||
};
|
||||
builder.try_add(ast::Expr::parse(&raw_pattern), raw_template.map(ast::Expr::parse));
|
||||
builder.try_add(ast::TypeRef::parse(&raw_pattern), raw_template.map(ast::TypeRef::parse));
|
||||
builder.try_add(
|
||||
ast::ModuleItem::parse(&raw_pattern),
|
||||
raw_template.map(ast::ModuleItem::parse),
|
||||
);
|
||||
builder.try_add(ast::Item::parse(&raw_pattern), raw_template.map(ast::Item::parse));
|
||||
builder.try_add(ast::Path::parse(&raw_pattern), raw_template.map(ast::Path::parse));
|
||||
builder.try_add(ast::Pat::parse(&raw_pattern), raw_template.map(ast::Pat::parse));
|
||||
builder.build()
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -44,7 +44,7 @@ pub trait ArgListOwner: AstNode {
|
|||
}
|
||||
|
||||
pub trait ModuleItemOwner: AstNode {
|
||||
fn items(&self) -> AstChildren<ast::ModuleItem> {
|
||||
fn items(&self) -> AstChildren<ast::Item> {
|
||||
support::children(self.syntax())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -187,7 +187,7 @@ impl ast::Expr {
|
|||
}
|
||||
}
|
||||
|
||||
impl ast::ModuleItem {
|
||||
impl ast::Item {
|
||||
/// Returns `text`, parsed as an item, but only if it has no errors.
|
||||
pub fn parse(text: &str) -> Result<Self, ()> {
|
||||
parsing::parse_text_fragment(text, ra_parser::FragmentKind::Item)
|
||||
|
@ -255,7 +255,7 @@ fn api_walkthrough() {
|
|||
let mut func = None;
|
||||
for item in file.items() {
|
||||
match item {
|
||||
ast::ModuleItem::FnDef(f) => func = Some(f),
|
||||
ast::Item::FnDef(f) => func = Some(f),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ fn item_parser_tests() {
|
|||
fragment_parser_dir_test(
|
||||
&["parser/fragments/item/ok"],
|
||||
&["parser/fragments/item/err"],
|
||||
crate::ast::ModuleItem::parse,
|
||||
crate::ast::Item::parse,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -374,6 +374,7 @@ fn generate_syntax_kinds(grammar: KindsSrc<'_>) -> Result<String> {
|
|||
#([#all_keywords_idents] => { $crate::SyntaxKind::#all_keywords };)*
|
||||
[lifetime] => { $crate::SyntaxKind::LIFETIME };
|
||||
[ident] => { $crate::SyntaxKind::IDENT };
|
||||
[shebang] => { $crate::SyntaxKind::SHEBANG };
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -595,7 +596,6 @@ fn lower_rule(acc: &mut Vec<Field>, grammar: &Grammar, rule: &Rule) {
|
|||
}
|
||||
|
||||
fn deduplicate_fields(ast: &mut AstSrc) {
|
||||
eprintln!();
|
||||
for node in &mut ast.nodes {
|
||||
let mut i = 0;
|
||||
'outer: while i < node.fields.len() {
|
||||
|
|
|
@ -1,6 +1,23 @@
|
|||
SourceFile =
|
||||
'shebang'?
|
||||
Attr*
|
||||
items:ModuleItem*
|
||||
Item*
|
||||
|
||||
Item =
|
||||
ConstDef
|
||||
| EnumDef
|
||||
| ExternBlock
|
||||
| ExternCrateItem
|
||||
| FnDef
|
||||
| ImplDef
|
||||
| MacroCall
|
||||
| Module
|
||||
| StaticDef
|
||||
| StructDef
|
||||
| TraitDef
|
||||
| TypeAliasDef
|
||||
| UnionDef
|
||||
| UseItem
|
||||
|
||||
FnDef =
|
||||
Attr* Visibility? Abi? 'const' 'default' 'async' 'unsafe' 'fn' Name TypeParamList?
|
||||
|
@ -59,7 +76,7 @@ Module =
|
|||
ItemList =
|
||||
'{'
|
||||
AssocItem*
|
||||
items:ModuleItem*
|
||||
Item*
|
||||
'}'
|
||||
|
||||
ConstDef =
|
||||
|
@ -168,7 +185,7 @@ Label =
|
|||
BlockExpr =
|
||||
Attr* Label
|
||||
'{'
|
||||
items:ModuleItem*
|
||||
Item*
|
||||
statements:Stmt*
|
||||
Expr?
|
||||
'}'
|
||||
|
@ -316,7 +333,7 @@ TokenTree =
|
|||
'(' ')' | '{' '}' | '[' ']'
|
||||
|
||||
MacroItems =
|
||||
items:ModuleItem*
|
||||
Item*
|
||||
|
||||
MacroStmts =
|
||||
statements:Stmt*
|
||||
|
@ -454,22 +471,6 @@ AssocItem =
|
|||
ExternItem =
|
||||
FnDef | StaticDef
|
||||
|
||||
ModuleItem =
|
||||
StructDef
|
||||
| UnionDef
|
||||
| EnumDef
|
||||
| FnDef
|
||||
| TraitDef
|
||||
| TypeAliasDef
|
||||
| ImplDef
|
||||
| UseItem
|
||||
| ExternCrateItem
|
||||
| ConstDef
|
||||
| StaticDef
|
||||
| Module
|
||||
| MacroCall
|
||||
| ExternBlock
|
||||
|
||||
AttrInput =
|
||||
Literal
|
||||
| TokenTree
|
||||
|
|
Loading…
Reference in a new issue