Skip to content

Commit f95f425

Browse files
committed
Use ty to access most TypeRefs
1 parent 2e2642e commit f95f425

File tree

11 files changed

+39
-41
lines changed

11 files changed

+39
-41
lines changed

crates/ra_assists/src/handlers/change_return_type_to_result.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub(crate) fn change_return_type_to_result(acc: &mut Assists, ctx: &AssistContex
2222
// FIXME: extend to lambdas as well
2323
let fn_def = ret_type.syntax().parent().and_then(ast::Fn::cast)?;
2424

25-
let type_ref = &ret_type.type_ref()?;
25+
let type_ref = &ret_type.ty()?;
2626
let ret_type_str = type_ref.syntax().text().to_string();
2727
let first_part_ret_type = ret_type_str.splitn(2, '<').next();
2828
if let Some(ret_type_first_part) = first_part_ret_type {

crates/ra_assists/src/handlers/generate_from_impl_for_enum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub(crate) fn generate_from_impl_for_enum(acc: &mut Assists, ctx: &AssistContext
3232
if field_list.fields().count() != 1 {
3333
return None;
3434
}
35-
let field_type = field_list.fields().next()?.type_ref()?;
35+
let field_type = field_list.fields().next()?.ty()?;
3636
let path = match field_type {
3737
ast::TypeRef::PathType(it) => it,
3838
_ => return None,

crates/ra_hir_def/src/adt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ fn lower_struct(
234234
|| Either::Left(fd.clone()),
235235
|| FieldData {
236236
name: Name::new_tuple_field(i),
237-
type_ref: TypeRef::from_ast_opt(&ctx, fd.type_ref()),
237+
type_ref: TypeRef::from_ast_opt(&ctx, fd.ty()),
238238
visibility: RawVisibility::from_ast(db, ast.with_value(fd.visibility())),
239239
},
240240
);

crates/ra_hir_def/src/body/lower.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ impl ExprCollector<'_> {
432432
}
433433
ast::Expr::CastExpr(e) => {
434434
let expr = self.collect_expr_opt(e.expr());
435-
let type_ref = TypeRef::from_ast_opt(&self.ctx(), e.type_ref());
435+
let type_ref = TypeRef::from_ast_opt(&self.ctx(), e.ty());
436436
self.alloc_expr(Expr::Cast { expr, type_ref }, syntax_ptr)
437437
}
438438
ast::Expr::RefExpr(e) => {
@@ -471,10 +471,8 @@ impl ExprCollector<'_> {
471471
arg_types.push(type_ref);
472472
}
473473
}
474-
let ret_type = e
475-
.ret_type()
476-
.and_then(|r| r.type_ref())
477-
.map(|it| TypeRef::from_ast(&self.ctx(), it));
474+
let ret_type =
475+
e.ret_type().and_then(|r| r.ty()).map(|it| TypeRef::from_ast(&self.ctx(), it));
478476
let body = self.collect_expr_opt(e.body());
479477
self.alloc_expr(Expr::Lambda { args, arg_types, ret_type, body }, syntax_ptr)
480478
}

crates/ra_hir_def/src/item_tree/lower.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ impl Ctx {
228228
fn lower_tuple_field(&mut self, idx: usize, field: &ast::TupleField) -> Field {
229229
let name = Name::new_tuple_field(idx);
230230
let visibility = self.lower_visibility(field);
231-
let type_ref = self.lower_type_ref_opt(field.type_ref());
231+
let type_ref = self.lower_type_ref_opt(field.ty());
232232
let res = Field { name, type_ref, visibility };
233233
res
234234
}
@@ -317,7 +317,7 @@ impl Ctx {
317317
}
318318
}
319319

320-
let ret_type = match func.ret_type().and_then(|rt| rt.type_ref()) {
320+
let ret_type = match func.ret_type().and_then(|rt| rt.ty()) {
321321
Some(type_ref) => TypeRef::from_ast(&self.body_ctx, type_ref),
322322
_ => TypeRef::unit(),
323323
};
@@ -352,7 +352,7 @@ impl Ctx {
352352
type_alias: &ast::TypeAlias,
353353
) -> Option<FileItemTreeId<TypeAlias>> {
354354
let name = type_alias.name()?.as_name();
355-
let type_ref = type_alias.type_ref().map(|it| self.lower_type_ref(&it));
355+
let type_ref = type_alias.ty().map(|it| self.lower_type_ref(&it));
356356
let visibility = self.lower_visibility(type_alias);
357357
let bounds = self.lower_type_bounds(type_alias);
358358
let generic_params = self.lower_generic_params(GenericsOwner::TypeAlias, type_alias);

crates/ra_hir_def/src/path/lower.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ fn lower_generic_args_from_fn_path(
196196
args.push(arg);
197197
}
198198
if let Some(ret_type) = ret_type {
199-
let type_ref = TypeRef::from_ast_opt(&ctx, ret_type.type_ref());
199+
let type_ref = TypeRef::from_ast_opt(&ctx, ret_type.ty());
200200
bindings.push(AssociatedTypeBinding {
201201
name: name![Output],
202202
type_ref: Some(type_ref),

crates/ra_hir_def/src/type_ref.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl TypeRef {
8282
/// Converts an `ast::TypeRef` to a `hir::TypeRef`.
8383
pub(crate) fn from_ast(ctx: &LowerCtx, node: ast::TypeRef) -> Self {
8484
match node {
85-
ast::TypeRef::ParenType(inner) => TypeRef::from_ast_opt(&ctx, inner.type_ref()),
85+
ast::TypeRef::ParenType(inner) => TypeRef::from_ast_opt(&ctx, inner.ty()),
8686
ast::TypeRef::TupleType(inner) => {
8787
TypeRef::Tuple(inner.fields().map(|it| TypeRef::from_ast(ctx, it)).collect())
8888
}
@@ -96,26 +96,26 @@ impl TypeRef {
9696
.unwrap_or(TypeRef::Error)
9797
}
9898
ast::TypeRef::PointerType(inner) => {
99-
let inner_ty = TypeRef::from_ast_opt(&ctx, inner.type_ref());
99+
let inner_ty = TypeRef::from_ast_opt(&ctx, inner.ty());
100100
let mutability = Mutability::from_mutable(inner.mut_token().is_some());
101101
TypeRef::RawPtr(Box::new(inner_ty), mutability)
102102
}
103103
ast::TypeRef::ArrayType(inner) => {
104-
TypeRef::Array(Box::new(TypeRef::from_ast_opt(&ctx, inner.type_ref())))
104+
TypeRef::Array(Box::new(TypeRef::from_ast_opt(&ctx, inner.ty())))
105105
}
106106
ast::TypeRef::SliceType(inner) => {
107-
TypeRef::Slice(Box::new(TypeRef::from_ast_opt(&ctx, inner.type_ref())))
107+
TypeRef::Slice(Box::new(TypeRef::from_ast_opt(&ctx, inner.ty())))
108108
}
109109
ast::TypeRef::ReferenceType(inner) => {
110-
let inner_ty = TypeRef::from_ast_opt(&ctx, inner.type_ref());
110+
let inner_ty = TypeRef::from_ast_opt(&ctx, inner.ty());
111111
let mutability = Mutability::from_mutable(inner.mut_token().is_some());
112112
TypeRef::Reference(Box::new(inner_ty), mutability)
113113
}
114114
ast::TypeRef::PlaceholderType(_inner) => TypeRef::Placeholder,
115115
ast::TypeRef::FnPointerType(inner) => {
116116
let ret_ty = inner
117117
.ret_type()
118-
.and_then(|rt| rt.type_ref())
118+
.and_then(|rt| rt.ty())
119119
.map(|it| TypeRef::from_ast(ctx, it))
120120
.unwrap_or_else(|| TypeRef::Tuple(Vec::new()));
121121
let mut is_varargs = false;
@@ -132,7 +132,7 @@ impl TypeRef {
132132
TypeRef::Fn(params, is_varargs)
133133
}
134134
// for types are close enough for our purposes to the inner type for now...
135-
ast::TypeRef::ForType(inner) => TypeRef::from_ast_opt(&ctx, inner.type_ref()),
135+
ast::TypeRef::ForType(inner) => TypeRef::from_ast_opt(&ctx, inner.ty()),
136136
ast::TypeRef::ImplTraitType(inner) => {
137137
TypeRef::ImplTrait(type_bounds_from_ast(ctx, inner.type_bound_list()))
138138
}

crates/ra_ide/src/display.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub(crate) fn function_declaration(node: &ast::Fn) -> String {
4444
format_to!(buf, "{}", param_list);
4545
}
4646
if let Some(ret_type) = node.ret_type() {
47-
if ret_type.type_ref().is_some() {
47+
if ret_type.ty().is_some() {
4848
format_to!(buf, " {}", ret_type);
4949
}
5050
}

crates/ra_ide/src/file_structure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
125125
ast::Variant(it) => decl(it),
126126
ast::Trait(it) => decl(it),
127127
ast::Module(it) => decl(it),
128-
ast::TypeAlias(it) => decl_with_type_ref(&it, it.type_ref()),
128+
ast::TypeAlias(it) => decl_with_type_ref(&it, it.ty()),
129129
ast::RecordField(it) => decl_with_type_ref(&it, it.ty()),
130130
ast::Const(it) => decl_with_type_ref(&it, it.ty()),
131131
ast::Static(it) => decl_with_type_ref(&it, it.ty()),

crates/ra_syntax/src/ast/generated/nodes.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl TypeAlias {
198198
pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) }
199199
pub fn type_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![type]) }
200200
pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
201-
pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
201+
pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) }
202202
pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
203203
}
204204
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -333,7 +333,7 @@ pub struct RetType {
333333
}
334334
impl RetType {
335335
pub fn thin_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![->]) }
336-
pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
336+
pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) }
337337
}
338338
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
339339
pub struct WhereClause {
@@ -425,7 +425,7 @@ pub struct TupleField {
425425
impl ast::AttrsOwner for TupleField {}
426426
impl ast::VisibilityOwner for TupleField {}
427427
impl TupleField {
428-
pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
428+
pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) }
429429
}
430430
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
431431
pub struct VariantList {
@@ -525,7 +525,7 @@ pub struct ParenType {
525525
}
526526
impl ParenType {
527527
pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
528-
pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
528+
pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) }
529529
pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
530530
}
531531
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -559,15 +559,15 @@ impl PointerType {
559559
pub fn star_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![*]) }
560560
pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
561561
pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
562-
pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
562+
pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) }
563563
}
564564
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
565565
pub struct ArrayType {
566566
pub(crate) syntax: SyntaxNode,
567567
}
568568
impl ArrayType {
569569
pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) }
570-
pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
570+
pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) }
571571
pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
572572
pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
573573
pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
@@ -578,7 +578,7 @@ pub struct SliceType {
578578
}
579579
impl SliceType {
580580
pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) }
581-
pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
581+
pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) }
582582
pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
583583
}
584584
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -591,7 +591,7 @@ impl ReferenceType {
591591
support::token(&self.syntax, T![lifetime])
592592
}
593593
pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
594-
pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
594+
pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) }
595595
}
596596
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
597597
pub struct PlaceholderType {
@@ -618,7 +618,7 @@ pub struct ForType {
618618
impl ForType {
619619
pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) }
620620
pub fn generic_param_list(&self) -> Option<GenericParamList> { support::child(&self.syntax) }
621-
pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
621+
pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) }
622622
}
623623
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
624624
pub struct ImplTraitType {
@@ -882,7 +882,7 @@ impl ast::AttrsOwner for CastExpr {}
882882
impl CastExpr {
883883
pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
884884
pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) }
885-
pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
885+
pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) }
886886
}
887887
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
888888
pub struct RefExpr {

0 commit comments

Comments
 (0)