Skip to content

Commit 683d0a4

Browse files
bors[bot]matklad
andauthored
Merge #5618
5618: Rename TypeRef -> Type r=matklad a=matklad The TypeRef name comes from IntelliJ days, where you often have both type *syntax* as well as *semantical* representation of types in scope. And naming both Type is confusing. In rust-analyzer however, we use ast types as `ast::Type`, and have many more semantic counterparts to ast types, so avoiding name clash here is just confusing. bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents 6b7cb8b + 08ea227 commit 683d0a4

File tree

19 files changed

+228
-222
lines changed

19 files changed

+228
-222
lines changed

crates/ra_assists/src/ast_transform.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl<'a> AstTransform<'a> for NullTransformer {
3232

3333
pub struct SubstituteTypeParams<'a> {
3434
source_scope: &'a SemanticsScope<'a>,
35-
substs: FxHashMap<hir::TypeParam, ast::TypeRef>,
35+
substs: FxHashMap<hir::TypeParam, ast::Type>,
3636
previous: Box<dyn AstTransform<'a> + 'a>,
3737
}
3838

@@ -80,17 +80,17 @@ impl<'a> SubstituteTypeParams<'a> {
8080

8181
// FIXME: It would probably be nicer if we could get this via HIR (i.e. get the
8282
// trait ref, and then go from the types in the substs back to the syntax)
83-
fn get_syntactic_substs(impl_def: ast::Impl) -> Option<Vec<ast::TypeRef>> {
83+
fn get_syntactic_substs(impl_def: ast::Impl) -> Option<Vec<ast::Type>> {
8484
let target_trait = impl_def.target_trait()?;
8585
let path_type = match target_trait {
86-
ast::TypeRef::PathType(path) => path,
86+
ast::Type::PathType(path) => path,
8787
_ => return None,
8888
};
8989
let type_arg_list = path_type.path()?.segment()?.type_arg_list()?;
9090
let mut result = Vec::new();
9191
for type_arg in type_arg_list.type_args() {
9292
let type_arg: ast::TypeArg = type_arg;
93-
result.push(type_arg.type_ref()?);
93+
result.push(type_arg.ty()?);
9494
}
9595
Some(result)
9696
}
@@ -99,9 +99,9 @@ impl<'a> SubstituteTypeParams<'a> {
9999
&self,
100100
node: &ra_syntax::SyntaxNode,
101101
) -> Option<ra_syntax::SyntaxNode> {
102-
let type_ref = ast::TypeRef::cast(node.clone())?;
102+
let type_ref = ast::Type::cast(node.clone())?;
103103
let path = match &type_ref {
104-
ast::TypeRef::PathType(path_type) => path_type.path()?,
104+
ast::Type::PathType(path_type) => path_type.path()?,
105105
_ => return None,
106106
};
107107
// FIXME: use `hir::Path::from_src` instead.

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
@@ -34,7 +34,7 @@ pub(crate) fn generate_from_impl_for_enum(acc: &mut Assists, ctx: &AssistContext
3434
}
3535
let field_type = field_list.fields().next()?.ty()?;
3636
let path = match field_type {
37-
ast::TypeRef::PathType(it) => it,
37+
ast::Type::PathType(it) => it,
3838
_ => return None,
3939
};
4040

crates/ra_assists/src/handlers/introduce_named_lifetime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn generate_fn_def_assist(
6868
let fn_params_without_lifetime: Vec<_> = param_list
6969
.params()
7070
.filter_map(|param| match param.ty() {
71-
Some(ast::TypeRef::ReferenceType(ascribed_type))
71+
Some(ast::Type::ReferenceType(ascribed_type))
7272
if ascribed_type.lifetime_token() == None =>
7373
{
7474
Some(ascribed_type.amp_token()?.text_range().end())

crates/ra_hir_def/src/generics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ impl GenericParams {
253253

254254
fn fill_where_predicates(&mut self, lower_ctx: &LowerCtx, where_clause: ast::WhereClause) {
255255
for pred in where_clause.predicates() {
256-
let type_ref = match pred.type_ref() {
256+
let type_ref = match pred.ty() {
257257
Some(type_ref) => type_ref,
258258
None => continue,
259259
};

crates/ra_hir_def/src/item_tree/lower.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,10 +648,10 @@ impl Ctx {
648648
self.data().vis.alloc(vis)
649649
}
650650

651-
fn lower_type_ref(&self, type_ref: &ast::TypeRef) -> TypeRef {
651+
fn lower_type_ref(&self, type_ref: &ast::Type) -> TypeRef {
652652
TypeRef::from_ast(&self.body_ctx, type_ref.clone())
653653
}
654-
fn lower_type_ref_opt(&self, type_ref: Option<ast::TypeRef>) -> TypeRef {
654+
fn lower_type_ref_opt(&self, type_ref: Option<ast::Type>) -> TypeRef {
655655
type_ref.map(|ty| self.lower_type_ref(&ty)).unwrap_or(TypeRef::Error)
656656
}
657657

crates/ra_hir_def/src/path/lower.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ pub(super) fn lower_generic_args(
152152
) -> Option<GenericArgs> {
153153
let mut args = Vec::new();
154154
for type_arg in node.type_args() {
155-
let type_ref = TypeRef::from_ast_opt(lower_ctx, type_arg.type_ref());
155+
let type_ref = TypeRef::from_ast_opt(lower_ctx, type_arg.ty());
156156
args.push(GenericArg::Type(type_ref));
157157
}
158158
// lifetimes ignored for now
@@ -161,7 +161,7 @@ pub(super) fn lower_generic_args(
161161
let assoc_type_arg: ast::AssocTypeArg = assoc_type_arg;
162162
if let Some(name_ref) = assoc_type_arg.name_ref() {
163163
let name = name_ref.as_name();
164-
let type_ref = assoc_type_arg.type_ref().map(|it| TypeRef::from_ast(lower_ctx, it));
164+
let type_ref = assoc_type_arg.ty().map(|it| TypeRef::from_ast(lower_ctx, it));
165165
let bounds = if let Some(l) = assoc_type_arg.type_bound_list() {
166166
l.bounds().map(|it| TypeBound::from_ast(lower_ctx, it)).collect()
167167
} else {

crates/ra_hir_def/src/type_ref.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,39 +80,39 @@ pub enum TypeBound {
8080

8181
impl TypeRef {
8282
/// Converts an `ast::TypeRef` to a `hir::TypeRef`.
83-
pub(crate) fn from_ast(ctx: &LowerCtx, node: ast::TypeRef) -> Self {
83+
pub(crate) fn from_ast(ctx: &LowerCtx, node: ast::Type) -> Self {
8484
match node {
85-
ast::TypeRef::ParenType(inner) => TypeRef::from_ast_opt(&ctx, inner.ty()),
86-
ast::TypeRef::TupleType(inner) => {
85+
ast::Type::ParenType(inner) => TypeRef::from_ast_opt(&ctx, inner.ty()),
86+
ast::Type::TupleType(inner) => {
8787
TypeRef::Tuple(inner.fields().map(|it| TypeRef::from_ast(ctx, it)).collect())
8888
}
89-
ast::TypeRef::NeverType(..) => TypeRef::Never,
90-
ast::TypeRef::PathType(inner) => {
89+
ast::Type::NeverType(..) => TypeRef::Never,
90+
ast::Type::PathType(inner) => {
9191
// FIXME: Use `Path::from_src`
9292
inner
9393
.path()
9494
.and_then(|it| ctx.lower_path(it))
9595
.map(TypeRef::Path)
9696
.unwrap_or(TypeRef::Error)
9797
}
98-
ast::TypeRef::PointerType(inner) => {
98+
ast::Type::PointerType(inner) => {
9999
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
}
103-
ast::TypeRef::ArrayType(inner) => {
103+
ast::Type::ArrayType(inner) => {
104104
TypeRef::Array(Box::new(TypeRef::from_ast_opt(&ctx, inner.ty())))
105105
}
106-
ast::TypeRef::SliceType(inner) => {
106+
ast::Type::SliceType(inner) => {
107107
TypeRef::Slice(Box::new(TypeRef::from_ast_opt(&ctx, inner.ty())))
108108
}
109-
ast::TypeRef::ReferenceType(inner) => {
109+
ast::Type::ReferenceType(inner) => {
110110
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
}
114-
ast::TypeRef::PlaceholderType(_inner) => TypeRef::Placeholder,
115-
ast::TypeRef::FnPointerType(inner) => {
114+
ast::Type::PlaceholderType(_inner) => TypeRef::Placeholder,
115+
ast::Type::FnPointerType(inner) => {
116116
let ret_ty = inner
117117
.ret_type()
118118
.and_then(|rt| rt.ty())
@@ -132,17 +132,17 @@ 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.ty()),
136-
ast::TypeRef::ImplTraitType(inner) => {
135+
ast::Type::ForType(inner) => TypeRef::from_ast_opt(&ctx, inner.ty()),
136+
ast::Type::ImplTraitType(inner) => {
137137
TypeRef::ImplTrait(type_bounds_from_ast(ctx, inner.type_bound_list()))
138138
}
139-
ast::TypeRef::DynTraitType(inner) => {
139+
ast::Type::DynTraitType(inner) => {
140140
TypeRef::DynTrait(type_bounds_from_ast(ctx, inner.type_bound_list()))
141141
}
142142
}
143143
}
144144

145-
pub(crate) fn from_ast_opt(ctx: &LowerCtx, node: Option<ast::TypeRef>) -> Self {
145+
pub(crate) fn from_ast_opt(ctx: &LowerCtx, node: Option<ast::Type>) -> Self {
146146
if let Some(node) = node {
147147
TypeRef::from_ast(ctx, node)
148148
} else {

crates/ra_ide/src/display/short_label.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl ShortLabel for ast::Variant {
7777
}
7878
}
7979

80-
fn short_label_from_ty<T>(node: &T, ty: Option<ast::TypeRef>, prefix: &str) -> Option<String>
80+
fn short_label_from_ty<T>(node: &T, ty: Option<ast::Type>, prefix: &str) -> Option<String>
8181
where
8282
T: NameOwner + VisibilityOwner,
8383
{

crates/ra_ide/src/file_structure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
5757

5858
fn decl_with_type_ref<N: NameOwner + AttrsOwner>(
5959
node: &N,
60-
type_ref: Option<ast::TypeRef>,
60+
type_ref: Option<ast::Type>,
6161
) -> Option<StructureNode> {
6262
let detail = type_ref.map(|type_ref| {
6363
let mut detail = String::new();

crates/ra_ide/src/references/rename.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ fn rename_to_self(
157157
}
158158
let first_param = params.params().next()?;
159159
let mutable = match first_param.ty() {
160-
Some(ast::TypeRef::ReferenceType(rt)) => rt.mut_token().is_some(),
160+
Some(ast::Type::ReferenceType(rt)) => rt.mut_token().is_some(),
161161
_ => return None, // not renaming other types
162162
};
163163

@@ -194,7 +194,7 @@ fn text_edit_from_self_param(
194194
new_name: &str,
195195
) -> Option<TextEdit> {
196196
fn target_type_name(impl_def: &ast::Impl) -> Option<String> {
197-
if let Some(ast::TypeRef::PathType(p)) = impl_def.target_type() {
197+
if let Some(ast::Type::PathType(p)) = impl_def.target_type() {
198198
return Some(p.path()?.segment()?.name_ref()?.text().to_string());
199199
}
200200
None

0 commit comments

Comments
 (0)