about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJeroen Vannevel <jer_vannevel@outlook.com>2022-02-15 19:12:23 +0000
committerJeroen Vannevel <jer_vannevel@outlook.com>2022-02-15 19:12:23 +0000
commitc8cd7a68b3ee3bc2c7de4d4287f554f78c63846a (patch)
treed6b8770ad276ee44f10ec8a1bacb0748512ffe47
parente1df78820ee5f4c3981035e13c6d6ec305974822 (diff)
downloadrust-c8cd7a68b3ee3bc2c7de4d4287f554f78c63846a.tar.gz
rust-c8cd7a68b3ee3bc2c7de4d4287f554f78c63846a.zip
use Name instead of String
-rw-r--r--crates/hir_def/src/type_ref.rs18
1 files changed, 11 insertions, 7 deletions
diff --git a/crates/hir_def/src/type_ref.rs b/crates/hir_def/src/type_ref.rs
index 01aca8f1de0..05d139219c7 100644
--- a/crates/hir_def/src/type_ref.rs
+++ b/crates/hir_def/src/type_ref.rs
@@ -1,9 +1,12 @@
 //! HIR for references to types. Paths in these are not yet resolved. They can
 //! be directly created from an ast::TypeRef, without further queries.
 
-use hir_expand::{name::Name, AstId, InFile};
+use hir_expand::{
+    name::{AsName, Name},
+    AstId, InFile,
+};
 use std::convert::TryInto;
-use syntax::{ast, AstNode};
+use syntax::ast::{self, HasName};
 
 use crate::{body::LowerCtx, intern::Interned, path::Path};
 
@@ -89,7 +92,7 @@ pub enum TypeRef {
     Array(Box<TypeRef>, ConstScalar),
     Slice(Box<TypeRef>),
     /// A fn pointer. Last element of the vector is the return type.
-    Fn(Vec<(Option<String>, TypeRef)>, bool /*varargs*/),
+    Fn(Vec<(Option<Name>, TypeRef)>, bool /*varargs*/),
     // For
     ImplTrait(Vec<Interned<TypeBound>>),
     DynTrait(Vec<Interned<TypeBound>>),
@@ -192,10 +195,11 @@ impl TypeRef {
                         .map(|p| (p.pat(), p.ty()))
                         .map(|it| {
                             let type_ref = TypeRef::from_ast_opt(ctx, it.1);
-                            let name = if it.0.is_some() {
-                                Some(it.0.unwrap().syntax().text().to_string())
-                            } else {
-                                None
+                            let name = match it.0 {
+                                Some(ast::Pat::IdentPat(it)) => Some(
+                                    it.name().map(|nr| nr.as_name()).unwrap_or_else(Name::missing),
+                                ),
+                                _ => None,
                             };
                             (name, type_ref)
                         })