Skip to content

Commit 2bfb65d

Browse files
committed
Be consistent about token accesors
1 parent e6d2218 commit 2bfb65d

File tree

14 files changed

+36
-114
lines changed

14 files changed

+36
-114
lines changed

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_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));

crates/ra_hir_def/src/type_ref.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl TypeRef {
7777
}
7878
ast::TypeRef::PointerType(inner) => {
7979
let inner_ty = TypeRef::from_ast_opt(inner.type_ref());
80-
let mutability = Mutability::from_mutable(inner.is_mut());
80+
let mutability = Mutability::from_mutable(inner.mut_kw_token().is_some());
8181
TypeRef::RawPtr(Box::new(inner_ty), mutability)
8282
}
8383
ast::TypeRef::ArrayType(inner) => {
@@ -88,7 +88,7 @@ impl TypeRef {
8888
}
8989
ast::TypeRef::ReferenceType(inner) => {
9090
let inner_ty = TypeRef::from_ast_opt(inner.type_ref());
91-
let mutability = Mutability::from_mutable(inner.is_mut());
91+
let mutability = Mutability::from_mutable(inner.mut_kw_token().is_some());
9292
TypeRef::Reference(Box::new(inner_ty), mutability)
9393
}
9494
ast::TypeRef::PlaceholderType(_inner) => TypeRef::Placeholder,

crates/ra_ide/src/completion/completion_context.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,10 @@ impl<'a> CompletionContext<'a> {
190190
if let Some(name) = find_node_at_offset::<ast::Name>(&file_with_fake_ident, offset) {
191191
if let Some(bind_pat) = name.syntax().ancestors().find_map(ast::BindPat::cast) {
192192
self.is_pat_binding_or_const = true;
193-
if bind_pat.has_at() || bind_pat.is_ref() || bind_pat.is_mutable() {
193+
if bind_pat.at_token().is_some()
194+
|| bind_pat.ref_kw_token().is_some()
195+
|| bind_pat.mut_kw_token().is_some()
196+
{
194197
self.is_pat_binding_or_const = false;
195198
}
196199
if bind_pat.syntax().parent().and_then(ast::RecordFieldPatList::cast).is_some() {

crates/ra_ide/src/references.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ fn decl_access(def: &Definition, syntax: &SyntaxNode, range: TextRange) -> Optio
152152
if stmt.initializer().is_some() {
153153
let pat = stmt.pat()?;
154154
if let ast::Pat::BindPat(it) = pat {
155-
if it.is_mutable() {
155+
if it.mut_kw_token().is_some() {
156156
return Some(ReferenceAccess::Write);
157157
}
158158
}

crates/ra_ide/src/typing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fn on_char_typed_inner(
6363
fn on_eq_typed(file: &SourceFile, offset: TextUnit) -> Option<SingleFileChange> {
6464
assert_eq!(file.syntax().text().char_at(offset), Some('='));
6565
let let_stmt: ast::LetStmt = find_node_at_offset(file.syntax(), offset)?;
66-
if let_stmt.has_semi() {
66+
if let_stmt.semi_token().is_some() {
6767
return None;
6868
}
6969
if let Some(expr) = let_stmt.initializer() {

0 commit comments

Comments
 (0)