mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 11:59:49 +00:00
rename flavor to kind
This commit is contained in:
parent
cb5001c0a5
commit
0e1e40676a
6 changed files with 53 additions and 53 deletions
|
@ -6,7 +6,7 @@ use std::sync::Arc;
|
||||||
use ra_arena::{RawId, Arena, impl_arena_id};
|
use ra_arena::{RawId, Arena, impl_arena_id};
|
||||||
use ra_syntax::{
|
use ra_syntax::{
|
||||||
TreeArc,
|
TreeArc,
|
||||||
ast::{self, NameOwner, StructFlavor, TypeAscriptionOwner}
|
ast::{self, NameOwner, StructKind, TypeAscriptionOwner}
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -47,7 +47,7 @@ pub struct StructData {
|
||||||
impl StructData {
|
impl StructData {
|
||||||
fn new(struct_def: &ast::StructDef) -> StructData {
|
fn new(struct_def: &ast::StructDef) -> StructData {
|
||||||
let name = struct_def.name().map(|n| n.as_name());
|
let name = struct_def.name().map(|n| n.as_name());
|
||||||
let variant_data = VariantData::new(struct_def.flavor());
|
let variant_data = VariantData::new(struct_def.kind());
|
||||||
let variant_data = Arc::new(variant_data);
|
let variant_data = Arc::new(variant_data);
|
||||||
StructData { name, variant_data }
|
StructData { name, variant_data }
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ impl EnumData {
|
||||||
let variants = variants(&*enum_def)
|
let variants = variants(&*enum_def)
|
||||||
.map(|var| EnumVariantData {
|
.map(|var| EnumVariantData {
|
||||||
name: var.name().map(|it| it.as_name()),
|
name: var.name().map(|it| it.as_name()),
|
||||||
variant_data: Arc::new(VariantData::new(var.flavor())),
|
variant_data: Arc::new(VariantData::new(var.kind())),
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
Arc::new(EnumData { name, variants })
|
Arc::new(EnumData { name, variants })
|
||||||
|
@ -143,9 +143,9 @@ impl VariantData {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VariantData {
|
impl VariantData {
|
||||||
fn new(flavor: StructFlavor) -> Self {
|
fn new(flavor: StructKind) -> Self {
|
||||||
let inner = match flavor {
|
let inner = match flavor {
|
||||||
ast::StructFlavor::Tuple(fl) => {
|
ast::StructKind::Tuple(fl) => {
|
||||||
let fields = fl
|
let fields = fl
|
||||||
.fields()
|
.fields()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
|
@ -156,7 +156,7 @@ impl VariantData {
|
||||||
.collect();
|
.collect();
|
||||||
VariantDataInner::Tuple(fields)
|
VariantDataInner::Tuple(fields)
|
||||||
}
|
}
|
||||||
ast::StructFlavor::Named(fl) => {
|
ast::StructKind::Named(fl) => {
|
||||||
let fields = fl
|
let fields = fl
|
||||||
.fields()
|
.fields()
|
||||||
.map(|fd| StructFieldData {
|
.map(|fd| StructFieldData {
|
||||||
|
@ -166,7 +166,7 @@ impl VariantData {
|
||||||
.collect();
|
.collect();
|
||||||
VariantDataInner::Struct(fields)
|
VariantDataInner::Struct(fields)
|
||||||
}
|
}
|
||||||
ast::StructFlavor::Unit => VariantDataInner::Unit,
|
ast::StructKind::Unit => VariantDataInner::Unit,
|
||||||
};
|
};
|
||||||
VariantData(inner)
|
VariantData(inner)
|
||||||
}
|
}
|
||||||
|
@ -200,27 +200,27 @@ impl StructField {
|
||||||
let fields = var_data.fields().unwrap();
|
let fields = var_data.fields().unwrap();
|
||||||
let ss;
|
let ss;
|
||||||
let es;
|
let es;
|
||||||
let (file_id, struct_flavor) = match self.parent {
|
let (file_id, struct_kind) = match self.parent {
|
||||||
VariantDef::Struct(s) => {
|
VariantDef::Struct(s) => {
|
||||||
let (file_id, source) = s.source(db);
|
let (file_id, source) = s.source(db);
|
||||||
ss = source;
|
ss = source;
|
||||||
(file_id, ss.flavor())
|
(file_id, ss.kind())
|
||||||
}
|
}
|
||||||
VariantDef::EnumVariant(e) => {
|
VariantDef::EnumVariant(e) => {
|
||||||
let (file_id, source) = e.source(db);
|
let (file_id, source) = e.source(db);
|
||||||
es = source;
|
es = source;
|
||||||
(file_id, es.flavor())
|
(file_id, es.kind())
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let field_sources = match struct_flavor {
|
let field_sources = match struct_kind {
|
||||||
ast::StructFlavor::Tuple(fl) => {
|
ast::StructKind::Tuple(fl) => {
|
||||||
fl.fields().map(|it| FieldSource::Pos(it.to_owned())).collect()
|
fl.fields().map(|it| FieldSource::Pos(it.to_owned())).collect()
|
||||||
}
|
}
|
||||||
ast::StructFlavor::Named(fl) => {
|
ast::StructKind::Named(fl) => {
|
||||||
fl.fields().map(|it| FieldSource::Named(it.to_owned())).collect()
|
fl.fields().map(|it| FieldSource::Named(it.to_owned())).collect()
|
||||||
}
|
}
|
||||||
ast::StructFlavor::Unit => Vec::new(),
|
ast::StructKind::Unit => Vec::new(),
|
||||||
};
|
};
|
||||||
let field = field_sources
|
let field = field_sources
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|
|
@ -20,12 +20,12 @@ impl FnSignature {
|
||||||
TypeRef::from_ast(type_ref)
|
TypeRef::from_ast(type_ref)
|
||||||
} else {
|
} else {
|
||||||
let self_type = TypeRef::Path(Name::self_type().into());
|
let self_type = TypeRef::Path(Name::self_type().into());
|
||||||
match self_param.flavor() {
|
match self_param.kind() {
|
||||||
ast::SelfParamFlavor::Owned => self_type,
|
ast::SelfParamKind::Owned => self_type,
|
||||||
ast::SelfParamFlavor::Ref => {
|
ast::SelfParamKind::Ref => {
|
||||||
TypeRef::Reference(Box::new(self_type), Mutability::Shared)
|
TypeRef::Reference(Box::new(self_type), Mutability::Shared)
|
||||||
}
|
}
|
||||||
ast::SelfParamFlavor::MutRef => {
|
ast::SelfParamKind::MutRef => {
|
||||||
TypeRef::Reference(Box::new(self_type), Mutability::Mut)
|
TypeRef::Reference(Box::new(self_type), Mutability::Mut)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ use rustc_hash::FxHashMap;
|
||||||
use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap};
|
use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap};
|
||||||
use ra_syntax::{
|
use ra_syntax::{
|
||||||
SyntaxNodePtr, AstPtr, AstNode,
|
SyntaxNodePtr, AstPtr, AstNode,
|
||||||
ast::{self, LoopBodyOwner, ArgListOwner, NameOwner, LiteralFlavor, TypeAscriptionOwner}
|
ast::{self, LoopBodyOwner, ArgListOwner, NameOwner, LiteralKind, TypeAscriptionOwner}
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -726,8 +726,8 @@ impl ExprCollector {
|
||||||
self.alloc_expr(Expr::Array { exprs }, syntax_ptr)
|
self.alloc_expr(Expr::Array { exprs }, syntax_ptr)
|
||||||
}
|
}
|
||||||
ast::ExprKind::Literal(e) => {
|
ast::ExprKind::Literal(e) => {
|
||||||
let lit = match e.flavor() {
|
let lit = match e.kind() {
|
||||||
LiteralFlavor::IntNumber { suffix } => {
|
LiteralKind::IntNumber { suffix } => {
|
||||||
let known_name = suffix
|
let known_name = suffix
|
||||||
.and_then(|it| IntTy::from_suffix(&it).map(UncertainIntTy::Known));
|
.and_then(|it| IntTy::from_suffix(&it).map(UncertainIntTy::Known));
|
||||||
|
|
||||||
|
@ -736,7 +736,7 @@ impl ExprCollector {
|
||||||
known_name.unwrap_or(UncertainIntTy::Unknown),
|
known_name.unwrap_or(UncertainIntTy::Unknown),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
LiteralFlavor::FloatNumber { suffix } => {
|
LiteralKind::FloatNumber { suffix } => {
|
||||||
let known_name = suffix
|
let known_name = suffix
|
||||||
.and_then(|it| FloatTy::from_suffix(&it).map(UncertainFloatTy::Known));
|
.and_then(|it| FloatTy::from_suffix(&it).map(UncertainFloatTy::Known));
|
||||||
|
|
||||||
|
@ -745,13 +745,13 @@ impl ExprCollector {
|
||||||
known_name.unwrap_or(UncertainFloatTy::Unknown),
|
known_name.unwrap_or(UncertainFloatTy::Unknown),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
LiteralFlavor::ByteString => Literal::ByteString(Default::default()),
|
LiteralKind::ByteString => Literal::ByteString(Default::default()),
|
||||||
LiteralFlavor::String => Literal::String(Default::default()),
|
LiteralKind::String => Literal::String(Default::default()),
|
||||||
LiteralFlavor::Byte => {
|
LiteralKind::Byte => {
|
||||||
Literal::Int(Default::default(), UncertainIntTy::Known(IntTy::u8()))
|
Literal::Int(Default::default(), UncertainIntTy::Known(IntTy::u8()))
|
||||||
}
|
}
|
||||||
LiteralFlavor::Bool => Literal::Bool(Default::default()),
|
LiteralKind::Bool => Literal::Bool(Default::default()),
|
||||||
LiteralFlavor::Char => Literal::Char(Default::default()),
|
LiteralKind::Char => Literal::Char(Default::default()),
|
||||||
};
|
};
|
||||||
self.alloc_expr(Expr::Literal(lit), syntax_ptr)
|
self.alloc_expr(Expr::Literal(lit), syntax_ptr)
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,8 @@ pub use self::{
|
||||||
generated::*,
|
generated::*,
|
||||||
traits::*,
|
traits::*,
|
||||||
tokens::*,
|
tokens::*,
|
||||||
extensions::{PathSegmentKind, StructFlavor, SelfParamFlavor},
|
extensions::{PathSegmentKind, StructKind, SelfParamKind},
|
||||||
expr_extensions::{ElseBranch, PrefixOp, BinOp, LiteralFlavor},
|
expr_extensions::{ElseBranch, PrefixOp, BinOp, LiteralKind},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The main trait to go from untyped `SyntaxNode` to a typed ast. The
|
/// The main trait to go from untyped `SyntaxNode` to a typed ast. The
|
||||||
|
|
|
@ -192,7 +192,7 @@ impl ast::BinExpr {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
pub enum LiteralFlavor {
|
pub enum LiteralKind {
|
||||||
String,
|
String,
|
||||||
ByteString,
|
ByteString,
|
||||||
Char,
|
Char,
|
||||||
|
@ -210,7 +210,7 @@ impl ast::Literal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn flavor(&self) -> LiteralFlavor {
|
pub fn kind(&self) -> LiteralKind {
|
||||||
match self.token().kind() {
|
match self.token().kind() {
|
||||||
INT_NUMBER => {
|
INT_NUMBER => {
|
||||||
let allowed_suffix_list = [
|
let allowed_suffix_list = [
|
||||||
|
@ -222,7 +222,7 @@ impl ast::Literal {
|
||||||
.iter()
|
.iter()
|
||||||
.find(|&s| text.ends_with(s))
|
.find(|&s| text.ends_with(s))
|
||||||
.map(|&suf| SmolStr::new(suf));
|
.map(|&suf| SmolStr::new(suf));
|
||||||
LiteralFlavor::IntNumber { suffix }
|
LiteralKind::IntNumber { suffix }
|
||||||
}
|
}
|
||||||
FLOAT_NUMBER => {
|
FLOAT_NUMBER => {
|
||||||
let allowed_suffix_list = ["f64", "f32"];
|
let allowed_suffix_list = ["f64", "f32"];
|
||||||
|
@ -231,13 +231,13 @@ impl ast::Literal {
|
||||||
.iter()
|
.iter()
|
||||||
.find(|&s| text.ends_with(s))
|
.find(|&s| text.ends_with(s))
|
||||||
.map(|&suf| SmolStr::new(suf));
|
.map(|&suf| SmolStr::new(suf));
|
||||||
LiteralFlavor::FloatNumber { suffix: suffix }
|
LiteralKind::FloatNumber { suffix: suffix }
|
||||||
}
|
}
|
||||||
STRING | RAW_STRING => LiteralFlavor::String,
|
STRING | RAW_STRING => LiteralKind::String,
|
||||||
TRUE_KW | FALSE_KW => LiteralFlavor::Bool,
|
TRUE_KW | FALSE_KW => LiteralKind::Bool,
|
||||||
BYTE_STRING | RAW_BYTE_STRING => LiteralFlavor::ByteString,
|
BYTE_STRING | RAW_BYTE_STRING => LiteralKind::ByteString,
|
||||||
CHAR => LiteralFlavor::Char,
|
CHAR => LiteralKind::Char,
|
||||||
BYTE => LiteralFlavor::Byte,
|
BYTE => LiteralKind::Byte,
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,27 +159,27 @@ impl ast::ImplBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub enum StructFlavor<'a> {
|
pub enum StructKind<'a> {
|
||||||
Tuple(&'a ast::PosFieldDefList),
|
Tuple(&'a ast::PosFieldDefList),
|
||||||
Named(&'a ast::NamedFieldDefList),
|
Named(&'a ast::NamedFieldDefList),
|
||||||
Unit,
|
Unit,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StructFlavor<'_> {
|
impl StructKind<'_> {
|
||||||
fn from_node<N: AstNode>(node: &N) -> StructFlavor {
|
fn from_node<N: AstNode>(node: &N) -> StructKind {
|
||||||
if let Some(nfdl) = child_opt::<_, ast::NamedFieldDefList>(node) {
|
if let Some(nfdl) = child_opt::<_, ast::NamedFieldDefList>(node) {
|
||||||
StructFlavor::Named(nfdl)
|
StructKind::Named(nfdl)
|
||||||
} else if let Some(pfl) = child_opt::<_, ast::PosFieldDefList>(node) {
|
} else if let Some(pfl) = child_opt::<_, ast::PosFieldDefList>(node) {
|
||||||
StructFlavor::Tuple(pfl)
|
StructKind::Tuple(pfl)
|
||||||
} else {
|
} else {
|
||||||
StructFlavor::Unit
|
StructKind::Unit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ast::StructDef {
|
impl ast::StructDef {
|
||||||
pub fn flavor(&self) -> StructFlavor {
|
pub fn kind(&self) -> StructKind {
|
||||||
StructFlavor::from_node(self)
|
StructKind::from_node(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,8 +191,8 @@ impl ast::EnumVariant {
|
||||||
.and_then(ast::EnumDef::cast)
|
.and_then(ast::EnumDef::cast)
|
||||||
.expect("EnumVariants are always nested in Enums")
|
.expect("EnumVariants are always nested in Enums")
|
||||||
}
|
}
|
||||||
pub fn flavor(&self) -> StructFlavor {
|
pub fn kind(&self) -> StructKind {
|
||||||
StructFlavor::from_node(self)
|
StructKind::from_node(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,7 +243,7 @@ impl ast::ReferenceType {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
pub enum SelfParamFlavor {
|
pub enum SelfParamKind {
|
||||||
/// self
|
/// self
|
||||||
Owned,
|
Owned,
|
||||||
/// &self
|
/// &self
|
||||||
|
@ -261,7 +261,7 @@ impl ast::SelfParam {
|
||||||
.expect("invalid tree: self param must have self")
|
.expect("invalid tree: self param must have self")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn flavor(&self) -> SelfParamFlavor {
|
pub fn kind(&self) -> SelfParamKind {
|
||||||
let borrowed = self.syntax().children_with_tokens().any(|n| n.kind() == AMP);
|
let borrowed = self.syntax().children_with_tokens().any(|n| n.kind() == AMP);
|
||||||
if borrowed {
|
if borrowed {
|
||||||
// check for a `mut` coming after the & -- `mut &self` != `&mut self`
|
// check for a `mut` coming after the & -- `mut &self` != `&mut self`
|
||||||
|
@ -271,12 +271,12 @@ impl ast::SelfParam {
|
||||||
.skip_while(|n| n.kind() != AMP)
|
.skip_while(|n| n.kind() != AMP)
|
||||||
.any(|n| n.kind() == MUT_KW)
|
.any(|n| n.kind() == MUT_KW)
|
||||||
{
|
{
|
||||||
SelfParamFlavor::MutRef
|
SelfParamKind::MutRef
|
||||||
} else {
|
} else {
|
||||||
SelfParamFlavor::Ref
|
SelfParamKind::Ref
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
SelfParamFlavor::Owned
|
SelfParamKind::Owned
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue