Skip to content

Commit ec7d2f6

Browse files
bors[bot]Sergey Parilin
andcommitted
Merge #1278
1278: Apply T! macro where posible r=matklad a=pasa apply T! macro implemented in #1248 Co-authored-by: Sergey Parilin <[email protected]>
2 parents 64ab5ab + 993abed commit ec7d2f6

40 files changed

+622
-626
lines changed

crates/ra_assists/src/add_explicit_type.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use hir::{
33
db::HirDatabase,
44
};
55
use ra_syntax::{
6-
SyntaxKind,
6+
T,
77
ast::{LetStmt, PatKind, NameOwner, AstNode}
88
};
99

@@ -24,7 +24,7 @@ pub(crate) fn add_explicit_type(mut ctx: AssistCtx<impl HirDatabase>) -> Option<
2424
let name = pat.name()?;
2525
let name_range = name.syntax().range();
2626
// Assist not applicable if the type has already been specified
27-
if stmt.syntax().children_with_tokens().any(|child| child.kind() == SyntaxKind::COLON) {
27+
if stmt.syntax().children_with_tokens().any(|child| child.kind() == T![:]) {
2828
return None;
2929
}
3030
// Infer type

crates/ra_assists/src/ast_editor.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::{iter, ops::RangeInclusive};
22

33
use arrayvec::ArrayVec;
44
use ra_text_edit::TextEditBuilder;
5-
use ra_syntax::{AstNode, TreeArc, ast, SyntaxKind::*, SyntaxElement, SourceFile, InsertPosition, Direction};
5+
use ra_syntax::{AstNode, TreeArc, ast, SyntaxKind::*, SyntaxElement, SourceFile, InsertPosition, Direction, T};
66
use ra_fmt::leading_indent;
77
use hir::Name;
88

@@ -49,7 +49,7 @@ impl<N: AstNode> AstEditor<N> {
4949

5050
fn do_make_multiline(&mut self) {
5151
let l_curly =
52-
match self.ast().syntax().children_with_tokens().find(|it| it.kind() == L_CURLY) {
52+
match self.ast().syntax().children_with_tokens().find(|it| it.kind() == T!['{']) {
5353
Some(it) => it,
5454
None => return,
5555
};
@@ -124,7 +124,7 @@ impl AstEditor<ast::NamedFieldList> {
124124
if let Some(comma) = $anchor
125125
.syntax()
126126
.siblings_with_tokens(Direction::Next)
127-
.find(|it| it.kind() == COMMA)
127+
.find(|it| it.kind() == T![,])
128128
{
129129
InsertPosition::After(comma)
130130
} else {
@@ -154,7 +154,7 @@ impl AstEditor<ast::NamedFieldList> {
154154
}
155155

156156
fn l_curly(&self) -> Option<SyntaxElement> {
157-
self.ast().syntax().children_with_tokens().find(|it| it.kind() == L_CURLY)
157+
self.ast().syntax().children_with_tokens().find(|it| it.kind() == T!['{'])
158158
}
159159
}
160160

@@ -188,7 +188,7 @@ impl AstEditor<ast::ItemList> {
188188
}
189189

190190
fn l_curly(&self) -> Option<SyntaxElement> {
191-
self.ast().syntax().children_with_tokens().find(|it| it.kind() == L_CURLY)
191+
self.ast().syntax().children_with_tokens().find(|it| it.kind() == T!['{'])
192192
}
193193
}
194194

@@ -290,7 +290,7 @@ fn ast_node_from_file_text<N: AstNode>(text: &str) -> TreeArc<N> {
290290

291291
mod tokens {
292292
use once_cell::sync::Lazy;
293-
use ra_syntax::{AstNode, SourceFile, TreeArc, SyntaxToken, SyntaxKind::*};
293+
use ra_syntax::{AstNode, SourceFile, TreeArc, SyntaxToken, SyntaxKind::*, T};
294294

295295
static SOURCE_FILE: Lazy<TreeArc<SourceFile>> = Lazy::new(|| SourceFile::parse(",\n; ;"));
296296

@@ -299,7 +299,7 @@ mod tokens {
299299
.syntax()
300300
.descendants_with_tokens()
301301
.filter_map(|it| it.as_token())
302-
.find(|it| it.kind() == COMMA)
302+
.find(|it| it.kind() == T![,])
303303
.unwrap()
304304
}
305305

crates/ra_assists/src/auto_import.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ use ra_text_edit::TextEditBuilder;
22
use hir::{ self, db::HirDatabase};
33

44
use ra_syntax::{
5+
T,
56
ast::{ self, NameOwner }, AstNode, SyntaxNode, Direction, TextRange, SmolStr,
6-
SyntaxKind::{ PATH, PATH_SEGMENT, COLONCOLON, COMMA }
7+
SyntaxKind::{ PATH, PATH_SEGMENT }
78
};
89
use crate::{
910
AssistId,
@@ -23,7 +24,7 @@ fn collect_path_segments_raw<'a>(
2324
children.next().map(|n| (n, n.kind())),
2425
);
2526
match (first, second, third) {
26-
(Some((subpath, PATH)), Some((_, COLONCOLON)), Some((segment, PATH_SEGMENT))) => {
27+
(Some((subpath, PATH)), Some((_, T![::])), Some((segment, PATH_SEGMENT))) => {
2728
path = ast::Path::cast(subpath.as_node()?)?;
2829
segments.push(ast::PathSegment::cast(segment.as_node()?)?);
2930
}
@@ -421,7 +422,7 @@ fn make_assist_add_in_tree_list(
421422
let last = tree_list.use_trees().last();
422423
if let Some(last) = last {
423424
let mut buf = String::new();
424-
let comma = last.syntax().siblings(Direction::Next).find(|n| n.kind() == COMMA);
425+
let comma = last.syntax().siblings(Direction::Next).find(|n| n.kind() == T![,]);
425426
let offset = if let Some(comma) = comma {
426427
comma.range().end()
427428
} else {

crates/ra_assists/src/change_visibility.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use hir::db::HirDatabase;
22
use ra_syntax::{
3+
T,
34
AstNode, SyntaxNode, TextUnit,
45
ast::{self, VisibilityOwner, NameOwner},
5-
SyntaxKind::{VISIBILITY, FN_KW, MOD_KW, STRUCT_KW, ENUM_KW, TRAIT_KW, FN_DEF, MODULE, STRUCT_DEF, ENUM_DEF, TRAIT_DEF, IDENT, WHITESPACE, COMMENT, ATTR},
6+
SyntaxKind::{VISIBILITY, FN_DEF, MODULE, STRUCT_DEF, ENUM_DEF, TRAIT_DEF, IDENT, WHITESPACE, COMMENT, ATTR},
67
};
78

89
use crate::{AssistCtx, Assist, AssistId};
@@ -16,7 +17,7 @@ pub(crate) fn change_visibility(ctx: AssistCtx<impl HirDatabase>) -> Option<Assi
1617

1718
fn add_vis(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
1819
let item_keyword = ctx.token_at_offset().find(|leaf| match leaf.kind() {
19-
FN_KW | MOD_KW | STRUCT_KW | ENUM_KW | TRAIT_KW => true,
20+
T![fn] | T![mod] | T![struct] | T![enum] | T![trait] => true,
2021
_ => false,
2122
});
2223

crates/ra_assists/src/flip_comma.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use hir::db::HirDatabase;
22
use ra_syntax::{
3+
T,
34
Direction,
4-
SyntaxKind::COMMA,
55
algo::non_trivia_sibling,
66
};
77

88
use crate::{AssistCtx, Assist, AssistId};
99

1010
pub(crate) fn flip_comma(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
11-
let comma = ctx.token_at_offset().find(|leaf| leaf.kind() == COMMA)?;
11+
let comma = ctx.token_at_offset().find(|leaf| leaf.kind() == T![,])?;
1212
let prev = non_trivia_sibling(comma.into(), Direction::Prev)?;
1313
let next = non_trivia_sibling(comma.into(), Direction::Next)?;
1414
ctx.add_action(AssistId("flip_comma"), "flip comma", |edit| {

crates/ra_assists/src/remove_dbg.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ use hir::db::HirDatabase;
22
use ra_syntax::{
33
ast::{self, AstNode},
44
TextUnit,
5-
SyntaxKind::{
6-
L_PAREN, R_PAREN, L_CURLY, R_CURLY, L_BRACK, R_BRACK, EXCL
7-
},
5+
T
86
};
97
use crate::{AssistCtx, Assist, AssistId};
108

@@ -64,7 +62,7 @@ fn is_valid_macrocall(macro_call: &ast::MacroCall, macro_name: &str) -> Option<b
6462
// Make sure it is actually a dbg-macro call, dbg followed by !
6563
let excl = path.syntax().next_sibling_or_token()?;
6664

67-
if name_ref.text() != macro_name || excl.kind() != EXCL {
65+
if name_ref.text() != macro_name || excl.kind() != T![!] {
6866
return None;
6967
}
7068

@@ -73,7 +71,7 @@ fn is_valid_macrocall(macro_call: &ast::MacroCall, macro_name: &str) -> Option<b
7371
let last_child = node.last_child_or_token()?;
7472

7573
match (first_child.kind(), last_child.kind()) {
76-
(L_PAREN, R_PAREN) | (L_BRACK, R_BRACK) | (L_CURLY, R_CURLY) => Some(true),
74+
(T!['('], T![')']) | (T!['['], T![']']) | (T!['{'], T!['}']) => Some(true),
7775
_ => Some(false),
7876
}
7977
}

crates/ra_assists/src/split_import.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ use std::iter::successors;
22

33
use hir::db::HirDatabase;
44
use ra_syntax::{
5-
TextUnit, AstNode, SyntaxKind::COLONCOLON,
5+
T,
6+
TextUnit, AstNode,
67
ast,
78
};
89

910
use crate::{AssistCtx, Assist, AssistId};
1011

1112
pub(crate) fn split_import(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
12-
let colon_colon = ctx.token_at_offset().find(|leaf| leaf.kind() == COLONCOLON)?;
13+
let colon_colon = ctx.token_at_offset().find(|leaf| leaf.kind() == T![::])?;
1314
let path = ast::Path::cast(colon_colon.parent())?;
1415
let top_path = successors(Some(path), |it| it.parent_path()).last()?;
1516

crates/ra_fmt/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::iter::successors;
44
use itertools::Itertools;
55
use ra_syntax::{
6-
SyntaxNode, SyntaxKind::*, SyntaxToken, SyntaxKind,
6+
SyntaxNode, SyntaxKind::*, SyntaxToken, SyntaxKind, T,
77
ast::{self, AstNode, AstToken},
88
};
99

@@ -38,7 +38,7 @@ pub fn extract_trivial_expression(block: &ast::Block) -> Option<&ast::Expr> {
3838
return None;
3939
}
4040
let non_trivial_children = block.syntax().children().filter(|it| match it.kind() {
41-
WHITESPACE | L_CURLY | R_CURLY => false,
41+
WHITESPACE | T!['{'] | T!['}'] => false,
4242
_ => it != &expr.syntax(),
4343
});
4444
if non_trivial_children.count() > 0 {
@@ -49,22 +49,22 @@ pub fn extract_trivial_expression(block: &ast::Block) -> Option<&ast::Expr> {
4949

5050
pub fn compute_ws(left: SyntaxKind, right: SyntaxKind) -> &'static str {
5151
match left {
52-
L_PAREN | L_BRACK => return "",
53-
L_CURLY => {
52+
T!['('] | T!['['] => return "",
53+
T!['{'] => {
5454
if let USE_TREE = right {
5555
return "";
5656
}
5757
}
5858
_ => (),
5959
}
6060
match right {
61-
R_PAREN | R_BRACK => return "",
62-
R_CURLY => {
61+
T![')'] | T![']'] => return "",
62+
T!['}'] => {
6363
if let USE_TREE = left {
6464
return "";
6565
}
6666
}
67-
DOT => return "",
67+
T![.] => return "",
6868
_ => (),
6969
}
7070
" "

crates/ra_ide_api/src/diagnostics.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use itertools::Itertools;
44
use hir::{source_binder, diagnostics::{Diagnostic as _, DiagnosticSink}};
55
use ra_db::SourceDatabase;
66
use ra_syntax::{
7-
Location, SourceFile, SyntaxKind, TextRange, SyntaxNode,
7+
T, Location, SourceFile, TextRange, SyntaxNode,
88
ast::{self, AstNode, NamedFieldList, NamedField},
99
};
1010
use ra_assists::ast_editor::{AstEditor, AstBuilder};
@@ -130,9 +130,7 @@ fn text_edit_for_remove_unnecessary_braces_with_self_in_use_statement(
130130
single_use_tree: &ast::UseTree,
131131
) -> Option<TextEdit> {
132132
let use_tree_list_node = single_use_tree.syntax().parent()?;
133-
if single_use_tree.path()?.segment()?.syntax().first_child_or_token()?.kind()
134-
== SyntaxKind::SELF_KW
135-
{
133+
if single_use_tree.path()?.segment()?.syntax().first_child_or_token()?.kind() == T![self] {
136134
let start = use_tree_list_node.prev_sibling_or_token()?.range().start();
137135
let end = use_tree_list_node.range().end();
138136
let range = TextRange::from_to(start, end);

crates/ra_ide_api/src/extend_selection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ fn extend_list_item(node: &SyntaxNode) -> Option<TextRange> {
157157
})
158158
.next()
159159
.and_then(|it| it.as_token())
160-
.filter(|node| node.kind() == COMMA)
160+
.filter(|node| node.kind() == T![,])
161161
}
162162

163163
if let Some(comma_node) = nearby_comma(node, Direction::Prev) {

0 commit comments

Comments
 (0)