Skip to content

Commit 51b18ee

Browse files
bors[bot]matklad
andauthored
Merge #5587
5587: Finish use grammar r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 9042009 + 02cac96 commit 51b18ee

40 files changed

+222
-184
lines changed

crates/ra_assists/src/handlers/auto_import.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl AutoImportAssets {
9292

9393
fn for_regular_path(path_under_caret: ast::Path, ctx: &AssistContext) -> Option<Self> {
9494
let syntax_under_caret = path_under_caret.syntax().to_owned();
95-
if syntax_under_caret.ancestors().find_map(ast::UseItem::cast).is_some() {
95+
if syntax_under_caret.ancestors().find_map(ast::Use::cast).is_some() {
9696
return None;
9797
}
9898

crates/ra_assists/src/handlers/merge_imports.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub(crate) fn merge_imports(acc: &mut Assists, ctx: &AssistContext) -> Option<()
2828
let mut rewriter = SyntaxRewriter::default();
2929
let mut offset = ctx.offset();
3030

31-
if let Some(use_item) = tree.syntax().parent().and_then(ast::UseItem::cast) {
31+
if let Some(use_item) = tree.syntax().parent().and_then(ast::Use::cast) {
3232
let (merged, to_delete) = next_prev()
3333
.filter_map(|dir| neighbor(&use_item, dir))
3434
.filter_map(|it| Some((it.clone(), it.use_tree()?)))

crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub(crate) fn replace_qualified_name_with_use(
2525
) -> Option<()> {
2626
let path: ast::Path = ctx.find_node_at_offset()?;
2727
// We don't want to mess with use statements
28-
if path.syntax().ancestors().find_map(ast::UseItem::cast).is_some() {
28+
if path.syntax().ancestors().find_map(ast::Use::cast).is_some() {
2929
return None;
3030
}
3131

@@ -85,7 +85,7 @@ fn shorten_paths(rewriter: &mut SyntaxRewriter<'static>, node: SyntaxNode, path:
8585
match child {
8686
// Don't modify `use` items, as this can break the `use` item when injecting a new
8787
// import into the use tree.
88-
ast::UseItem(_it) => continue,
88+
ast::Use(_it) => continue,
8989
// Don't descend into submodules, they don't have the same `use` items in scope.
9090
ast::Module(_it) => continue,
9191

crates/ra_assists/src/utils/insert_use.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ fn walk_use_tree_for_best_action(
225225
current_use_tree
226226
.syntax()
227227
.ancestors()
228-
.find_map(ast::UseItem::cast)
228+
.find_map(ast::Use::cast)
229229
.map(|it| it.syntax().clone()),
230230
true,
231231
);
@@ -254,7 +254,7 @@ fn walk_use_tree_for_best_action(
254254
current_use_tree
255255
.syntax()
256256
.ancestors()
257-
.find_map(ast::UseItem::cast)
257+
.find_map(ast::Use::cast)
258258
.map(|it| it.syntax().clone()),
259259
true,
260260
),
@@ -304,7 +304,7 @@ fn walk_use_tree_for_best_action(
304304
current_use_tree
305305
.syntax()
306306
.ancestors()
307-
.find_map(ast::UseItem::cast)
307+
.find_map(ast::Use::cast)
308308
.map(|it| it.syntax().clone()),
309309
true,
310310
);
@@ -377,7 +377,7 @@ fn best_action_for_target(
377377
let mut storage = Vec::with_capacity(16); // this should be the only allocation
378378
let best_action = container
379379
.children()
380-
.filter_map(ast::UseItem::cast)
380+
.filter_map(ast::Use::cast)
381381
.filter_map(|it| it.use_tree())
382382
.map(|u| walk_use_tree_for_best_action(&mut storage, None, u, target))
383383
.fold(None, |best, a| match best {

crates/ra_hir_def/src/body/lower.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ impl ExprCollector<'_> {
670670
}
671671
ast::Item::ExternBlock(_) => return None, // FIXME: collect from extern blocks
672672
ast::Item::ImplDef(_)
673-
| ast::Item::UseItem(_)
673+
| ast::Item::Use(_)
674674
| ast::Item::ExternCrate(_)
675675
| ast::Item::Module(_)
676676
| ast::Item::MacroCall(_) => return None,

crates/ra_hir_def/src/item_tree.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ macro_rules! mod_items {
411411
}
412412

413413
mod_items! {
414-
Import in imports -> ast::UseItem,
414+
Import in imports -> ast::Use,
415415
ExternCrate in extern_crates -> ast::ExternCrate,
416416
Function in functions -> ast::FnDef,
417417
Struct in structs -> ast::StructDef,
@@ -482,7 +482,7 @@ pub struct Import {
482482
pub is_prelude: bool,
483483
/// AST ID of the `use` or `extern crate` item this import was derived from. Note that many
484484
/// `Import`s can map to the same `use` item.
485-
pub ast_id: FileAstId<ast::UseItem>,
485+
pub ast_id: FileAstId<ast::Use>,
486486
}
487487

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

crates/ra_hir_def/src/item_tree/lower.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl Ctx {
9595
ast::Item::TraitDef(_) | ast::Item::ImplDef(_) | ast::Item::ExternBlock(_) => {}
9696

9797
// These don't have inner items.
98-
ast::Item::Module(_) | ast::Item::ExternCrate(_) | ast::Item::UseItem(_) => {}
98+
ast::Item::Module(_) | ast::Item::ExternCrate(_) | ast::Item::Use(_) => {}
9999
};
100100

101101
let attrs = Attrs::new(item, &self.hygiene);
@@ -110,7 +110,7 @@ impl Ctx {
110110
ast::Item::Module(ast) => self.lower_module(ast).map(Into::into),
111111
ast::Item::TraitDef(ast) => self.lower_trait(ast).map(Into::into),
112112
ast::Item::ImplDef(ast) => self.lower_impl(ast).map(Into::into),
113-
ast::Item::UseItem(ast) => Some(ModItems(
113+
ast::Item::Use(ast) => Some(ModItems(
114114
self.lower_use(ast).into_iter().map(Into::into).collect::<SmallVec<_>>(),
115115
)),
116116
ast::Item::ExternCrate(ast) => self.lower_extern_crate(ast).map(Into::into),
@@ -469,7 +469,7 @@ impl Ctx {
469469
Some(id(self.data().impls.alloc(res)))
470470
}
471471

472-
fn lower_use(&mut self, use_item: &ast::UseItem) -> Vec<FileItemTreeId<Import>> {
472+
fn lower_use(&mut self, use_item: &ast::Use) -> Vec<FileItemTreeId<Import>> {
473473
// FIXME: cfg_attr
474474
let is_prelude = use_item.has_atom_attr("prelude_import");
475475
let visibility = self.lower_visibility(use_item);

crates/ra_hir_def/src/item_tree/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,9 @@ fn smoke() {
228228
229229
top-level items:
230230
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_on_use"))] }, input: None }]) }]
231-
Import { path: ModPath { kind: Plain, segments: [Name(Text("a"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_glob: false, is_prelude: false, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::UseItem>(0) }
231+
Import { path: ModPath { kind: Plain, segments: [Name(Text("a"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_glob: false, is_prelude: false, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Use>(0) }
232232
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_on_use"))] }, input: None }]) }]
233-
Import { path: ModPath { kind: Plain, segments: [Name(Text("b"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_glob: true, is_prelude: false, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::UseItem>(0) }
233+
Import { path: ModPath { kind: Plain, segments: [Name(Text("b"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_glob: true, is_prelude: false, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Use>(0) }
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 }]) }]

crates/ra_hir_def/src/path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl ModPath {
6767

6868
/// Calls `cb` with all paths, represented by this use item.
6969
pub(crate) fn expand_use_item(
70-
item_src: InFile<ast::UseItem>,
70+
item_src: InFile<ast::Use>,
7171
hygiene: &Hygiene,
7272
mut cb: impl FnMut(ModPath, &ast::UseTree, /* is_glob */ bool, Option<ImportAlias>),
7373
) {

crates/ra_ide/src/completion/completion_context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub(crate) struct CompletionContext<'a> {
3636
pub(super) expected_type: Option<Type>,
3737
pub(super) name_ref_syntax: Option<ast::NameRef>,
3838
pub(super) function_syntax: Option<ast::FnDef>,
39-
pub(super) use_item_syntax: Option<ast::UseItem>,
39+
pub(super) use_item_syntax: Option<ast::Use>,
4040
pub(super) record_lit_syntax: Option<ast::RecordLit>,
4141
pub(super) record_pat_syntax: Option<ast::RecordPat>,
4242
pub(super) record_field_syntax: Option<ast::RecordField>,
@@ -343,7 +343,7 @@ impl<'a> CompletionContext<'a> {
343343
}
344344

345345
self.use_item_syntax =
346-
self.sema.ancestors_with_macros(self.token.parent()).find_map(ast::UseItem::cast);
346+
self.sema.ancestors_with_macros(self.token.parent()).find_map(ast::Use::cast);
347347

348348
self.function_syntax = self
349349
.sema

crates/ra_ide/src/folding_ranges.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec<Fold> {
5858
}
5959
NodeOrToken::Node(node) => {
6060
// Fold groups of imports
61-
if node.kind() == USE_ITEM && !visited_imports.contains(&node) {
61+
if node.kind() == USE && !visited_imports.contains(&node) {
6262
if let Some(range) = contiguous_range_for_group(&node, &mut visited_imports) {
6363
res.push(Fold { range, kind: FoldKind::Imports })
6464
}
@@ -83,7 +83,7 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec<Fold> {
8383
fn fold_kind(kind: SyntaxKind) -> Option<FoldKind> {
8484
match kind {
8585
COMMENT => Some(FoldKind::Comment),
86-
USE_ITEM => Some(FoldKind::Imports),
86+
USE => Some(FoldKind::Imports),
8787
ARG_LIST | PARAM_LIST => Some(FoldKind::ArgList),
8888
RECORD_FIELD_DEF_LIST
8989
| RECORD_FIELD_PAT_LIST

crates/ra_parser/src/grammar/items/use_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub(super) fn use_item(p: &mut Parser, m: Marker) {
77
p.bump(T![use]);
88
use_tree(p, true);
99
p.expect(T![;]);
10-
m.complete(p, USE_ITEM);
10+
m.complete(p, USE);
1111
}
1212

1313
/// Parse a use 'tree', such as `some::path` in `use some::path;`

crates/ra_parser/src/syntax_kind/generated.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pub enum SyntaxKind {
130130
RET_TYPE,
131131
EXTERN_CRATE,
132132
MODULE,
133-
USE_ITEM,
133+
USE,
134134
STATIC_DEF,
135135
CONST_DEF,
136136
TRAIT_DEF,

crates/ra_ssr/src/search.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ fn is_search_permitted(node: &SyntaxNode) -> bool {
237237
// and the code is `use foo::{baz, bar}`, we'll match `bar`, since it resolves to `foo::bar`.
238238
// However we'll then replace just the part we matched `bar`. We probably need to instead remove
239239
// `bar` and insert a new use declaration.
240-
node.kind() != SyntaxKind::USE_ITEM
240+
node.kind() != SyntaxKind::USE
241241
}
242242

243243
impl UsageCache {

crates/ra_syntax/src/ast/edit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,9 @@ impl ast::PathSegment {
262262
}
263263
}
264264

265-
impl ast::UseItem {
265+
impl ast::Use {
266266
#[must_use]
267-
pub fn with_use_tree(&self, use_tree: ast::UseTree) -> ast::UseItem {
267+
pub fn with_use_tree(&self, use_tree: ast::UseTree) -> ast::Use {
268268
if let Some(old) = self.use_tree() {
269269
return self.replace_descendant(old, use_tree);
270270
}

0 commit comments

Comments
 (0)