Skip to content

Commit dde9488

Browse files
bors[bot]matklad
andauthored
Merge #3919
3919: Refactor tokena accessors r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 4cea01f + 2bfb65d commit dde9488

File tree

23 files changed

+247
-341
lines changed

23 files changed

+247
-341
lines changed

crates/ra_assists/src/handlers/add_explicit_type.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use hir::HirDisplay;
22
use ra_syntax::{
3-
ast::{self, AstNode, LetStmt, NameOwner, TypeAscriptionOwner},
3+
ast::{self, AstNode, AstToken, LetStmt, NameOwner, TypeAscriptionOwner},
44
TextRange,
55
};
66

@@ -35,7 +35,7 @@ pub(crate) fn add_explicit_type(ctx: AssistCtx) -> Option<Assist> {
3535
let name = pat.name()?;
3636
let name_range = name.syntax().text_range();
3737
let stmt_range = stmt.syntax().text_range();
38-
let eq_range = stmt.eq_token()?.text_range();
38+
let eq_range = stmt.eq_token()?.syntax().text_range();
3939
// Assist should only be applicable if cursor is between 'let' and '='
4040
let let_range = TextRange::from_to(stmt_range.start(), eq_range.start());
4141
let cursor_in_range = ctx.frange.range.is_subrange(&let_range);

crates/ra_assists/src/handlers/add_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub(crate) fn add_impl(ctx: AssistCtx) -> Option<Assist> {
4242
if let Some(type_params) = type_params {
4343
let lifetime_params = type_params
4444
.lifetime_params()
45-
.filter_map(|it| it.lifetime())
45+
.filter_map(|it| it.lifetime_token())
4646
.map(|it| it.text().clone());
4747
let type_params =
4848
type_params.type_params().filter_map(|it| it.name()).map(|it| it.text().clone());

crates/ra_assists/src/handlers/add_new.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ fn generate_impl_text(strukt: &ast::StructDef, code: &str) -> String {
106106
if let Some(type_params) = type_params {
107107
let lifetime_params = type_params
108108
.lifetime_params()
109-
.filter_map(|it| it.lifetime())
109+
.filter_map(|it| it.lifetime_token())
110110
.map(|it| it.text().clone());
111111
let type_params =
112112
type_params.type_params().filter_map(|it| it.name()).map(|it| it.text().clone());

crates/ra_assists/src/handlers/inline_local_variable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub(crate) fn inline_local_variable(ctx: AssistCtx) -> Option<Assist> {
2929
ast::Pat::BindPat(pat) => pat,
3030
_ => return None,
3131
};
32-
if bind_pat.is_mutable() {
32+
if bind_pat.mut_kw_token().is_some() {
3333
tested_by!(test_not_inline_mut_variable);
3434
return None;
3535
}

crates/ra_assists/src/handlers/introduce_variable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub(crate) fn introduce_variable(ctx: AssistCtx) -> Option<Assist> {
6161
};
6262
if is_full_stmt {
6363
tested_by!(test_introduce_var_expr_stmt);
64-
if !full_stmt.unwrap().has_semi() {
64+
if full_stmt.unwrap().semi_token().is_none() {
6565
buf.push_str(";");
6666
}
6767
edit.replace(expr.syntax().text_range(), buf);

crates/ra_assists/src/handlers/merge_imports.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ fn try_merge_trees(old: &ast::UseTree, new: &ast::UseTree) -> Option<ast::UseTre
8282
.filter(|it| it.kind() != T!['{'] && it.kind() != T!['}']),
8383
);
8484
let use_tree_list = lhs.use_tree_list()?;
85-
let pos = InsertPosition::Before(use_tree_list.r_curly()?.syntax().clone().into());
85+
let pos = InsertPosition::Before(use_tree_list.r_curly_token()?.syntax().clone().into());
8686
let use_tree_list = use_tree_list.insert_children(pos, to_insert);
8787
Some(lhs.with_use_tree_list(use_tree_list))
8888
}

crates/ra_hir_def/src/body/lower.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,10 @@ impl ExprCollector<'_> {
572572
let pattern = match &pat {
573573
ast::Pat::BindPat(bp) => {
574574
let name = bp.name().map(|nr| nr.as_name()).unwrap_or_else(Name::missing);
575-
let annotation = BindingAnnotation::new(bp.is_mutable(), bp.is_ref());
575+
let annotation = BindingAnnotation::new(
576+
bp.mut_kw_token().is_some(),
577+
bp.ref_kw_token().is_some(),
578+
);
576579
let subpat = bp.pat().map(|subpat| self.collect_pat(subpat));
577580
if annotation == BindingAnnotation::Unannotated && subpat.is_none() {
578581
// This could also be a single-segment path pattern. To
@@ -613,7 +616,7 @@ impl ExprCollector<'_> {
613616
}
614617
ast::Pat::RefPat(p) => {
615618
let pat = self.collect_pat_opt(p.pat());
616-
let mutability = Mutability::from_mutable(p.is_mut());
619+
let mutability = Mutability::from_mutable(p.mut_kw_token().is_some());
617620
Pat::Ref { pat, mutability }
618621
}
619622
ast::Pat::PathPat(p) => {

crates/ra_hir_def/src/data.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl FunctionData {
7575
TypeRef::unit()
7676
};
7777

78-
let ret_type = if src.value.is_async() {
78+
let ret_type = if src.value.async_kw_token().is_some() {
7979
let future_impl = desugar_future_path(ret_type);
8080
let ty_bound = TypeBound::Path(future_impl);
8181
TypeRef::ImplTrait(vec![ty_bound])
@@ -136,7 +136,7 @@ impl TraitData {
136136
pub(crate) fn trait_data_query(db: &dyn DefDatabase, tr: TraitId) -> Arc<TraitData> {
137137
let src = tr.lookup(db).source(db);
138138
let name = src.value.name().map_or_else(Name::missing, |n| n.as_name());
139-
let auto = src.value.is_auto();
139+
let auto = src.value.auto_kw_token().is_some();
140140
let ast_id_map = db.ast_id_map(src.file_id);
141141

142142
let container = AssocContainerId::TraitId(tr);
@@ -213,7 +213,7 @@ impl ImplData {
213213

214214
let target_trait = src.value.target_trait().map(TypeRef::from_ast);
215215
let target_type = TypeRef::from_ast_opt(src.value.target_type());
216-
let is_negative = src.value.is_negative();
216+
let is_negative = src.value.excl_token().is_some();
217217
let module_id = impl_loc.container.module(db);
218218

219219
let mut items = Vec::new();

crates/ra_hir_def/src/generics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl GenericParams {
194194
}
195195

196196
fn add_where_predicate_from_bound(&mut self, bound: ast::TypeBound, type_ref: TypeRef) {
197-
if bound.has_question_mark() {
197+
if bound.question_token().is_some() {
198198
// FIXME: remove this bound
199199
return;
200200
}

crates/ra_hir_def/src/nameres/raw.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ impl RawItemsCollector {
287287
let visibility = RawVisibility::from_ast_with_hygiene(module.visibility(), &self.hygiene);
288288

289289
let ast_id = self.source_ast_id_map.ast_id(&module);
290-
if module.has_semi() {
290+
if module.semi_token().is_some() {
291291
let item =
292292
self.raw_items.modules.alloc(ModuleData::Declaration { name, visibility, ast_id });
293293
self.push_item(current_module, attrs, RawItemKind::Module(item));

0 commit comments

Comments
 (0)