mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 01:04:03 +00:00
AdtDef -> Adt
This commit is contained in:
parent
75a87ec198
commit
7022ea52b5
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -1816,9 +1816,9 @@ checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c"
|
||||
|
||||
[[package]]
|
||||
name = "ungrammar"
|
||||
version = "1.10.0"
|
||||
version = "1.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ce24866975a8858d3a35eba845efc6b42962c5067afd2bc1a07b9ce0108d335c"
|
||||
checksum = "84c629795d377049f2a1dc5f42cf505dc5ba8b28a5df0a03f4183a24480e4a6a"
|
||||
|
||||
[[package]]
|
||||
name = "unicase"
|
||||
|
@ -26,7 +26,7 @@ pub(crate) fn add_lifetime_to_type(acc: &mut Assists, ctx: &AssistContext) -> Op
|
||||
return None;
|
||||
}
|
||||
|
||||
let node = ctx.find_node_at_offset::<ast::AdtDef>()?;
|
||||
let node = ctx.find_node_at_offset::<ast::Adt>()?;
|
||||
let has_lifetime = node
|
||||
.generic_param_list()
|
||||
.map(|gen_list| gen_list.lifetime_params().count() > 0)
|
||||
@ -66,9 +66,9 @@ pub(crate) fn add_lifetime_to_type(acc: &mut Assists, ctx: &AssistContext) -> Op
|
||||
)
|
||||
}
|
||||
|
||||
fn fetch_borrowed_types(node: &ast::AdtDef) -> Option<Vec<RefType>> {
|
||||
fn fetch_borrowed_types(node: &ast::Adt) -> Option<Vec<RefType>> {
|
||||
let ref_types: Vec<RefType> = match node {
|
||||
ast::AdtDef::Enum(enum_) => {
|
||||
ast::Adt::Enum(enum_) => {
|
||||
let variant_list = enum_.variant_list()?;
|
||||
variant_list
|
||||
.variants()
|
||||
@ -80,11 +80,11 @@ fn fetch_borrowed_types(node: &ast::AdtDef) -> Option<Vec<RefType>> {
|
||||
.flatten()
|
||||
.collect()
|
||||
}
|
||||
ast::AdtDef::Struct(strukt) => {
|
||||
ast::Adt::Struct(strukt) => {
|
||||
let field_list = strukt.field_list()?;
|
||||
find_ref_types_from_field_list(&field_list)?
|
||||
}
|
||||
ast::AdtDef::Union(un) => {
|
||||
ast::Adt::Union(un) => {
|
||||
let record_field_list = un.record_field_list()?;
|
||||
record_field_list
|
||||
.fields()
|
||||
|
@ -26,7 +26,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
|
||||
// ```
|
||||
pub(crate) fn generate_derive(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
|
||||
let cap = ctx.config.snippet_cap?;
|
||||
let nominal = ctx.find_node_at_offset::<ast::AdtDef>()?;
|
||||
let nominal = ctx.find_node_at_offset::<ast::Adt>()?;
|
||||
let node_start = derive_insertion_offset(&nominal)?;
|
||||
let target = nominal.syntax().text_range();
|
||||
acc.add(
|
||||
@ -58,7 +58,7 @@ pub(crate) fn generate_derive(acc: &mut Assists, ctx: &AssistContext) -> Option<
|
||||
}
|
||||
|
||||
// Insert `derive` after doc comments.
|
||||
fn derive_insertion_offset(nominal: &ast::AdtDef) -> Option<TextSize> {
|
||||
fn derive_insertion_offset(nominal: &ast::Adt) -> Option<TextSize> {
|
||||
let non_ws_child = nominal
|
||||
.syntax()
|
||||
.children_with_tokens()
|
||||
|
@ -49,7 +49,7 @@ pub(crate) fn generate_enum_match_method(acc: &mut Assists, ctx: &AssistContext)
|
||||
// Return early if we've found an existing new fn
|
||||
let impl_def = find_struct_impl(
|
||||
&ctx,
|
||||
&ast::AdtDef::Enum(parent_enum.clone()),
|
||||
&ast::Adt::Enum(parent_enum.clone()),
|
||||
format!("is_{}", fn_name).as_str(),
|
||||
)?;
|
||||
|
||||
|
@ -27,7 +27,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
|
||||
// }
|
||||
// ```
|
||||
pub(crate) fn generate_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
|
||||
let nominal = ctx.find_node_at_offset::<ast::AdtDef>()?;
|
||||
let nominal = ctx.find_node_at_offset::<ast::Adt>()?;
|
||||
let name = nominal.name()?;
|
||||
let target = nominal.syntax().text_range();
|
||||
|
||||
|
@ -40,7 +40,7 @@ pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
|
||||
};
|
||||
|
||||
// Return early if we've found an existing new fn
|
||||
let impl_def = find_struct_impl(&ctx, &ast::AdtDef::Struct(strukt.clone()), "new")?;
|
||||
let impl_def = find_struct_impl(&ctx, &ast::Adt::Struct(strukt.clone()), "new")?;
|
||||
|
||||
let target = strukt.syntax().text_range();
|
||||
acc.add(AssistId("generate_new", AssistKind::Generate), "Generate `new`", target, |builder| {
|
||||
|
@ -281,7 +281,7 @@ pub(crate) fn does_pat_match_variant(pat: &ast::Pat, var: &ast::Pat) -> bool {
|
||||
// FIXME: this partially overlaps with `find_impl_block`
|
||||
pub(crate) fn find_struct_impl(
|
||||
ctx: &AssistContext,
|
||||
strukt: &ast::AdtDef,
|
||||
strukt: &ast::Adt,
|
||||
name: &str,
|
||||
) -> Option<Option<ast::Impl>> {
|
||||
let db = ctx.db();
|
||||
@ -290,9 +290,9 @@ pub(crate) fn find_struct_impl(
|
||||
})?;
|
||||
|
||||
let struct_def = match strukt {
|
||||
ast::AdtDef::Enum(e) => Adt::Enum(ctx.sema.to_def(e)?),
|
||||
ast::AdtDef::Struct(s) => Adt::Struct(ctx.sema.to_def(s)?),
|
||||
ast::AdtDef::Union(u) => Adt::Union(ctx.sema.to_def(u)?),
|
||||
ast::Adt::Enum(e) => Adt::Enum(ctx.sema.to_def(e)?),
|
||||
ast::Adt::Struct(s) => Adt::Struct(ctx.sema.to_def(s)?),
|
||||
ast::Adt::Union(u) => Adt::Union(ctx.sema.to_def(u)?),
|
||||
};
|
||||
|
||||
let block = module.descendants().filter_map(ast::Impl::cast).find_map(|impl_blk| {
|
||||
|
@ -23,7 +23,7 @@ pub(crate) fn goto_implementation(
|
||||
|
||||
let krate = sema.to_module_def(position.file_id)?.krate();
|
||||
|
||||
if let Some(nominal_def) = find_node_at_offset::<ast::AdtDef>(&syntax, position.offset) {
|
||||
if let Some(nominal_def) = find_node_at_offset::<ast::Adt>(&syntax, position.offset) {
|
||||
return Some(RangeInfo::new(
|
||||
nominal_def.syntax().text_range(),
|
||||
impls_for_def(&sema, &nominal_def, krate)?,
|
||||
@ -40,13 +40,13 @@ pub(crate) fn goto_implementation(
|
||||
|
||||
fn impls_for_def(
|
||||
sema: &Semantics<RootDatabase>,
|
||||
node: &ast::AdtDef,
|
||||
node: &ast::Adt,
|
||||
krate: Crate,
|
||||
) -> Option<Vec<NavigationTarget>> {
|
||||
let ty = match node {
|
||||
ast::AdtDef::Struct(def) => sema.to_def(def)?.ty(sema.db),
|
||||
ast::AdtDef::Enum(def) => sema.to_def(def)?.ty(sema.db),
|
||||
ast::AdtDef::Union(def) => sema.to_def(def)?.ty(sema.db),
|
||||
ast::Adt::Struct(def) => sema.to_def(def)?.ty(sema.db),
|
||||
ast::Adt::Enum(def) => sema.to_def(def)?.ty(sema.db),
|
||||
ast::Adt::Union(def) => sema.to_def(def)?.ty(sema.db),
|
||||
};
|
||||
|
||||
let impls = Impl::all_in_crate(sema.db, krate);
|
||||
|
@ -1401,15 +1401,15 @@ pub enum FieldList {
|
||||
TupleFieldList(TupleFieldList),
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum AdtDef {
|
||||
pub enum Adt {
|
||||
Enum(Enum),
|
||||
Struct(Struct),
|
||||
Union(Union),
|
||||
}
|
||||
impl ast::AttrsOwner for AdtDef {}
|
||||
impl ast::GenericParamsOwner for AdtDef {}
|
||||
impl ast::NameOwner for AdtDef {}
|
||||
impl ast::VisibilityOwner for AdtDef {}
|
||||
impl ast::AttrsOwner for Adt {}
|
||||
impl ast::GenericParamsOwner for Adt {}
|
||||
impl ast::NameOwner for Adt {}
|
||||
impl ast::VisibilityOwner for Adt {}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum AssocItem {
|
||||
Const(Const),
|
||||
@ -3394,16 +3394,16 @@ impl AstNode for FieldList {
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<Enum> for AdtDef {
|
||||
fn from(node: Enum) -> AdtDef { AdtDef::Enum(node) }
|
||||
impl From<Enum> for Adt {
|
||||
fn from(node: Enum) -> Adt { Adt::Enum(node) }
|
||||
}
|
||||
impl From<Struct> for AdtDef {
|
||||
fn from(node: Struct) -> AdtDef { AdtDef::Struct(node) }
|
||||
impl From<Struct> for Adt {
|
||||
fn from(node: Struct) -> Adt { Adt::Struct(node) }
|
||||
}
|
||||
impl From<Union> for AdtDef {
|
||||
fn from(node: Union) -> AdtDef { AdtDef::Union(node) }
|
||||
impl From<Union> for Adt {
|
||||
fn from(node: Union) -> Adt { Adt::Union(node) }
|
||||
}
|
||||
impl AstNode for AdtDef {
|
||||
impl AstNode for Adt {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
ENUM | STRUCT | UNION => true,
|
||||
@ -3412,18 +3412,18 @@ impl AstNode for AdtDef {
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
let res = match syntax.kind() {
|
||||
ENUM => AdtDef::Enum(Enum { syntax }),
|
||||
STRUCT => AdtDef::Struct(Struct { syntax }),
|
||||
UNION => AdtDef::Union(Union { syntax }),
|
||||
ENUM => Adt::Enum(Enum { syntax }),
|
||||
STRUCT => Adt::Struct(Struct { syntax }),
|
||||
UNION => Adt::Union(Union { syntax }),
|
||||
_ => return None,
|
||||
};
|
||||
Some(res)
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
match self {
|
||||
AdtDef::Enum(it) => &it.syntax,
|
||||
AdtDef::Struct(it) => &it.syntax,
|
||||
AdtDef::Union(it) => &it.syntax,
|
||||
Adt::Enum(it) => &it.syntax,
|
||||
Adt::Struct(it) => &it.syntax,
|
||||
Adt::Union(it) => &it.syntax,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3571,7 +3571,7 @@ impl std::fmt::Display for FieldList {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for AdtDef {
|
||||
impl std::fmt::Display for Adt {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user