mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 15:15:24 +00:00
use Name instead of String
This commit is contained in:
parent
e1df78820e
commit
c8cd7a68b3
1 changed files with 11 additions and 7 deletions
|
@ -1,9 +1,12 @@
|
||||||
//! HIR for references to types. Paths in these are not yet resolved. They can
|
//! HIR for references to types. Paths in these are not yet resolved. They can
|
||||||
//! be directly created from an ast::TypeRef, without further queries.
|
//! 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 std::convert::TryInto;
|
||||||
use syntax::{ast, AstNode};
|
use syntax::ast::{self, HasName};
|
||||||
|
|
||||||
use crate::{body::LowerCtx, intern::Interned, path::Path};
|
use crate::{body::LowerCtx, intern::Interned, path::Path};
|
||||||
|
|
||||||
|
@ -89,7 +92,7 @@ pub enum TypeRef {
|
||||||
Array(Box<TypeRef>, ConstScalar),
|
Array(Box<TypeRef>, ConstScalar),
|
||||||
Slice(Box<TypeRef>),
|
Slice(Box<TypeRef>),
|
||||||
/// A fn pointer. Last element of the vector is the return type.
|
/// 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
|
// For
|
||||||
ImplTrait(Vec<Interned<TypeBound>>),
|
ImplTrait(Vec<Interned<TypeBound>>),
|
||||||
DynTrait(Vec<Interned<TypeBound>>),
|
DynTrait(Vec<Interned<TypeBound>>),
|
||||||
|
@ -192,10 +195,11 @@ impl TypeRef {
|
||||||
.map(|p| (p.pat(), p.ty()))
|
.map(|p| (p.pat(), p.ty()))
|
||||||
.map(|it| {
|
.map(|it| {
|
||||||
let type_ref = TypeRef::from_ast_opt(ctx, it.1);
|
let type_ref = TypeRef::from_ast_opt(ctx, it.1);
|
||||||
let name = if it.0.is_some() {
|
let name = match it.0 {
|
||||||
Some(it.0.unwrap().syntax().text().to_string())
|
Some(ast::Pat::IdentPat(it)) => Some(
|
||||||
} else {
|
it.name().map(|nr| nr.as_name()).unwrap_or_else(Name::missing),
|
||||||
None
|
),
|
||||||
|
_ => None,
|
||||||
};
|
};
|
||||||
(name, type_ref)
|
(name, type_ref)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue