Rename ast::ImplBlock -> ast::ImplDef

This commit is contained in:
Aleksey Kladov 2020-02-29 21:24:40 +01:00
parent f316e074d2
commit a1e1869554
68 changed files with 216 additions and 224 deletions

View file

@ -40,9 +40,9 @@ impl<'a> SubstituteTypeParams<'a> {
db: &'a RootDatabase,
// FIXME: there's implicit invariant that `trait_` and `source_scope` match...
trait_: hir::Trait,
impl_block: ast::ImplBlock,
impl_def: ast::ImplDef,
) -> SubstituteTypeParams<'a> {
let substs = get_syntactic_substs(impl_block).unwrap_or_default();
let substs = get_syntactic_substs(impl_def).unwrap_or_default();
let generic_def: hir::GenericDef = trait_.into();
let substs_by_param: FxHashMap<_, _> = generic_def
.params(db)
@ -59,8 +59,8 @@ impl<'a> SubstituteTypeParams<'a> {
// FIXME: It would probably be nicer if we could get this via HIR (i.e. get the
// trait ref, and then go from the types in the substs back to the syntax)
fn get_syntactic_substs(impl_block: ast::ImplBlock) -> Option<Vec<ast::TypeRef>> {
let target_trait = impl_block.target_trait()?;
fn get_syntactic_substs(impl_def: ast::ImplDef) -> Option<Vec<ast::TypeRef>> {
let target_trait = impl_def.target_trait()?;
let path_type = match target_trait {
ast::TypeRef::PathType(path) => path,
_ => return None,

View file

@ -101,7 +101,7 @@ fn add_missing_impl_members_inner(
label: &'static str,
) -> Option<Assist> {
let _p = ra_prof::profile("add_missing_impl_members_inner");
let impl_node = ctx.find_node_at_offset::<ast::ImplBlock>()?;
let impl_node = ctx.find_node_at_offset::<ast::ImplDef>()?;
let impl_item_list = impl_node.item_list()?;
let trait_ = resolve_target_trait(&ctx.sema, &impl_node)?;
@ -257,7 +257,7 @@ impl Foo for S {
}
#[test]
fn test_empty_impl_block() {
fn test_empty_impl_def() {
check_assist(
add_missing_impl_members,
"
@ -308,7 +308,7 @@ impl<U> Foo<U> for S {
}
#[test]
fn test_cursor_after_empty_impl_block() {
fn test_cursor_after_empty_impl_def() {
check_assist(
add_missing_impl_members,
"

View file

@ -41,14 +41,14 @@ pub(crate) fn add_new(ctx: AssistCtx) -> Option<Assist> {
};
// Return early if we've found an existing new fn
let impl_block = find_struct_impl(&ctx, &strukt)?;
let impl_def = find_struct_impl(&ctx, &strukt)?;
ctx.add_assist(AssistId("add_new"), "Add default constructor", |edit| {
edit.target(strukt.syntax().text_range());
let mut buf = String::with_capacity(512);
if impl_block.is_some() {
if impl_def.is_some() {
buf.push('\n');
}
@ -71,10 +71,10 @@ pub(crate) fn add_new(ctx: AssistCtx) -> Option<Assist> {
buf.push_str("} }");
let (start_offset, end_offset) = impl_block
.and_then(|impl_block| {
let (start_offset, end_offset) = impl_def
.and_then(|impl_def| {
buf.push('\n');
let start = impl_block
let start = impl_def
.syntax()
.descendants_with_tokens()
.find(|t| t.kind() == T!['{'])?
@ -128,7 +128,7 @@ fn generate_impl_text(strukt: &ast::StructDef, code: &str) -> String {
//
// FIXME: change the new fn checking to a more semantic approach when that's more
// viable (e.g. we process proc macros, etc)
fn find_struct_impl(ctx: &AssistCtx, strukt: &ast::StructDef) -> Option<Option<ast::ImplBlock>> {
fn find_struct_impl(ctx: &AssistCtx, strukt: &ast::StructDef) -> Option<Option<ast::ImplDef>> {
let db = ctx.db;
let module = strukt.syntax().ancestors().find(|node| {
ast::Module::can_cast(node.kind()) || ast::SourceFile::can_cast(node.kind())
@ -136,7 +136,7 @@ fn find_struct_impl(ctx: &AssistCtx, strukt: &ast::StructDef) -> Option<Option<a
let struct_def = ctx.sema.to_def(strukt)?;
let block = module.descendants().filter_map(ast::ImplBlock::cast).find_map(|impl_blk| {
let block = module.descendants().filter_map(ast::ImplDef::cast).find_map(|impl_blk| {
let blk = ctx.sema.to_def(&impl_blk)?;
// FIXME: handle e.g. `struct S<T>; impl<U> S<U> {}`
@ -164,7 +164,7 @@ fn find_struct_impl(ctx: &AssistCtx, strukt: &ast::StructDef) -> Option<Option<a
Some(block)
}
fn has_new_fn(imp: &ast::ImplBlock) -> bool {
fn has_new_fn(imp: &ast::ImplDef) -> bool {
if let Some(il) = imp.item_list() {
for item in il.impl_items() {
if let ast::ImplItem::FnDef(f) = item {

View file

@ -37,7 +37,7 @@ pub(crate) fn move_bounds_to_where_clause(ctx: AssistCtx) -> Option<Assist> {
let anchor: SyntaxElement = match parent.kind() {
FN_DEF => ast::FnDef::cast(parent)?.body()?.syntax().clone().into(),
TRAIT_DEF => ast::TraitDef::cast(parent)?.item_list()?.syntax().clone().into(),
IMPL_BLOCK => ast::ImplBlock::cast(parent)?.item_list()?.syntax().clone().into(),
IMPL_DEF => ast::ImplDef::cast(parent)?.item_list()?.syntax().clone().into(),
ENUM_DEF => ast::EnumDef::cast(parent)?.variant_list()?.syntax().clone().into(),
STRUCT_DEF => parent
.children_with_tokens()

View file

@ -13,14 +13,14 @@ pub use insert_use::insert_use_statement;
pub fn get_missing_impl_items(
sema: &Semantics<RootDatabase>,
impl_block: &ast::ImplBlock,
impl_def: &ast::ImplDef,
) -> Vec<hir::AssocItem> {
// Names must be unique between constants and functions. However, type aliases
// may share the same name as a function or constant.
let mut impl_fns_consts = FxHashSet::default();
let mut impl_type = FxHashSet::default();
if let Some(item_list) = impl_block.item_list() {
if let Some(item_list) = impl_def.item_list() {
for item in item_list.impl_items() {
match item {
ast::ImplItem::FnDef(f) => {
@ -44,7 +44,7 @@ pub fn get_missing_impl_items(
}
}
resolve_target_trait(sema, impl_block).map_or(vec![], |target_trait| {
resolve_target_trait(sema, impl_def).map_or(vec![], |target_trait| {
target_trait
.items(sema.db)
.iter()
@ -65,9 +65,9 @@ pub fn get_missing_impl_items(
pub(crate) fn resolve_target_trait(
sema: &Semantics<RootDatabase>,
impl_block: &ast::ImplBlock,
impl_def: &ast::ImplDef,
) -> Option<hir::Trait> {
let ast_path = impl_block
let ast_path = impl_def
.target_trait()
.map(|it| it.syntax().clone())
.and_then(ast::PathType::cast)?

View file

@ -229,8 +229,8 @@ impl Module {
}
}
for impl_block in self.impl_blocks(db) {
for item in impl_block.items(db) {
for impl_def in self.impl_defs(db) {
for item in impl_def.items(db) {
if let AssocItem::Function(f) = item {
f.diagnostics(db, sink);
}
@ -243,9 +243,9 @@ impl Module {
def_map[self.id.local_id].scope.declarations().map(ModuleDef::from).collect()
}
pub fn impl_blocks(self, db: &impl DefDatabase) -> Vec<ImplBlock> {
pub fn impl_defs(self, db: &impl DefDatabase) -> Vec<ImplDef> {
let def_map = db.crate_def_map(self.id.krate);
def_map[self.id.local_id].scope.impls().map(ImplBlock::from).collect()
def_map[self.id.local_id].scope.impls().map(ImplDef::from).collect()
}
pub(crate) fn with_module_id(self, module_id: LocalModuleId) -> Module {
@ -686,7 +686,7 @@ pub enum AssocItem {
}
pub enum AssocItemContainer {
Trait(Trait),
ImplBlock(ImplBlock),
ImplDef(ImplDef),
}
pub trait AsAssocItem {
fn as_assoc_item(self, db: &impl DefDatabase) -> Option<AssocItem>;
@ -736,7 +736,7 @@ impl AssocItem {
};
match container {
AssocContainerId::TraitId(id) => AssocItemContainer::Trait(id.into()),
AssocContainerId::ImplId(id) => AssocItemContainer::ImplBlock(id.into()),
AssocContainerId::ImplId(id) => AssocItemContainer::ImplDef(id.into()),
AssocContainerId::ContainerId(_) => panic!("invalid AssocItem"),
}
}
@ -748,7 +748,7 @@ pub enum GenericDef {
Adt(Adt),
Trait(Trait),
TypeAlias(TypeAlias),
ImplBlock(ImplBlock),
ImplDef(ImplDef),
// enum variants cannot have generics themselves, but their parent enums
// can, and this makes some code easier to write
EnumVariant(EnumVariant),
@ -760,7 +760,7 @@ impl_froms!(
Adt(Struct, Enum, Union),
Trait,
TypeAlias,
ImplBlock,
ImplDef,
EnumVariant,
Const
);
@ -850,20 +850,20 @@ impl TypeParam {
}
}
// FIXME: rename from `ImplBlock` to `Impl`
// FIXME: rename from `ImplDef` to `Impl`
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ImplBlock {
pub struct ImplDef {
pub(crate) id: ImplId,
}
impl ImplBlock {
pub fn all_in_crate(db: &impl HirDatabase, krate: Crate) -> Vec<ImplBlock> {
impl ImplDef {
pub fn all_in_crate(db: &impl HirDatabase, krate: Crate) -> Vec<ImplDef> {
let impls = db.impls_in_crate(krate.id);
impls.all_impls().map(Self::from).collect()
}
pub fn for_trait(db: &impl HirDatabase, krate: Crate, trait_: Trait) -> Vec<ImplBlock> {
pub fn for_trait(db: &impl HirDatabase, krate: Crate, trait_: Trait) -> Vec<ImplDef> {
let impls = db.impls_in_crate(krate.id);
impls.lookup_impl_blocks_for_trait(trait_.id).map(Self::from).collect()
impls.lookup_impl_defs_for_trait(trait_.id).map(Self::from).collect()
}
pub fn target_trait(&self, db: &impl DefDatabase) -> Option<TypeRef> {
@ -1077,7 +1077,7 @@ impl Type {
}
// This would be nicer if it just returned an iterator, but that runs into
// lifetime problems, because we need to borrow temp `CrateImplBlocks`.
// lifetime problems, because we need to borrow temp `CrateImplDefs`.
pub fn iterate_impl_items<T>(
self,
db: &impl HirDatabase,
@ -1087,8 +1087,8 @@ impl Type {
for krate in self.ty.value.def_crates(db, krate.id)? {
let impls = db.impls_in_crate(krate);
for impl_block in impls.lookup_impl_blocks(&self.ty.value) {
for &item in db.impl_data(impl_block).items.iter() {
for impl_def in impls.lookup_impl_defs(&self.ty.value) {
for &item in db.impl_data(impl_def).items.iter() {
if let Some(result) = callback(item.into()) {
return Some(result);
}
@ -1196,7 +1196,7 @@ pub enum ScopeDef {
ModuleDef(ModuleDef),
MacroDef(MacroDef),
GenericParam(TypeParam),
ImplSelfType(ImplBlock),
ImplSelfType(ImplDef),
AdtSelfType(Adt),
Local(Local),
Unknown,

View file

@ -39,7 +39,7 @@ from_id![
(hir_def::StaticId, crate::Static),
(hir_def::ConstId, crate::Const),
(hir_def::FunctionId, crate::Function),
(hir_def::ImplId, crate::ImplBlock),
(hir_def::ImplId, crate::ImplDef),
(hir_def::TypeParamId, crate::TypeParam),
(hir_expand::MacroDefId, crate::MacroDef)
];
@ -145,7 +145,7 @@ impl From<GenericDef> for GenericDefId {
GenericDef::Adt(it) => GenericDefId::AdtId(it.into()),
GenericDef::Trait(it) => GenericDefId::TraitId(it.id),
GenericDef::TypeAlias(it) => GenericDefId::TypeAliasId(it.id),
GenericDef::ImplBlock(it) => GenericDefId::ImplId(it.id),
GenericDef::ImplDef(it) => GenericDefId::ImplId(it.id),
GenericDef::EnumVariant(it) => {
GenericDefId::EnumVariantId(EnumVariantId { parent: it.parent.id, local_id: it.id })
}

View file

@ -9,7 +9,7 @@ use hir_def::{
use ra_syntax::ast;
use crate::{
db::DefDatabase, Const, Enum, EnumVariant, FieldSource, Function, ImplBlock, MacroDef, Module,
db::DefDatabase, Const, Enum, EnumVariant, FieldSource, Function, ImplDef, MacroDef, Module,
Static, Struct, StructField, Trait, TypeAlias, TypeParam, Union,
};
@ -111,9 +111,9 @@ impl HasSource for MacroDef {
}
}
}
impl HasSource for ImplBlock {
type Ast = ast::ImplBlock;
fn source(self, db: &impl DefDatabase) -> InFile<ast::ImplBlock> {
impl HasSource for ImplDef {
type Ast = ast::ImplDef;
fn source(self, db: &impl DefDatabase) -> InFile<ast::ImplDef> {
self.id.lookup(db).source(db)
}
}

View file

@ -41,7 +41,7 @@ pub use crate::{
code_model::{
Adt, AsAssocItem, AssocItem, AssocItemContainer, AttrDef, Const, Crate, CrateDependency,
DefWithBody, Docs, Enum, EnumVariant, FieldSource, Function, GenericDef, HasAttrs,
HasVisibility, ImplBlock, Local, MacroDef, Module, ModuleDef, ScopeDef, Static, Struct,
HasVisibility, ImplDef, Local, MacroDef, Module, ModuleDef, ScopeDef, Static, Struct,
StructField, Trait, Type, TypeAlias, TypeParam, Union, VariantDef,
},
has_source::HasSource,

View file

@ -262,7 +262,7 @@ to_def_impls![
(crate::Enum, ast::EnumDef, enum_to_def),
(crate::Union, ast::UnionDef, union_to_def),
(crate::Trait, ast::TraitDef, trait_to_def),
(crate::ImplBlock, ast::ImplBlock, impl_to_def),
(crate::ImplDef, ast::ImplDef, impl_to_def),
(crate::TypeAlias, ast::TypeAliasDef, type_alias_to_def),
(crate::Const, ast::ConstDef, const_to_def),
(crate::Static, ast::StaticDef, static_to_def),

View file

@ -67,7 +67,7 @@ impl<DB: HirDatabase> SourceToDefCtx<'_, &'_ DB> {
pub(super) fn trait_to_def(&mut self, src: InFile<ast::TraitDef>) -> Option<TraitId> {
self.to_def(src, keys::TRAIT)
}
pub(super) fn impl_to_def(&mut self, src: InFile<ast::ImplBlock>) -> Option<ImplId> {
pub(super) fn impl_to_def(&mut self, src: InFile<ast::ImplDef>) -> Option<ImplId> {
self.to_def(src, keys::IMPL)
}
pub(super) fn fn_to_def(&mut self, src: InFile<ast::FnDef>) -> Option<FunctionId> {
@ -166,7 +166,7 @@ impl<DB: HirDatabase> SourceToDefCtx<'_, &'_ DB> {
let def = self.trait_to_def(container.with_value(it))?;
def.into()
},
ast::ImplBlock(it) => {
ast::ImplDef(it) => {
let def = self.impl_to_def(container.with_value(it))?;
def.into()
},
@ -213,7 +213,7 @@ impl<DB: HirDatabase> SourceToDefCtx<'_, &'_ DB> {
ast::EnumDef(it) => { self.enum_to_def(container.with_value(it))?.into() },
ast::TraitDef(it) => { self.trait_to_def(container.with_value(it))?.into() },
ast::TypeAliasDef(it) => { self.type_alias_to_def(container.with_value(it))?.into() },
ast::ImplBlock(it) => { self.impl_to_def(container.with_value(it))?.into() },
ast::ImplDef(it) => { self.impl_to_def(container.with_value(it))?.into() },
_ => continue,
}
};

View file

@ -49,7 +49,7 @@ pub enum PathResolution {
Local(Local),
/// A generic parameter
TypeParam(TypeParam),
SelfType(crate::ImplBlock),
SelfType(crate::ImplDef),
Macro(MacroDef),
AssocItem(crate::AssocItem),
}

View file

@ -544,7 +544,7 @@ where
let ast_id = self.expander.ast_id(&def);
(TraitLoc { container, ast_id }.intern(self.db).into(), def.name())
}
ast::ModuleItem::ImplBlock(_)
ast::ModuleItem::ImplDef(_)
| ast::ModuleItem::UseItem(_)
| ast::ModuleItem::ExternCrateItem(_)
| ast::ModuleItem::Module(_) => continue,

View file

@ -238,16 +238,16 @@ impl ConstData {
fn collect_impl_items_in_macros(
db: &impl DefDatabase,
module_id: ModuleId,
impl_block: &InFile<ast::ItemList>,
impl_def: &InFile<ast::ItemList>,
id: ImplId,
) -> Vec<AssocItemId> {
let mut expander = Expander::new(db, impl_block.file_id, module_id);
let mut expander = Expander::new(db, impl_def.file_id, module_id);
let mut res = Vec::new();
// We set a limit to protect against infinite recursion
let limit = 100;
for m in impl_block.value.syntax().children().filter_map(ast::MacroCall::cast) {
for m in impl_def.value.syntax().children().filter_map(ast::MacroCall::cast) {
res.extend(collect_impl_items_in_macro(db, &mut expander, m, id, limit))
}

View file

@ -18,7 +18,7 @@ pub const FUNCTION: Key<ast::FnDef, FunctionId> = Key::new();
pub const CONST: Key<ast::ConstDef, ConstId> = Key::new();
pub const STATIC: Key<ast::StaticDef, StaticId> = Key::new();
pub const TYPE_ALIAS: Key<ast::TypeAliasDef, TypeAliasId> = Key::new();
pub const IMPL: Key<ast::ImplBlock, ImplId> = Key::new();
pub const IMPL: Key<ast::ImplDef, ImplId> = Key::new();
pub const TRAIT: Key<ast::TraitDef, TraitId> = Key::new();
pub const STRUCT: Key<ast::StructDef, StructId> = Key::new();
pub const UNION: Key<ast::UnionDef, UnionId> = Key::new();

View file

@ -16,7 +16,7 @@ use crate::{
pub enum LangItemTarget {
EnumId(EnumId),
FunctionId(FunctionId),
ImplBlockId(ImplId),
ImplDefId(ImplId),
StaticId(StaticId),
StructId(StructId),
TraitId(TraitId),
@ -37,9 +37,9 @@ impl LangItemTarget {
}
}
pub fn as_impl_block(self) -> Option<ImplId> {
pub fn as_impl_def(self) -> Option<ImplId> {
match self {
LangItemTarget::ImplBlockId(id) => Some(id),
LangItemTarget::ImplDefId(id) => Some(id),
_ => None,
}
}
@ -125,8 +125,8 @@ impl LangItems {
// Look for impl targets
let def_map = db.crate_def_map(module.krate);
let module_data = &def_map[module.local_id];
for impl_block in module_data.scope.impls() {
self.collect_lang_item(db, impl_block, LangItemTarget::ImplBlockId)
for impl_def in module_data.scope.impls() {
self.collect_lang_item(db, impl_def, LangItemTarget::ImplDefId)
}
for def in module_data.scope.declarations() {

View file

@ -164,7 +164,7 @@ impl_intern!(TypeAliasId, TypeAliasLoc, intern_type_alias, lookup_intern_type_al
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ImplId(salsa::InternId);
type ImplLoc = ItemLoc<ast::ImplBlock>;
type ImplLoc = ItemLoc<ast::ImplDef>;
impl_intern!(ImplId, ImplLoc, intern_impl, lookup_intern_impl);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]

View file

@ -213,7 +213,7 @@ impl_arena_id!(Impl);
#[derive(Debug, PartialEq, Eq)]
pub(super) struct ImplData {
pub(super) ast_id: FileAstId<ast::ImplBlock>,
pub(super) ast_id: FileAstId<ast::ImplDef>,
}
struct RawItemsCollector {
@ -249,7 +249,7 @@ impl RawItemsCollector {
self.add_extern_crate_item(current_module, extern_crate);
return;
}
ast::ModuleItem::ImplBlock(it) => {
ast::ModuleItem::ImplDef(it) => {
self.add_impl(current_module, it);
return;
}
@ -395,7 +395,7 @@ impl RawItemsCollector {
self.push_item(current_module, attrs, RawItemKind::Macro(m));
}
fn add_impl(&mut self, current_module: Option<Module>, imp: ast::ImplBlock) {
fn add_impl(&mut self, current_module: Option<Module>, imp: ast::ImplDef) {
let attrs = self.parse_attrs(&imp);
let ast_id = self.source_ast_id_map.ast_id(&imp);
let imp = self.raw_items.impls.alloc(ImplData { ast_id });

View file

@ -52,7 +52,7 @@ enum Scope {
/// Brings the generic parameters of an item into scope
GenericParams { def: GenericDefId, params: Arc<GenericParams> },
/// Brings `Self` in `impl` block into scope
ImplBlockScope(ImplId),
ImplDefScope(ImplId),
/// Brings `Self` in enum, struct and union definitions into scope
AdtScope(AdtId),
/// Local bindings
@ -154,7 +154,7 @@ impl Resolver {
match scope {
Scope::ExprScope(_) => continue,
Scope::GenericParams { .. }
| Scope::ImplBlockScope(_)
| Scope::ImplDefScope(_)
| Scope::LocalItemsScope(_)
if skip_to_mod =>
{
@ -170,7 +170,7 @@ impl Resolver {
));
}
}
Scope::ImplBlockScope(impl_) => {
Scope::ImplDefScope(impl_) => {
if first_name == &name![Self] {
let idx = if path.segments.len() == 1 { None } else { Some(1) };
return Some((TypeNs::SelfType(*impl_), idx));
@ -263,7 +263,7 @@ impl Resolver {
Scope::AdtScope(_)
| Scope::ExprScope(_)
| Scope::GenericParams { .. }
| Scope::ImplBlockScope(_)
| Scope::ImplDefScope(_)
| Scope::LocalItemsScope(_)
if skip_to_mod =>
{
@ -291,7 +291,7 @@ impl Resolver {
}
Scope::GenericParams { .. } => continue,
Scope::ImplBlockScope(impl_) if n_segments > 1 => {
Scope::ImplDefScope(impl_) if n_segments > 1 => {
if first_name == &name![Self] {
let ty = TypeNs::SelfType(*impl_);
return Some(ResolveValueResult::Partial(ty, 1));
@ -303,7 +303,7 @@ impl Resolver {
return Some(ResolveValueResult::Partial(ty, 1));
}
}
Scope::ImplBlockScope(_) | Scope::AdtScope(_) => continue,
Scope::ImplDefScope(_) | Scope::AdtScope(_) => continue,
Scope::ModuleScope(m) => {
let (module_def, idx) = m.crate_def_map.resolve_path(
@ -503,7 +503,7 @@ impl Scope {
}
}
}
Scope::ImplBlockScope(i) => {
Scope::ImplDefScope(i) => {
f(name![Self], ScopeDef::ImplSelfType(*i));
}
Scope::AdtScope(i) => {
@ -550,8 +550,8 @@ impl Resolver {
self.push_scope(Scope::GenericParams { def, params })
}
fn push_impl_block_scope(self, impl_block: ImplId) -> Resolver {
self.push_scope(Scope::ImplBlockScope(impl_block))
fn push_impl_def_scope(self, impl_def: ImplId) -> Resolver {
self.push_scope(Scope::ImplDefScope(impl_def))
}
fn push_module_scope(
@ -634,7 +634,7 @@ impl HasResolver for ImplId {
.container
.resolver(db)
.push_generic_params_scope(db, self.into())
.push_impl_block_scope(self)
.push_impl_def_scope(self)
}
}

View file

@ -11,7 +11,7 @@ use ra_db::{impl_intern_key, salsa, CrateId};
use ra_prof::profile;
use crate::{
method_resolution::CrateImplBlocks,
method_resolution::CrateImplDefs,
traits::{chalk, AssocTyValue, Impl},
Binders, CallableDef, GenericPredicate, InferenceResult, PolyFnSig, Substs, TraitRef, Ty,
TyDefId, TypeCtor, ValueTyDefId,
@ -59,8 +59,8 @@ pub trait HirDatabase: DefDatabase {
#[salsa::invoke(crate::lower::generic_defaults_query)]
fn generic_defaults(&self, def: GenericDefId) -> Substs;
#[salsa::invoke(crate::method_resolution::CrateImplBlocks::impls_in_crate_query)]
fn impls_in_crate(&self, krate: CrateId) -> Arc<CrateImplBlocks>;
#[salsa::invoke(crate::method_resolution::CrateImplDefs::impls_in_crate_query)]
fn impls_in_crate(&self, krate: CrateId) -> Arc<CrateImplDefs>;
#[salsa::invoke(crate::traits::impls_for_trait_query)]
fn impls_for_trait(&self, krate: CrateId, trait_: TraitId) -> Arc<[ImplId]>;

View file

@ -42,19 +42,19 @@ impl TyFingerprint {
}
#[derive(Debug, PartialEq, Eq)]
pub struct CrateImplBlocks {
pub struct CrateImplDefs {
impls: FxHashMap<TyFingerprint, Vec<ImplId>>,
impls_by_trait: FxHashMap<TraitId, Vec<ImplId>>,
}
impl CrateImplBlocks {
impl CrateImplDefs {
pub(crate) fn impls_in_crate_query(
db: &impl HirDatabase,
krate: CrateId,
) -> Arc<CrateImplBlocks> {
) -> Arc<CrateImplDefs> {
let _p = profile("impls_in_crate_query");
let mut res =
CrateImplBlocks { impls: FxHashMap::default(), impls_by_trait: FxHashMap::default() };
CrateImplDefs { impls: FxHashMap::default(), impls_by_trait: FxHashMap::default() };
let crate_def_map = db.crate_def_map(krate);
for (_module_id, module_data) in crate_def_map.modules.iter() {
@ -75,12 +75,12 @@ impl CrateImplBlocks {
Arc::new(res)
}
pub fn lookup_impl_blocks(&self, ty: &Ty) -> impl Iterator<Item = ImplId> + '_ {
pub fn lookup_impl_defs(&self, ty: &Ty) -> impl Iterator<Item = ImplId> + '_ {
let fingerprint = TyFingerprint::for_impl(ty);
fingerprint.and_then(|f| self.impls.get(&f)).into_iter().flatten().copied()
}
pub fn lookup_impl_blocks_for_trait(&self, tr: TraitId) -> impl Iterator<Item = ImplId> + '_ {
pub fn lookup_impl_defs_for_trait(&self, tr: TraitId) -> impl Iterator<Item = ImplId> + '_ {
self.impls_by_trait.get(&tr).into_iter().flatten().copied()
}
@ -131,7 +131,7 @@ impl Ty {
let res = lang_item_targets
.into_iter()
.filter_map(|it| match it {
LangItemTarget::ImplBlockId(it) => Some(it),
LangItemTarget::ImplDefId(it) => Some(it),
_ => None,
})
.map(|it| it.lookup(db).container.module(db).krate)
@ -177,7 +177,7 @@ pub enum LookupMode {
}
// This would be nicer if it just returned an iterator, but that runs into
// lifetime problems, because we need to borrow temp `CrateImplBlocks`.
// lifetime problems, because we need to borrow temp `CrateImplDefs`.
// FIXME add a context type here?
pub fn iterate_method_candidates<T>(
ty: &Canonical<Ty>,
@ -425,8 +425,8 @@ fn iterate_inherent_methods<T>(
for krate in self_ty.value.def_crates(db, krate)? {
let impls = db.impls_in_crate(krate);
for impl_block in impls.lookup_impl_blocks(&self_ty.value) {
for &item in db.impl_data(impl_block).items.iter() {
for impl_def in impls.lookup_impl_defs(&self_ty.value) {
for &item in db.impl_data(impl_def).items.iter() {
if !is_valid_candidate(db, name, receiver_ty, item, self_ty) {
continue;
}
@ -434,8 +434,7 @@ fn iterate_inherent_methods<T>(
// that the impl is for. If we have a receiver type, this
// already happens in `is_valid_candidate` above; if not, we
// check it here
if receiver_ty.is_none() && inherent_impl_substs(db, impl_block, self_ty).is_none()
{
if receiver_ty.is_none() && inherent_impl_substs(db, impl_def, self_ty).is_none() {
test_utils::tested_by!(impl_self_type_match_without_receiver);
continue;
}

View file

@ -4,7 +4,7 @@ use insta::assert_snapshot;
use ra_db::fixture::WithFixture;
#[test]
fn cfg_impl_block() {
fn cfg_impl_def() {
let (db, pos) = TestDB::with_position(
r#"
//- /main.rs crate:main deps:foo cfg:test
@ -354,10 +354,10 @@ fn main() {
@r###"
[159; 164) '{ 0 }': u64
[161; 162) '0': u64
[175; 199) '{ ...f(); }': ()
[187; 189) '_a': u64
[193; 194) 'f': fn f() -> u64
[193; 196) 'f()': u64
[175; 197) '{ ...f(); }': ()
[185; 187) '_a': u64
[191; 192) 'f': fn f() -> u64
[191; 194) 'f()': u64
"###
);
}

View file

@ -131,8 +131,8 @@ pub(crate) fn impls_for_trait_query(
for dep in db.crate_graph().dependencies(krate) {
impls.extend(db.impls_for_trait(dep.crate_id, trait_).iter());
}
let crate_impl_blocks = db.impls_in_crate(krate);
impls.extend(crate_impl_blocks.lookup_impl_blocks_for_trait(trait_));
let crate_impl_defs = db.impls_in_crate(krate);
impls.extend(crate_impl_defs.lookup_impl_defs_for_trait(trait_));
impls.into_iter().collect()
}
@ -346,7 +346,7 @@ pub struct UnsizeToSuperTraitObjectData {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Impl {
/// A normal impl from an impl block.
ImplBlock(ImplId),
ImplDef(ImplId),
/// Closure types implement the Fn traits synthetically.
ClosureFnTraitImpl(ClosureFnTraitImplData),
/// [T; n]: Unsize<[T]>

View file

@ -96,7 +96,7 @@ fn get_builtin_unsize_impls(
pub(super) fn impl_datum(db: &impl HirDatabase, krate: CrateId, impl_: Impl) -> BuiltinImplData {
match impl_ {
Impl::ImplBlock(_) => unreachable!(),
Impl::ImplDef(_) => unreachable!(),
Impl::ClosureFnTraitImpl(data) => closure_fn_trait_impl_datum(db, krate, data),
Impl::UnsizeArray => array_unsize_impl_datum(db, krate),
Impl::UnsizeToTraitObject(trait_) => trait_object_unsize_impl_datum(db, krate, trait_),

View file

@ -576,7 +576,7 @@ where
.impls_for_trait(self.krate, trait_)
.iter()
.copied()
.map(Impl::ImplBlock)
.map(Impl::ImplDef)
.map(|impl_| impl_.to_chalk(self.db))
.collect();
@ -712,12 +712,12 @@ pub(crate) fn impl_datum_query(
debug!("impl_datum {:?}", impl_id);
let impl_: Impl = from_chalk(db, impl_id);
match impl_ {
Impl::ImplBlock(impl_block) => impl_block_datum(db, krate, impl_id, impl_block),
Impl::ImplDef(impl_def) => impl_def_datum(db, krate, impl_id, impl_def),
_ => Arc::new(builtin::impl_datum(db, krate, impl_).to_chalk(db)),
}
}
fn impl_block_datum(
fn impl_def_datum(
db: &impl HirDatabase,
krate: CrateId,
chalk_id: ImplId,
@ -815,7 +815,7 @@ fn type_alias_associated_ty_value(
let ty = db.ty(type_alias.into());
let value_bound = chalk_rust_ir::AssociatedTyValueBound { ty: ty.value.to_chalk(db) };
let value = chalk_rust_ir::AssociatedTyValue {
impl_id: Impl::ImplBlock(impl_id).to_chalk(db),
impl_id: Impl::ImplDef(impl_id).to_chalk(db),
associated_ty_id: assoc_ty.to_chalk(db),
value: make_binders(value_bound, ty.num_binders),
};

View file

@ -3,7 +3,7 @@
//! This module adds the completion items related to implementing associated
//! items within a `impl Trait for Struct` block. The current context node
//! must be within either a `FN_DEF`, `TYPE_ALIAS_DEF`, or `CONST_DEF` node
//! and an direct child of an `IMPL_BLOCK`.
//! and an direct child of an `IMPL_DEF`.
//!
//! # Examples
//!
@ -55,49 +55,43 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext
_ => false,
});
let impl_block = trigger
let impl_def = trigger
.as_ref()
.and_then(|node| node.parent())
.and_then(|node| node.parent())
.and_then(ast::ImplBlock::cast);
.and_then(ast::ImplDef::cast);
if let (Some(trigger), Some(impl_block)) = (trigger, impl_block) {
if let (Some(trigger), Some(impl_def)) = (trigger, impl_def) {
match trigger.kind() {
SyntaxKind::FN_DEF => {
for missing_fn in
get_missing_impl_items(&ctx.sema, &impl_block).iter().filter_map(|item| {
match item {
hir::AssocItem::Function(fn_item) => Some(fn_item),
_ => None,
}
})
{
for missing_fn in get_missing_impl_items(&ctx.sema, &impl_def).iter().filter_map(
|item| match item {
hir::AssocItem::Function(fn_item) => Some(fn_item),
_ => None,
},
) {
add_function_impl(&trigger, acc, ctx, &missing_fn);
}
}
SyntaxKind::TYPE_ALIAS_DEF => {
for missing_fn in
get_missing_impl_items(&ctx.sema, &impl_block).iter().filter_map(|item| {
match item {
hir::AssocItem::TypeAlias(type_item) => Some(type_item),
_ => None,
}
})
{
for missing_fn in get_missing_impl_items(&ctx.sema, &impl_def).iter().filter_map(
|item| match item {
hir::AssocItem::TypeAlias(type_item) => Some(type_item),
_ => None,
},
) {
add_type_alias_impl(&trigger, acc, ctx, &missing_fn);
}
}
SyntaxKind::CONST_DEF => {
for missing_fn in
get_missing_impl_items(&ctx.sema, &impl_block).iter().filter_map(|item| {
match item {
hir::AssocItem::Const(const_item) => Some(const_item),
_ => None,
}
})
{
for missing_fn in get_missing_impl_items(&ctx.sema, &impl_def).iter().filter_map(
|item| match item {
hir::AssocItem::Const(const_item) => Some(const_item),
_ => None,
},
) {
add_const_impl(&trigger, acc, ctx, &missing_fn);
}
}

View file

@ -27,7 +27,7 @@ pub(crate) struct CompletionContext<'a> {
pub(super) use_item_syntax: Option<ast::UseItem>,
pub(super) record_lit_syntax: Option<ast::RecordLit>,
pub(super) record_lit_pat: Option<ast::RecordPat>,
pub(super) impl_block: Option<ast::ImplBlock>,
pub(super) impl_def: Option<ast::ImplDef>,
pub(super) is_param: bool,
/// If a name-binding or reference to a const in a pattern.
/// Irrefutable patterns (like let) are excluded.
@ -81,7 +81,7 @@ impl<'a> CompletionContext<'a> {
use_item_syntax: None,
record_lit_syntax: None,
record_lit_pat: None,
impl_block: None,
impl_def: None,
is_param: false,
is_pat_binding: false,
is_trivial_path: false,
@ -161,12 +161,12 @@ impl<'a> CompletionContext<'a> {
self.record_lit_syntax = find_node_at_offset(original_file.syntax(), self.offset);
}
self.impl_block = self
self.impl_def = self
.token
.parent()
.ancestors()
.take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE)
.find_map(ast::ImplBlock::cast);
.find_map(ast::ImplDef::cast);
let top_node = name_ref
.syntax()

View file

@ -269,7 +269,7 @@ impl ToNav for hir::Module {
}
}
impl ToNav for hir::ImplBlock {
impl ToNav for hir::ImplDef {
fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
let src = self.source(db);
let frange = if let Some(item) = self.is_builtin_derive(db) {

View file

@ -129,7 +129,7 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
ast::RecordFieldDef(it) => { decl_with_ascription(it) },
ast::ConstDef(it) => { decl_with_ascription(it) },
ast::StaticDef(it) => { decl_with_ascription(it) },
ast::ImplBlock(it) => {
ast::ImplDef(it) => {
let target_type = it.target_type()?;
let target_trait = it.target_trait();
let label = match target_trait {
@ -360,7 +360,7 @@ fn very_obsolete() {}
label: "impl E",
navigation_range: [239; 240),
node_range: [234; 243),
kind: IMPL_BLOCK,
kind: IMPL_DEF,
detail: None,
deprecated: false,
},
@ -369,7 +369,7 @@ fn very_obsolete() {}
label: "impl fmt::Debug for E",
navigation_range: [265; 266),
node_range: [245; 269),
kind: IMPL_BLOCK,
kind: IMPL_DEF,
detail: None,
deprecated: false,
},

View file

@ -195,7 +195,7 @@ fn some_thing() -> u32 {
mat<|>ch_ast! {
match container {
ast::TraitDef(it) => {},
ast::ImplBlock(it) => {},
ast::ImplDef(it) => {},
_ => { continue },
}
}
@ -207,7 +207,7 @@ fn some_thing() -> u32 {
assert_snapshot!(res.expansion, @r###"
{
if let Some(it) = ast::TraitDef::cast(container.clone()){}
else if let Some(it) = ast::ImplBlock::cast(container.clone()){}
else if let Some(it) = ast::ImplDef::cast(container.clone()){}
else {
{
continue

View file

@ -477,7 +477,7 @@ mod tests {
}
}
",
"impl IMPL_BLOCK FileId(1) [12; 73)",
"impl IMPL_DEF FileId(1) [12; 73)",
"impl Foo {...}",
);
@ -491,7 +491,7 @@ mod tests {
}
}
",
"impl IMPL_BLOCK FileId(1) [12; 73)",
"impl IMPL_DEF FileId(1) [12; 73)",
"impl Foo {...}",
);
@ -505,7 +505,7 @@ mod tests {
}
}
",
"impl IMPL_BLOCK FileId(1) [15; 75)",
"impl IMPL_DEF FileId(1) [15; 75)",
"impl Foo {...}",
);
@ -518,7 +518,7 @@ mod tests {
}
}
",
"impl IMPL_BLOCK FileId(1) [15; 62)",
"impl IMPL_DEF FileId(1) [15; 62)",
"impl Foo {...}",
);
}
@ -538,7 +538,7 @@ mod tests {
}
}
",
"impl IMPL_BLOCK FileId(1) [49; 115)",
"impl IMPL_DEF FileId(1) [49; 115)",
"impl Make for Foo {...}",
);
@ -555,7 +555,7 @@ mod tests {
}
}
",
"impl IMPL_BLOCK FileId(1) [49; 115)",
"impl IMPL_DEF FileId(1) [49; 115)",
"impl Make for Foo {...}",
);
}

View file

@ -1,6 +1,6 @@
//! FIXME: write short doc here
use hir::{Crate, ImplBlock, Semantics};
use hir::{Crate, ImplDef, Semantics};
use ra_ide_db::RootDatabase;
use ra_syntax::{algo::find_node_at_offset, ast, AstNode};
@ -42,12 +42,12 @@ fn impls_for_def(
ast::NominalDef::UnionDef(def) => sema.to_def(def)?.ty(sema.db),
};
let impls = ImplBlock::all_in_crate(sema.db, krate);
let impls = ImplDef::all_in_crate(sema.db, krate);
Some(
impls
.into_iter()
.filter(|impl_block| ty.is_equal_for_find_impls(&impl_block.target_ty(sema.db)))
.filter(|impl_def| ty.is_equal_for_find_impls(&impl_def.target_ty(sema.db)))
.map(|imp| imp.to_nav(sema.db))
.collect(),
)
@ -60,7 +60,7 @@ fn impls_for_trait(
) -> Option<Vec<NavigationTarget>> {
let tr = sema.to_def(node)?;
let impls = ImplBlock::for_trait(sema.db, krate, tr);
let impls = ImplDef::for_trait(sema.db, krate, tr);
Some(impls.into_iter().map(|imp| imp.to_nav(sema.db)).collect())
}
@ -86,7 +86,7 @@ mod tests {
struct Foo<|>;
impl Foo {}
",
&["impl IMPL_BLOCK FileId(1) [12; 23)"],
&["impl IMPL_DEF FileId(1) [12; 23)"],
);
}
@ -99,7 +99,7 @@ mod tests {
impl Foo {}
impl Foo {}
",
&["impl IMPL_BLOCK FileId(1) [12; 23)", "impl IMPL_BLOCK FileId(1) [24; 35)"],
&["impl IMPL_DEF FileId(1) [12; 23)", "impl IMPL_DEF FileId(1) [24; 35)"],
);
}
@ -116,7 +116,7 @@ mod tests {
impl super::Foo {}
}
",
&["impl IMPL_BLOCK FileId(1) [24; 42)", "impl IMPL_BLOCK FileId(1) [57; 75)"],
&["impl IMPL_DEF FileId(1) [24; 42)", "impl IMPL_DEF FileId(1) [57; 75)"],
);
}
@ -133,7 +133,7 @@ mod tests {
//- /b.rs
impl crate::Foo {}
",
&["impl IMPL_BLOCK FileId(2) [0; 18)", "impl IMPL_BLOCK FileId(3) [0; 18)"],
&["impl IMPL_DEF FileId(2) [0; 18)", "impl IMPL_DEF FileId(3) [0; 18)"],
);
}
@ -146,7 +146,7 @@ mod tests {
struct Foo;
impl T for Foo {}
",
&["impl IMPL_BLOCK FileId(1) [23; 40)"],
&["impl IMPL_DEF FileId(1) [23; 40)"],
);
}
@ -164,7 +164,7 @@ mod tests {
//- /b.rs
impl crate::T for crate::Foo {}
",
&["impl IMPL_BLOCK FileId(2) [0; 31)", "impl IMPL_BLOCK FileId(3) [0; 31)"],
&["impl IMPL_DEF FileId(2) [0; 31)", "impl IMPL_DEF FileId(3) [0; 31)"],
);
}
@ -180,9 +180,9 @@ mod tests {
impl T for &Foo {}
",
&[
"impl IMPL_BLOCK FileId(1) [23; 34)",
"impl IMPL_BLOCK FileId(1) [35; 52)",
"impl IMPL_BLOCK FileId(1) [53; 71)",
"impl IMPL_DEF FileId(1) [23; 34)",
"impl IMPL_DEF FileId(1) [35; 52)",
"impl IMPL_DEF FileId(1) [53; 71)",
],
);
}
@ -195,7 +195,7 @@ mod tests {
#[derive(Copy)]
struct Foo<|>;
",
&["impl IMPL_BLOCK FileId(1) [0; 15)"],
&["impl IMPL_DEF FileId(1) [0; 15)"],
);
}
}

View file

@ -61,7 +61,7 @@ pub(crate) fn classify_name_ref(
PathResolution::Local(local) => NameDefinition::Local(local),
PathResolution::TypeParam(par) => NameDefinition::TypeParam(par),
PathResolution::Macro(def) => NameDefinition::Macro(def),
PathResolution::SelfType(impl_block) => NameDefinition::SelfType(impl_block),
PathResolution::SelfType(impl_def) => NameDefinition::SelfType(impl_def),
};
Some(res)
}

View file

@ -6,7 +6,7 @@
// FIXME: this badly needs rename/rewrite (matklad, 2020-02-06).
use hir::{
Adt, FieldSource, HasSource, ImplBlock, Local, MacroDef, Module, ModuleDef, Semantics,
Adt, FieldSource, HasSource, ImplDef, Local, MacroDef, Module, ModuleDef, Semantics,
StructField, TypeParam,
};
use ra_prof::profile;
@ -22,7 +22,7 @@ pub enum NameDefinition {
Macro(MacroDef),
StructField(StructField),
ModuleDef(ModuleDef),
SelfType(ImplBlock),
SelfType(ImplDef),
Local(Local),
TypeParam(TypeParam),
}

View file

@ -152,7 +152,7 @@ pub(crate) fn reparser(
EXTERN_ITEM_LIST => items::extern_item_list,
TOKEN_TREE if first_child? == T!['{'] => items::token_tree,
ITEM_LIST => match parent? {
IMPL_BLOCK => items::impl_item_list,
IMPL_DEF => items::impl_item_list,
TRAIT_DEF => items::trait_item_list,
MODULE => items::mod_item_list,
_ => return None,

View file

@ -202,8 +202,8 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul
// test unsafe_default_impl
// unsafe default impl Foo {}
T![impl] => {
traits::impl_block(p);
m.complete(p, IMPL_BLOCK);
traits::impl_def(p);
m.complete(p, IMPL_DEF);
}
// test existential_type

View file

@ -53,9 +53,9 @@ pub(crate) fn trait_item_list(p: &mut Parser) {
m.complete(p, ITEM_LIST);
}
// test impl_block
// test impl_def
// impl Foo {}
pub(super) fn impl_block(p: &mut Parser) {
pub(super) fn impl_def(p: &mut Parser) {
assert!(p.at(T![impl]));
p.bump(T![impl]);
if choose_type_params_over_qpath(p) {
@ -65,7 +65,7 @@ pub(super) fn impl_block(p: &mut Parser) {
// FIXME: never type
// impl ! {}
// test impl_block_neg
// test impl_def_neg
// impl !Send for X {}
p.eat(T![!]);
impl_type(p);

View file

@ -133,7 +133,7 @@ pub enum SyntaxKind {
STATIC_DEF,
CONST_DEF,
TRAIT_DEF,
IMPL_BLOCK,
IMPL_DEF,
TYPE_ALIAS_DEF,
MACRO_CALL,
TOKEN_TREE,

View file

@ -169,7 +169,7 @@ impl ast::UseTreeList {
}
}
impl ast::ImplBlock {
impl ast::ImplDef {
pub fn target_type(&self) -> Option<ast::TypeRef> {
match self.target() {
(Some(t), None) | (_, Some(t)) => Some(t),

View file

@ -552,13 +552,13 @@ impl TypeAliasDef {
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ImplBlock {
pub struct ImplDef {
pub(crate) syntax: SyntaxNode,
}
impl AstNode for ImplBlock {
impl AstNode for ImplDef {
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
IMPL_BLOCK => true,
IMPL_DEF => true,
_ => false,
}
}
@ -573,9 +573,9 @@ impl AstNode for ImplBlock {
&self.syntax
}
}
impl ast::TypeParamsOwner for ImplBlock {}
impl ast::AttrsOwner for ImplBlock {}
impl ImplBlock {
impl ast::TypeParamsOwner for ImplDef {}
impl ast::AttrsOwner for ImplDef {}
impl ImplDef {
pub fn item_list(&self) -> Option<ItemList> {
AstChildren::new(&self.syntax).next()
}
@ -3524,7 +3524,7 @@ pub enum ModuleItem {
FnDef(FnDef),
TraitDef(TraitDef),
TypeAliasDef(TypeAliasDef),
ImplBlock(ImplBlock),
ImplDef(ImplDef),
UseItem(UseItem),
ExternCrateItem(ExternCrateItem),
ConstDef(ConstDef),
@ -3561,9 +3561,9 @@ impl From<TypeAliasDef> for ModuleItem {
ModuleItem::TypeAliasDef(node)
}
}
impl From<ImplBlock> for ModuleItem {
fn from(node: ImplBlock) -> ModuleItem {
ModuleItem::ImplBlock(node)
impl From<ImplDef> for ModuleItem {
fn from(node: ImplDef) -> ModuleItem {
ModuleItem::ImplDef(node)
}
}
impl From<UseItem> for ModuleItem {
@ -3594,8 +3594,8 @@ impl From<Module> for ModuleItem {
impl AstNode for ModuleItem {
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
STRUCT_DEF | UNION_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF
| IMPL_BLOCK | USE_ITEM | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE => true,
STRUCT_DEF | UNION_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | IMPL_DEF
| USE_ITEM | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE => true,
_ => false,
}
}
@ -3607,7 +3607,7 @@ impl AstNode for ModuleItem {
FN_DEF => ModuleItem::FnDef(FnDef { syntax }),
TRAIT_DEF => ModuleItem::TraitDef(TraitDef { syntax }),
TYPE_ALIAS_DEF => ModuleItem::TypeAliasDef(TypeAliasDef { syntax }),
IMPL_BLOCK => ModuleItem::ImplBlock(ImplBlock { syntax }),
IMPL_DEF => ModuleItem::ImplDef(ImplDef { syntax }),
USE_ITEM => ModuleItem::UseItem(UseItem { syntax }),
EXTERN_CRATE_ITEM => ModuleItem::ExternCrateItem(ExternCrateItem { syntax }),
CONST_DEF => ModuleItem::ConstDef(ConstDef { syntax }),
@ -3625,7 +3625,7 @@ impl AstNode for ModuleItem {
ModuleItem::FnDef(it) => &it.syntax,
ModuleItem::TraitDef(it) => &it.syntax,
ModuleItem::TypeAliasDef(it) => &it.syntax,
ModuleItem::ImplBlock(it) => &it.syntax,
ModuleItem::ImplDef(it) => &it.syntax,
ModuleItem::UseItem(it) => &it.syntax,
ModuleItem::ExternCrateItem(it) => &it.syntax,
ModuleItem::ConstDef(it) => &it.syntax,

View file

@ -203,12 +203,11 @@ fn validate_visibility(vis: ast::Visibility, errors: &mut Vec<SyntaxError>) {
_ => return,
}
let impl_block = match parent.parent().and_then(|it| it.parent()).and_then(ast::ImplBlock::cast)
{
let impl_def = match parent.parent().and_then(|it| it.parent()).and_then(ast::ImplDef::cast) {
Some(it) => it,
None => return,
};
if impl_block.target_trait().is_some() {
if impl_def.target_trait().is_some() {
errors.push(SyntaxError::new("Unnecessary visibility qualifier", vis.syntax.text_range()));
}
}

View file

@ -1,5 +1,5 @@
SOURCE_FILE@[0; 183)
IMPL_BLOCK@[0; 182)
IMPL_DEF@[0; 182)
IMPL_KW@[0; 4) "impl"
WHITESPACE@[4; 5) " "
PATH_TYPE@[5; 13)

View file

@ -77,7 +77,7 @@ SOURCE_FILE@[0; 112)
ERROR@[54; 55)
COMMA@[54; 55) ","
WHITESPACE@[55; 56) " "
IMPL_BLOCK@[56; 60)
IMPL_DEF@[56; 60)
IMPL_KW@[56; 60) "impl"
EXPR_STMT@[60; 61)
ERROR@[60; 61)

View file

@ -1,5 +1,5 @@
SOURCE_FILE@[0; 38)
IMPL_BLOCK@[0; 14)
IMPL_DEF@[0; 14)
IMPL_KW@[0; 4) "impl"
TYPE_PARAM_LIST@[4; 14)
L_ANGLE@[4; 5) "<"
@ -17,7 +17,7 @@ SOURCE_FILE@[0; 38)
IDENT@[8; 13) "Clone"
R_ANGLE@[13; 14) ">"
WHITESPACE@[14; 15) "\n"
IMPL_BLOCK@[15; 37)
IMPL_DEF@[15; 37)
IMPL_KW@[15; 19) "impl"
TYPE_PARAM_LIST@[19; 22)
L_ANGLE@[19; 20) "<"

View file

@ -1,5 +1,5 @@
SOURCE_FILE@[0; 118)
IMPL_BLOCK@[0; 117)
IMPL_DEF@[0; 117)
IMPL_KW@[0; 4) "impl"
WHITESPACE@[4; 5) " "
PATH_TYPE@[5; 6)

View file

@ -18,7 +18,7 @@ SOURCE_FILE@[0; 30)
LIFETIME@[16; 21) "\'loop"
COLON@[21; 22) ":"
WHITESPACE@[22; 23) " "
IMPL_BLOCK@[23; 27)
IMPL_DEF@[23; 27)
IMPL_KW@[23; 27) "impl"
WHITESPACE@[27; 28) "\n"
R_CURLY@[28; 29) "}"

View file

@ -1,5 +1,5 @@
SOURCE_FILE@[0; 87)
IMPL_BLOCK@[0; 12)
IMPL_DEF@[0; 12)
IMPL_KW@[0; 4) "impl"
WHITESPACE@[4; 5) " "
PATH_TYPE@[5; 9)
@ -12,7 +12,7 @@ SOURCE_FILE@[0; 87)
L_CURLY@[10; 11) "{"
R_CURLY@[11; 12) "}"
WHITESPACE@[12; 13) "\n"
IMPL_BLOCK@[13; 33)
IMPL_DEF@[13; 33)
IMPL_KW@[13; 17) "impl"
WHITESPACE@[17; 18) " "
PATH_TYPE@[18; 24)
@ -33,10 +33,10 @@ SOURCE_FILE@[0; 87)
L_CURLY@[31; 32) "{"
R_CURLY@[32; 33) "}"
WHITESPACE@[33; 34) "\n"
IMPL_BLOCK@[34; 38)
IMPL_DEF@[34; 38)
IMPL_KW@[34; 38) "impl"
WHITESPACE@[38; 39) " "
IMPL_BLOCK@[39; 54)
IMPL_DEF@[39; 54)
IMPL_KW@[39; 43) "impl"
WHITESPACE@[43; 44) " "
PATH_TYPE@[44; 51)
@ -49,7 +49,7 @@ SOURCE_FILE@[0; 87)
L_CURLY@[52; 53) "{"
R_CURLY@[53; 54) "}"
WHITESPACE@[54; 55) "\n"
IMPL_BLOCK@[55; 70)
IMPL_DEF@[55; 70)
IMPL_KW@[55; 59) "impl"
WHITESPACE@[59; 60) " "
PATH_TYPE@[60; 66)
@ -60,7 +60,7 @@ SOURCE_FILE@[0; 87)
WHITESPACE@[66; 67) " "
FOR_KW@[67; 70) "for"
WHITESPACE@[70; 71) " "
IMPL_BLOCK@[71; 86)
IMPL_DEF@[71; 86)
IMPL_KW@[71; 75) "impl"
WHITESPACE@[75; 76) " "
PATH_TYPE@[76; 83)

View file

@ -1,5 +1,5 @@
SOURCE_FILE@[0; 83)
IMPL_BLOCK@[0; 82)
IMPL_DEF@[0; 82)
IMPL_KW@[0; 4) "impl"
WHITESPACE@[4; 5) " "
PATH_TYPE@[5; 6)

View file

@ -1,5 +1,5 @@
SOURCE_FILE@[0; 128)
IMPL_BLOCK@[0; 127)
IMPL_DEF@[0; 127)
IMPL_KW@[0; 4) "impl"
WHITESPACE@[4; 5) " "
PATH_TYPE@[5; 6)

View file

@ -1,5 +1,5 @@
SOURCE_FILE@[0; 69)
IMPL_BLOCK@[0; 68)
IMPL_DEF@[0; 68)
IMPL_KW@[0; 4) "impl"
WHITESPACE@[4; 5) " "
PATH_TYPE@[5; 6)

View file

@ -1,5 +1,5 @@
SOURCE_FILE@[0; 89)
IMPL_BLOCK@[0; 88)
IMPL_DEF@[0; 88)
IMPL_KW@[0; 4) "impl"
WHITESPACE@[4; 5) " "
PATH_TYPE@[5; 6)

View file

@ -1,5 +1,5 @@
SOURCE_FILE@[0; 27)
IMPL_BLOCK@[0; 26)
IMPL_DEF@[0; 26)
UNSAFE_KW@[0; 6) "unsafe"
WHITESPACE@[6; 7) " "
DEFAULT_KW@[7; 14) "default"

View file

@ -1,5 +1,5 @@
SOURCE_FILE@[0; 20)
IMPL_BLOCK@[0; 19)
IMPL_DEF@[0; 19)
IMPL_KW@[0; 4) "impl"
WHITESPACE@[4; 5) " "
EXCL@[5; 6) "!"

View file

@ -1,5 +1,5 @@
SOURCE_FILE@[0; 12)
IMPL_BLOCK@[0; 11)
IMPL_DEF@[0; 11)
IMPL_KW@[0; 4) "impl"
WHITESPACE@[4; 5) " "
PATH_TYPE@[5; 8)

View file

@ -1,5 +1,5 @@
SOURCE_FILE@[0; 19)
IMPL_BLOCK@[0; 18)
IMPL_DEF@[0; 18)
UNSAFE_KW@[0; 6) "unsafe"
WHITESPACE@[6; 7) " "
IMPL_KW@[7; 11) "impl"

View file

@ -1,5 +1,5 @@
SOURCE_FILE@[0; 20)
IMPL_BLOCK@[0; 19)
IMPL_DEF@[0; 19)
DEFAULT_KW@[0; 7) "default"
WHITESPACE@[7; 8) " "
IMPL_KW@[8; 12) "impl"

View file

@ -8,7 +8,7 @@ SOURCE_FILE@[0; 94)
L_CURLY@[6; 7) "{"
R_CURLY@[7; 8) "}"
WHITESPACE@[8; 9) "\n"
IMPL_BLOCK@[9; 93)
IMPL_DEF@[9; 93)
IMPL_KW@[9; 13) "impl"
WHITESPACE@[13; 14) " "
PATH_TYPE@[14; 15)

View file

@ -1,5 +1,5 @@
SOURCE_FILE@[0; 69)
IMPL_BLOCK@[0; 68)
IMPL_DEF@[0; 68)
IMPL_KW@[0; 4) "impl"
WHITESPACE@[4; 5) " "
PATH_TYPE@[5; 6)

View file

@ -1,5 +1,5 @@
SOURCE_FILE@[0; 29)
IMPL_BLOCK@[0; 28)
IMPL_DEF@[0; 28)
IMPL_KW@[0; 4) "impl"
TYPE_PARAM_LIST@[4; 18)
L_ANGLE@[4; 5) "<"

View file

@ -1,5 +1,5 @@
SOURCE_FILE@[0; 137)
IMPL_BLOCK@[0; 136)
IMPL_DEF@[0; 136)
IMPL_KW@[0; 4) "impl"
WHITESPACE@[4; 5) " "
PATH_TYPE@[5; 6)

View file

@ -8,7 +8,7 @@ SOURCE_FILE@[0; 199)
IDENT@[69; 72) "Foo"
SEMI@[72; 73) ";"
WHITESPACE@[73; 75) "\n\n"
IMPL_BLOCK@[75; 141)
IMPL_DEF@[75; 141)
IMPL_KW@[75; 79) "impl"
WHITESPACE@[79; 80) " "
PATH_TYPE@[80; 83)

View file

@ -92,7 +92,7 @@ SOURCE_FILE@[0; 686)
WHITESPACE@[461; 463) "\n\n"
COMMENT@[463; 523) "// https://github.com ..."
WHITESPACE@[523; 524) "\n"
IMPL_BLOCK@[524; 685)
IMPL_DEF@[524; 685)
IMPL_KW@[524; 528) "impl"
WHITESPACE@[528; 529) " "
PATH_TYPE@[529; 537)

View file

@ -253,7 +253,7 @@ SOURCE_FILE@[0; 519)
WHITESPACE@[234; 235) "\n"
R_CURLY@[235; 236) "}"
WHITESPACE@[236; 238) "\n\n"
IMPL_BLOCK@[238; 519)
IMPL_DEF@[238; 519)
IMPL_KW@[238; 242) "impl"
WHITESPACE@[242; 243) " "
PATH_TYPE@[243; 244)

View file

@ -76,8 +76,8 @@ pub fn analysis_stats(
}
}
for impl_block in module.impl_blocks(db) {
for item in impl_block.items(db) {
for impl_def in module.impl_defs(db) {
for item in impl_def.items(db) {
num_decls += 1;
if let AssocItem::Function(f) = item {
funcs.push(f);

View file

@ -57,7 +57,7 @@ impl Conv for SyntaxKind {
SyntaxKind::RECORD_FIELD_DEF => SymbolKind::Field,
SyntaxKind::STATIC_DEF => SymbolKind::Constant,
SyntaxKind::CONST_DEF => SymbolKind::Constant,
SyntaxKind::IMPL_BLOCK => SymbolKind::Object,
SyntaxKind::IMPL_DEF => SymbolKind::Object,
_ => SymbolKind::Variable,
}
}

View file

@ -104,7 +104,7 @@ pub(crate) const KINDS_SRC: KindsSrc = KindsSrc {
"STATIC_DEF",
"CONST_DEF",
"TRAIT_DEF",
"IMPL_BLOCK",
"IMPL_DEF",
"TYPE_ALIAS_DEF",
"MACRO_CALL",
"TOKEN_TREE",
@ -357,7 +357,7 @@ pub(crate) const AST_SRC: AstSrc = AstSrc {
TypeRef,
}
struct ImplBlock: TypeParamsOwner, AttrsOwner {
struct ImplDef: TypeParamsOwner, AttrsOwner {
ItemList,
}
@ -560,7 +560,7 @@ pub(crate) const AST_SRC: AstSrc = AstSrc {
FnDef,
TraitDef,
TypeAliasDef,
ImplBlock,
ImplDef,
UseItem,
ExternCrateItem,
ConstDef,