mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-28 14:03:35 +00:00
remove forward pointer for name
This commit is contained in:
parent
16e620c052
commit
f8ddef875a
16 changed files with 52 additions and 43 deletions
|
@ -3,13 +3,14 @@
|
|||
|
||||
use std::sync::Arc;
|
||||
|
||||
use hir_def::name::AsName;
|
||||
use ra_arena::{impl_arena_id, Arena, RawId};
|
||||
use ra_syntax::ast::{self, NameOwner, StructKind, TypeAscriptionOwner};
|
||||
|
||||
use crate::{
|
||||
db::{AstDatabase, DefDatabase, HirDatabase},
|
||||
type_ref::TypeRef,
|
||||
AsName, Enum, EnumVariant, FieldSource, HasSource, Module, Name, Source, Struct, StructField,
|
||||
Enum, EnumVariant, FieldSource, HasSource, Module, Name, Source, Struct, StructField,
|
||||
};
|
||||
|
||||
impl Struct {
|
||||
|
|
|
@ -5,7 +5,13 @@ pub(crate) mod docs;
|
|||
|
||||
use std::sync::Arc;
|
||||
|
||||
use hir_def::{CrateModuleId, ModuleId};
|
||||
use hir_def::{
|
||||
name::{
|
||||
self, AsName, BOOL, CHAR, F32, F64, I128, I16, I32, I64, I8, ISIZE, SELF_TYPE, STR, U128,
|
||||
U16, U32, U64, U8, USIZE,
|
||||
},
|
||||
CrateModuleId, ModuleId,
|
||||
};
|
||||
use ra_db::{CrateId, Edition};
|
||||
use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner};
|
||||
|
||||
|
@ -20,10 +26,6 @@ use crate::{
|
|||
TypeAliasId,
|
||||
},
|
||||
impl_block::ImplBlock,
|
||||
name::{
|
||||
BOOL, CHAR, F32, F64, I128, I16, I32, I64, I8, ISIZE, SELF_TYPE, STR, U128, U16, U32, U64,
|
||||
U8, USIZE,
|
||||
},
|
||||
nameres::{ImportId, ModuleScope, Namespace},
|
||||
resolve::{Resolver, Scope, TypeNs},
|
||||
traits::TraitData,
|
||||
|
@ -33,7 +35,7 @@ use crate::{
|
|||
},
|
||||
type_ref::Mutability,
|
||||
type_ref::TypeRef,
|
||||
AsName, Either, HasSource, Name, Ty,
|
||||
Either, HasSource, Name, Ty,
|
||||
};
|
||||
|
||||
/// hir::Crate describes a single crate. It's the main interface with which
|
||||
|
@ -898,9 +900,7 @@ impl Trait {
|
|||
.where_predicates
|
||||
.iter()
|
||||
.filter_map(|pred| match &pred.type_ref {
|
||||
TypeRef::Path(p) if p.as_ident() == Some(&crate::name::SELF_TYPE) => {
|
||||
pred.bound.as_path()
|
||||
}
|
||||
TypeRef::Path(p) if p.as_ident() == Some(&name::SELF_TYPE) => pred.bound.as_path(),
|
||||
_ => None,
|
||||
})
|
||||
.filter_map(|path| match resolver.resolve_path_in_type_ns_fully(db, path) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
//! FIXME: write short doc here
|
||||
|
||||
use hir_def::name::{self, AsName, Name};
|
||||
use ra_arena::Arena;
|
||||
use ra_syntax::{
|
||||
ast::{
|
||||
|
@ -12,7 +13,6 @@ use test_utils::tested_by;
|
|||
|
||||
use crate::{
|
||||
db::HirDatabase,
|
||||
name::{AsName, Name, SELF_PARAM},
|
||||
path::GenericArgs,
|
||||
ty::primitive::{FloatTy, IntTy, UncertainFloatTy, UncertainIntTy},
|
||||
type_ref::TypeRef,
|
||||
|
@ -78,7 +78,7 @@ where
|
|||
let ptr = AstPtr::new(&self_param);
|
||||
let param_pat = self.alloc_pat(
|
||||
Pat::Bind {
|
||||
name: SELF_PARAM,
|
||||
name: name::SELF_PARAM,
|
||||
mode: BindingAnnotation::Unannotated,
|
||||
subpat: None,
|
||||
},
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
//! FIXME: write short doc here
|
||||
|
||||
use hir_def::name::AsName;
|
||||
use ra_syntax::ast::{self, AstNode, NameOwner};
|
||||
|
||||
use crate::{
|
||||
db::{AstDatabase, DefDatabase, HirDatabase},
|
||||
ids::{AstItemDef, LocationCtx},
|
||||
name::AsName,
|
||||
AstId, Const, Crate, Enum, EnumVariant, FieldSource, Function, HasSource, ImplBlock, Module,
|
||||
ModuleSource, Source, Static, Struct, StructField, Trait, TypeAlias, Union, VariantDef,
|
||||
};
|
||||
|
|
|
@ -5,15 +5,15 @@
|
|||
|
||||
use std::sync::Arc;
|
||||
|
||||
use hir_def::name::{self, AsName};
|
||||
use ra_syntax::ast::{self, DefaultTypeParamOwner, NameOwner, TypeBoundsOwner, TypeParamsOwner};
|
||||
|
||||
use crate::{
|
||||
db::{AstDatabase, DefDatabase, HirDatabase},
|
||||
name::SELF_TYPE,
|
||||
path::Path,
|
||||
type_ref::{TypeBound, TypeRef},
|
||||
Adt, AsName, Const, Container, Enum, EnumVariant, Function, HasSource, ImplBlock, Name, Struct,
|
||||
Trait, TypeAlias, Union,
|
||||
Adt, Const, Container, Enum, EnumVariant, Function, HasSource, ImplBlock, Name, Struct, Trait,
|
||||
TypeAlias, Union,
|
||||
};
|
||||
|
||||
/// Data about a generic parameter (to a function, struct, impl, ...).
|
||||
|
@ -94,11 +94,15 @@ impl GenericParams {
|
|||
GenericDef::Adt(Adt::Enum(it)) => generics.fill(&it.source(db).ast, start),
|
||||
GenericDef::Trait(it) => {
|
||||
// traits get the Self type as an implicit first type parameter
|
||||
generics.params.push(GenericParam { idx: start, name: SELF_TYPE, default: None });
|
||||
generics.params.push(GenericParam {
|
||||
idx: start,
|
||||
name: name::SELF_TYPE,
|
||||
default: None,
|
||||
});
|
||||
generics.fill(&it.source(db).ast, start + 1);
|
||||
// add super traits as bounds on Self
|
||||
// i.e., trait Foo: Bar is equivalent to trait Foo where Self: Bar
|
||||
let self_param = TypeRef::Path(SELF_TYPE.into());
|
||||
let self_param = TypeRef::Path(name::SELF_TYPE.into());
|
||||
generics.fill_bounds(&it.source(db).ast, self_param);
|
||||
}
|
||||
GenericDef::TypeAlias(it) => generics.fill(&it.source(db).ast, start),
|
||||
|
|
|
@ -36,7 +36,6 @@ mod path;
|
|||
pub mod source_binder;
|
||||
|
||||
mod ids;
|
||||
mod name;
|
||||
mod nameres;
|
||||
mod adt;
|
||||
mod traits;
|
||||
|
@ -61,7 +60,7 @@ mod marks;
|
|||
|
||||
use hir_expand::AstId;
|
||||
|
||||
use crate::{ids::MacroFileKind, name::AsName, resolve::Resolver};
|
||||
use crate::{ids::MacroFileKind, resolve::Resolver};
|
||||
|
||||
pub use crate::{
|
||||
adt::VariantDef,
|
||||
|
@ -71,7 +70,6 @@ pub use crate::{
|
|||
generics::{GenericDef, GenericParam, GenericParams, HasGenericParams},
|
||||
ids::{HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFile},
|
||||
impl_block::ImplBlock,
|
||||
name::Name,
|
||||
nameres::{ImportId, Namespace, PerNs},
|
||||
path::{Path, PathKind},
|
||||
resolve::ScopeDef,
|
||||
|
@ -89,3 +87,5 @@ pub use self::code_model::{
|
|||
Enum, EnumVariant, FieldSource, FnData, Function, HasBody, MacroDef, Module, ModuleDef,
|
||||
ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union,
|
||||
};
|
||||
|
||||
pub use hir_def::name::Name;
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
pub use hir_def::name::*;
|
|
@ -1,6 +1,6 @@
|
|||
//! FIXME: write short doc here
|
||||
|
||||
use hir_def::nameres::raw;
|
||||
use hir_def::{name, nameres::raw};
|
||||
use ra_cfg::CfgOptions;
|
||||
use ra_db::FileId;
|
||||
use ra_syntax::{ast, SmolStr};
|
||||
|
@ -11,7 +11,6 @@ use crate::{
|
|||
attr::Attr,
|
||||
db::DefDatabase,
|
||||
ids::{AstItemDef, LocationCtx, MacroCallId, MacroCallLoc, MacroDefId, MacroFileKind},
|
||||
name::MACRO_RULES,
|
||||
nameres::{
|
||||
diagnostics::DefDiagnostic, mod_resolution::ModDir, Crate, CrateDefMap, CrateModuleId,
|
||||
ModuleData, ModuleDef, PerNs, ReachedFixedPoint, Resolution, ResolveMode,
|
||||
|
@ -726,7 +725,7 @@ where
|
|||
}
|
||||
|
||||
fn is_macro_rules(path: &Path) -> bool {
|
||||
path.as_ident() == Some(&MACRO_RULES)
|
||||
path.as_ident() == Some(&name::MACRO_RULES)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
//! Name resolution.
|
||||
use std::sync::Arc;
|
||||
|
||||
use hir_def::CrateModuleId;
|
||||
use hir_def::{
|
||||
name::{self, Name},
|
||||
CrateModuleId,
|
||||
};
|
||||
use rustc_hash::FxHashSet;
|
||||
|
||||
use crate::{
|
||||
|
@ -13,7 +16,6 @@ use crate::{
|
|||
},
|
||||
generics::GenericParams,
|
||||
impl_block::ImplBlock,
|
||||
name::{Name, SELF_PARAM, SELF_TYPE},
|
||||
nameres::{CrateDefMap, PerNs},
|
||||
path::{Path, PathKind},
|
||||
Adt, BuiltinType, Const, Enum, EnumVariant, Function, MacroDef, ModuleDef, Static, Struct,
|
||||
|
@ -150,13 +152,13 @@ impl Resolver {
|
|||
}
|
||||
}
|
||||
Scope::ImplBlockScope(impl_) => {
|
||||
if first_name == &SELF_TYPE {
|
||||
if first_name == &name::SELF_TYPE {
|
||||
let idx = if path.segments.len() == 1 { None } else { Some(1) };
|
||||
return Some((TypeNs::SelfType(*impl_), idx));
|
||||
}
|
||||
}
|
||||
Scope::AdtScope(adt) => {
|
||||
if first_name == &SELF_TYPE {
|
||||
if first_name == &name::SELF_TYPE {
|
||||
let idx = if path.segments.len() == 1 { None } else { Some(1) };
|
||||
return Some((TypeNs::AdtSelfType(*adt), idx));
|
||||
}
|
||||
|
@ -205,7 +207,7 @@ impl Resolver {
|
|||
return None;
|
||||
}
|
||||
let n_segments = path.segments.len();
|
||||
let tmp = SELF_PARAM;
|
||||
let tmp = name::SELF_PARAM;
|
||||
let first_name = if path.is_self() { &tmp } else { &path.segments.first()?.name };
|
||||
let skip_to_mod = path.kind != PathKind::Plain && !path.is_self();
|
||||
for scope in self.scopes.iter().rev() {
|
||||
|
@ -241,13 +243,13 @@ impl Resolver {
|
|||
Scope::GenericParams(_) => continue,
|
||||
|
||||
Scope::ImplBlockScope(impl_) if n_segments > 1 => {
|
||||
if first_name == &SELF_TYPE {
|
||||
if first_name == &name::SELF_TYPE {
|
||||
let ty = TypeNs::SelfType(*impl_);
|
||||
return Some(ResolveValueResult::Partial(ty, 1));
|
||||
}
|
||||
}
|
||||
Scope::AdtScope(adt) if n_segments > 1 => {
|
||||
if first_name == &SELF_TYPE {
|
||||
if first_name == &name::SELF_TYPE {
|
||||
let ty = TypeNs::AdtSelfType(*adt);
|
||||
return Some(ResolveValueResult::Partial(ty, 1));
|
||||
}
|
||||
|
@ -459,10 +461,10 @@ impl Scope {
|
|||
}
|
||||
}
|
||||
Scope::ImplBlockScope(i) => {
|
||||
f(SELF_TYPE, ScopeDef::ImplSelfType(*i));
|
||||
f(name::SELF_TYPE, ScopeDef::ImplSelfType(*i));
|
||||
}
|
||||
Scope::AdtScope(i) => {
|
||||
f(SELF_TYPE, ScopeDef::AdtSelfType(*i));
|
||||
f(name::SELF_TYPE, ScopeDef::AdtSelfType(*i));
|
||||
}
|
||||
Scope::ExprScope(e) => {
|
||||
e.expr_scopes.entries(e.scope_id).iter().for_each(|e| {
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
//! purely for "IDE needs".
|
||||
use std::sync::Arc;
|
||||
|
||||
use hir_def::name::AsName;
|
||||
use ra_db::FileId;
|
||||
use ra_syntax::{
|
||||
ast::{self, AstNode},
|
||||
|
@ -27,8 +28,8 @@ use crate::{
|
|||
path::known,
|
||||
resolve::{ScopeDef, TypeNs, ValueNs},
|
||||
ty::method_resolution::implements_trait,
|
||||
AsName, Const, DefWithBody, Either, Enum, FromSource, Function, HasBody, HirFileId, MacroDef,
|
||||
Module, Name, Path, Resolver, Static, Struct, Ty,
|
||||
Const, DefWithBody, Either, Enum, FromSource, Function, HasBody, HirFileId, MacroDef, Module,
|
||||
Name, Path, Resolver, Static, Struct, Ty,
|
||||
};
|
||||
|
||||
fn try_get_resolver_for_node(
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
//! HIR for trait definitions.
|
||||
|
||||
use rustc_hash::FxHashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
use hir_def::name::AsName;
|
||||
use ra_syntax::ast::{self, NameOwner};
|
||||
use rustc_hash::FxHashMap;
|
||||
|
||||
use crate::{
|
||||
db::{AstDatabase, DefDatabase},
|
||||
ids::LocationCtx,
|
||||
name::AsName,
|
||||
AssocItem, Const, Function, HasSource, Module, Name, Trait, TypeAlias,
|
||||
};
|
||||
|
||||
|
|
|
@ -5,10 +5,11 @@
|
|||
|
||||
use std::iter::successors;
|
||||
|
||||
use hir_def::name;
|
||||
use log::{info, warn};
|
||||
|
||||
use super::{traits::Solution, Canonical, Substs, Ty, TypeWalk};
|
||||
use crate::{db::HirDatabase, name, HasGenericParams, Resolver};
|
||||
use crate::{db::HirDatabase, HasGenericParams, Resolver};
|
||||
|
||||
const AUTODEREF_RECURSION_LIMIT: usize = 10;
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ use std::sync::Arc;
|
|||
use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue};
|
||||
use rustc_hash::FxHashMap;
|
||||
|
||||
use hir_def::name;
|
||||
use ra_arena::map::ArenaMap;
|
||||
use ra_prof::profile;
|
||||
use test_utils::tested_by;
|
||||
|
@ -37,7 +38,6 @@ use crate::{
|
|||
db::HirDatabase,
|
||||
diagnostics::DiagnosticSink,
|
||||
expr::{BindingAnnotation, Body, ExprId, PatId},
|
||||
name,
|
||||
path::known,
|
||||
resolve::{Resolver, TypeNs},
|
||||
ty::infer::diagnostics::InferenceDiagnostic,
|
||||
|
|
|
@ -3,12 +3,13 @@
|
|||
use std::iter::{repeat, repeat_with};
|
||||
use std::sync::Arc;
|
||||
|
||||
use hir_def::name;
|
||||
|
||||
use super::{BindingMode, Expectation, InferenceContext, InferenceDiagnostic, TypeMismatch};
|
||||
use crate::{
|
||||
db::HirDatabase,
|
||||
expr::{self, Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp},
|
||||
generics::{GenericParams, HasGenericParams},
|
||||
name,
|
||||
nameres::Namespace,
|
||||
path::{GenericArg, GenericArgs},
|
||||
ty::{
|
||||
|
|
|
@ -9,6 +9,7 @@ use chalk_ir::{
|
|||
};
|
||||
use chalk_rust_ir::{AssociatedTyDatum, ImplDatum, StructDatum, TraitDatum};
|
||||
|
||||
use hir_def::name;
|
||||
use ra_db::salsa::{InternId, InternKey};
|
||||
|
||||
use super::{Canonical, ChalkContext, Impl, Obligation};
|
||||
|
@ -734,7 +735,7 @@ fn closure_fn_trait_impl_datum(
|
|||
substs: Substs::build_for_def(db, trait_).push(self_ty).push(arg_ty).build(),
|
||||
};
|
||||
|
||||
let output_ty_id = fn_once_trait.associated_type_by_name(db, &crate::name::OUTPUT_TYPE)?;
|
||||
let output_ty_id = fn_once_trait.associated_type_by_name(db, &name::OUTPUT_TYPE)?;
|
||||
|
||||
let output_ty_value = chalk_rust_ir::AssociatedTyValue {
|
||||
associated_ty_id: output_ty_id.to_chalk(db),
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
use std::sync::Arc;
|
||||
|
||||
use hir_def::name::{AsName, Name};
|
||||
use ra_syntax::ast::NameOwner;
|
||||
|
||||
use crate::{
|
||||
db::{AstDatabase, DefDatabase},
|
||||
name::{AsName, Name},
|
||||
type_ref::TypeRef,
|
||||
HasSource, TypeAlias,
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue