Skip to content

Commit 134d3c3

Browse files
bors[bot]matklad
andauthored
Merge #5612
5612: Remove TypeAscriptionOwner r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents 6f5b530 + 2e2642e commit 134d3c3

File tree

17 files changed

+64
-90
lines changed

17 files changed

+64
-90
lines changed

crates/ra_assists/src/handlers/add_explicit_type.rs

Lines changed: 8 additions & 8 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, LetStmt, NameOwner},
44
TextRange,
55
};
66

@@ -22,20 +22,20 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
2222
// }
2323
// ```
2424
pub(crate) fn add_explicit_type(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
25-
let stmt = ctx.find_node_at_offset::<LetStmt>()?;
26-
let module = ctx.sema.scope(stmt.syntax()).module()?;
27-
let expr = stmt.initializer()?;
25+
let let_stmt = ctx.find_node_at_offset::<LetStmt>()?;
26+
let module = ctx.sema.scope(let_stmt.syntax()).module()?;
27+
let expr = let_stmt.initializer()?;
2828
// Must be a binding
29-
let pat = match stmt.pat()? {
29+
let pat = match let_stmt.pat()? {
3030
ast::Pat::BindPat(bind_pat) => bind_pat,
3131
_ => return None,
3232
};
3333
let pat_range = pat.syntax().text_range();
3434
// The binding must have a name
3535
let name = pat.name()?;
3636
let name_range = name.syntax().text_range();
37-
let stmt_range = stmt.syntax().text_range();
38-
let eq_range = stmt.eq_token()?.text_range();
37+
let stmt_range = let_stmt.syntax().text_range();
38+
let eq_range = let_stmt.eq_token()?.text_range();
3939
// Assist should only be applicable if cursor is between 'let' and '='
4040
let let_range = TextRange::new(stmt_range.start(), eq_range.start());
4141
let cursor_in_range = let_range.contains_range(ctx.frange.range);
@@ -44,7 +44,7 @@ pub(crate) fn add_explicit_type(acc: &mut Assists, ctx: &AssistContext) -> Optio
4444
}
4545
// Assist not applicable if the type has already been specified
4646
// and it has no placeholders
47-
let ascribed_ty = stmt.ascribed_type();
47+
let ascribed_ty = let_stmt.ty();
4848
if let Some(ty) = &ascribed_ty {
4949
if ty.syntax().descendants().find_map(ast::PlaceholderType::cast).is_none() {
5050
return None;

crates/ra_assists/src/handlers/generate_new.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use hir::Adt;
22
use ra_syntax::{
3-
ast::{
4-
self, AstNode, GenericParamsOwner, NameOwner, StructKind, TypeAscriptionOwner,
5-
VisibilityOwner,
6-
},
3+
ast::{self, AstNode, GenericParamsOwner, NameOwner, StructKind, VisibilityOwner},
74
T,
85
};
96
use stdx::{format_to, SepBy};
@@ -54,9 +51,7 @@ pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
5451

5552
let params = field_list
5653
.fields()
57-
.filter_map(|f| {
58-
Some(format!("{}: {}", f.name()?.syntax(), f.ascribed_type()?.syntax()))
59-
})
54+
.filter_map(|f| Some(format!("{}: {}", f.name()?.syntax(), f.ty()?.syntax())))
6055
.sep_by(", ");
6156
let fields = field_list.fields().filter_map(|f| f.name()).sep_by(", ");
6257

crates/ra_assists/src/handlers/introduce_named_lifetime.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use ra_syntax::{
2-
ast::{self, GenericParamsOwner, NameOwner, TypeAscriptionOwner},
2+
ast::{self, GenericParamsOwner, NameOwner},
33
AstNode, SyntaxKind, TextRange, TextSize,
44
};
55
use rustc_hash::FxHashSet;
@@ -67,7 +67,7 @@ fn generate_fn_def_assist(
6767
// otherwise, if there's a single reference parameter without a named liftime, use that
6868
let fn_params_without_lifetime: Vec<_> = param_list
6969
.params()
70-
.filter_map(|param| match param.ascribed_type() {
70+
.filter_map(|param| match param.ty() {
7171
Some(ast::TypeRef::ReferenceType(ascribed_type))
7272
if ascribed_type.lifetime_token() == None =>
7373
{

crates/ra_hir_def/src/adt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use hir_expand::{
88
InFile,
99
};
1010
use ra_arena::{map::ArenaMap, Arena};
11-
use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner, VisibilityOwner};
11+
use ra_syntax::ast::{self, NameOwner, VisibilityOwner};
1212

1313
use crate::{
1414
body::{CfgExpander, LowerCtx},
@@ -251,7 +251,7 @@ fn lower_struct(
251251
|| Either::Right(fd.clone()),
252252
|| FieldData {
253253
name: fd.name().map(|n| n.as_name()).unwrap_or_else(Name::missing),
254-
type_ref: TypeRef::from_ast_opt(&ctx, fd.ascribed_type()),
254+
type_ref: TypeRef::from_ast_opt(&ctx, fd.ty()),
255255
visibility: RawVisibility::from_ast(db, ast.with_value(fd.visibility())),
256256
},
257257
);

crates/ra_hir_def/src/body/lower.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use ra_arena::Arena;
1111
use ra_syntax::{
1212
ast::{
1313
self, ArgListOwner, ArrayExprKind, LiteralKind, LoopBodyOwner, ModuleItemOwner, NameOwner,
14-
SlicePatComponents, TypeAscriptionOwner,
14+
SlicePatComponents,
1515
},
1616
AstNode, AstPtr,
1717
};
@@ -466,8 +466,7 @@ impl ExprCollector<'_> {
466466
if let Some(pl) = e.param_list() {
467467
for param in pl.params() {
468468
let pat = self.collect_pat_opt(param.pat());
469-
let type_ref =
470-
param.ascribed_type().map(|it| TypeRef::from_ast(&self.ctx(), it));
469+
let type_ref = param.ty().map(|it| TypeRef::from_ast(&self.ctx(), it));
471470
args.push(pat);
472471
arg_types.push(type_ref);
473472
}
@@ -607,8 +606,7 @@ impl ExprCollector<'_> {
607606
.map(|s| match s {
608607
ast::Stmt::LetStmt(stmt) => {
609608
let pat = self.collect_pat_opt(stmt.pat());
610-
let type_ref =
611-
stmt.ascribed_type().map(|it| TypeRef::from_ast(&self.ctx(), it));
609+
let type_ref = stmt.ty().map(|it| TypeRef::from_ast(&self.ctx(), it));
612610
let initializer = stmt.initializer().map(|e| self.collect_expr(e));
613611
Statement::Let { pat, type_ref, initializer }
614612
}

crates/ra_hir_def/src/item_tree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::{
1313
sync::Arc,
1414
};
1515

16-
use ast::{AstNode, AttrsOwner, NameOwner, StructKind, TypeAscriptionOwner};
16+
use ast::{AstNode, AttrsOwner, NameOwner, StructKind};
1717
use either::Either;
1818
use hir_expand::{
1919
ast_id_map::FileAstId,

crates/ra_hir_def/src/item_tree/lower.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ impl Ctx {
209209
fn lower_record_field(&mut self, field: &ast::RecordField) -> Option<Field> {
210210
let name = field.name()?.as_name();
211211
let visibility = self.lower_visibility(field);
212-
let type_ref = self.lower_type_ref_opt(field.ascribed_type());
212+
let type_ref = self.lower_type_ref_opt(field.ty());
213213
let res = Field { name, type_ref, visibility };
214214
Some(res)
215215
}
@@ -286,7 +286,7 @@ impl Ctx {
286286
let mut has_self_param = false;
287287
if let Some(param_list) = func.param_list() {
288288
if let Some(self_param) = param_list.self_param() {
289-
let self_type = match self_param.ascribed_type() {
289+
let self_type = match self_param.ty() {
290290
Some(type_ref) => TypeRef::from_ast(&self.body_ctx, type_ref),
291291
None => {
292292
let self_type = TypeRef::Path(name![Self].into());
@@ -305,7 +305,7 @@ impl Ctx {
305305
has_self_param = true;
306306
}
307307
for param in param_list.params() {
308-
let type_ref = TypeRef::from_ast_opt(&self.body_ctx, param.ascribed_type());
308+
let type_ref = TypeRef::from_ast_opt(&self.body_ctx, param.ty());
309309
params.push(type_ref);
310310
}
311311
}
@@ -370,7 +370,7 @@ impl Ctx {
370370

371371
fn lower_static(&mut self, static_: &ast::Static) -> Option<FileItemTreeId<Static>> {
372372
let name = static_.name()?.as_name();
373-
let type_ref = self.lower_type_ref_opt(static_.ascribed_type());
373+
let type_ref = self.lower_type_ref_opt(static_.ty());
374374
let visibility = self.lower_visibility(static_);
375375
let mutable = static_.mut_token().is_some();
376376
let ast_id = self.source_ast_id_map.ast_id(static_);
@@ -380,7 +380,7 @@ impl Ctx {
380380

381381
fn lower_const(&mut self, konst: &ast::Const) -> FileItemTreeId<Const> {
382382
let name = konst.name().map(|it| it.as_name());
383-
let type_ref = self.lower_type_ref_opt(konst.ascribed_type());
383+
let type_ref = self.lower_type_ref_opt(konst.ty());
384384
let visibility = self.lower_visibility(konst);
385385
let ast_id = self.source_ast_id_map.ast_id(konst);
386386
let res = Const { name, visibility, type_ref, ast_id };

crates/ra_hir_def/src/path/lower.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use hir_expand::{
99
hygiene::Hygiene,
1010
name::{name, AsName},
1111
};
12-
use ra_syntax::ast::{self, AstNode, TypeAscriptionOwner, TypeBoundsOwner};
12+
use ra_syntax::ast::{self, AstNode, TypeBoundsOwner};
1313

1414
use super::AssociatedTypeBinding;
1515
use crate::{
@@ -189,7 +189,7 @@ fn lower_generic_args_from_fn_path(
189189
if let Some(params) = params {
190190
let mut param_types = Vec::new();
191191
for param in params.params() {
192-
let type_ref = TypeRef::from_ast_opt(&ctx, param.ascribed_type());
192+
let type_ref = TypeRef::from_ast_opt(&ctx, param.ty());
193193
param_types.push(type_ref);
194194
}
195195
let arg = GenericArg::Type(TypeRef::Tuple(param_types));

crates/ra_hir_def/src/type_ref.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! HIR for references to types. Paths in these are not yet resolved. They can
22
//! be directly created from an ast::TypeRef, without further queries.
33
4-
use ra_syntax::ast::{self, TypeAscriptionOwner};
4+
use ra_syntax::ast::{self};
55

66
use crate::{body::LowerCtx, path::Path};
77

@@ -124,10 +124,7 @@ impl TypeRef {
124124
is_varargs = param.dotdotdot_token().is_some();
125125
}
126126

127-
pl.params()
128-
.map(|p| p.ascribed_type())
129-
.map(|it| TypeRef::from_ast_opt(&ctx, it))
130-
.collect()
127+
pl.params().map(|p| p.ty()).map(|it| TypeRef::from_ast_opt(&ctx, it)).collect()
131128
} else {
132129
Vec::new()
133130
};

crates/ra_ide/src/display/short_label.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! FIXME: write short doc here
22
3-
use ra_syntax::ast::{self, AstNode, NameOwner, TypeAscriptionOwner, VisibilityOwner};
3+
use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner};
44
use stdx::format_to;
55

66
pub(crate) trait ShortLabel {
@@ -55,19 +55,19 @@ impl ShortLabel for ast::TypeAlias {
5555

5656
impl ShortLabel for ast::Const {
5757
fn short_label(&self) -> Option<String> {
58-
short_label_from_ascribed_node(self, "const ")
58+
short_label_from_ty(self, self.ty(), "const ")
5959
}
6060
}
6161

6262
impl ShortLabel for ast::Static {
6363
fn short_label(&self) -> Option<String> {
64-
short_label_from_ascribed_node(self, "static ")
64+
short_label_from_ty(self, self.ty(), "static ")
6565
}
6666
}
6767

6868
impl ShortLabel for ast::RecordField {
6969
fn short_label(&self) -> Option<String> {
70-
short_label_from_ascribed_node(self, "")
70+
short_label_from_ty(self, self.ty(), "")
7171
}
7272
}
7373

@@ -77,13 +77,13 @@ impl ShortLabel for ast::Variant {
7777
}
7878
}
7979

80-
fn short_label_from_ascribed_node<T>(node: &T, prefix: &str) -> Option<String>
80+
fn short_label_from_ty<T>(node: &T, ty: Option<ast::TypeRef>, prefix: &str) -> Option<String>
8181
where
82-
T: NameOwner + VisibilityOwner + TypeAscriptionOwner,
82+
T: NameOwner + VisibilityOwner,
8383
{
8484
let mut buf = short_label_from_node(node, prefix)?;
8585

86-
if let Some(type_ref) = node.ascribed_type() {
86+
if let Some(type_ref) = ty {
8787
format_to!(buf, ": {}", type_ref.syntax());
8888
}
8989

0 commit comments

Comments
 (0)