mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
Merge #2399
2399: Use GenericDefId more r=matklad a=matklad Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
c46cea2ad8
5 changed files with 20 additions and 33 deletions
|
@ -24,7 +24,7 @@ pub use hir_def::{
|
||||||
RawItemsWithSourceMapQuery, StaticDataQuery, StructDataQuery, TraitDataQuery,
|
RawItemsWithSourceMapQuery, StaticDataQuery, StructDataQuery, TraitDataQuery,
|
||||||
TypeAliasDataQuery,
|
TypeAliasDataQuery,
|
||||||
},
|
},
|
||||||
LocalStructFieldId, VariantId,
|
GenericDefId, LocalStructFieldId, VariantId,
|
||||||
};
|
};
|
||||||
pub use hir_expand::db::{
|
pub use hir_expand::db::{
|
||||||
AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery,
|
AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery,
|
||||||
|
@ -54,7 +54,7 @@ pub trait HirDatabase: DefDatabase {
|
||||||
) -> Arc<[GenericPredicate]>;
|
) -> Arc<[GenericPredicate]>;
|
||||||
|
|
||||||
#[salsa::invoke(crate::ty::generic_predicates_query)]
|
#[salsa::invoke(crate::ty::generic_predicates_query)]
|
||||||
fn generic_predicates(&self, def: GenericDef) -> Arc<[GenericPredicate]>;
|
fn generic_predicates(&self, def: GenericDefId) -> Arc<[GenericPredicate]>;
|
||||||
|
|
||||||
#[salsa::invoke(crate::ty::generic_defaults_query)]
|
#[salsa::invoke(crate::ty::generic_defaults_query)]
|
||||||
fn generic_defaults(&self, def: GenericDef) -> Substs;
|
fn generic_defaults(&self, def: GenericDef) -> Substs;
|
||||||
|
|
|
@ -9,9 +9,8 @@ use hir_def::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ty::{CallableDef, TypableDef},
|
ty::TypableDef, Adt, AssocItem, AttrDef, Const, Crate, DefWithBody, EnumVariant, Function,
|
||||||
Adt, AssocItem, AttrDef, Const, Crate, DefWithBody, EnumVariant, Function, GenericDef,
|
GenericDef, ModuleDef, Static, StructField, TypeAlias, VariantDef,
|
||||||
ModuleDef, Static, StructField, TypeAlias, VariantDef,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
impl From<ra_db::CrateId> for Crate {
|
impl From<ra_db::CrateId> for Crate {
|
||||||
|
@ -214,18 +213,6 @@ impl From<Adt> for GenericDefId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<CallableDef> for GenericDefId {
|
|
||||||
fn from(def: CallableDef) -> Self {
|
|
||||||
match def {
|
|
||||||
CallableDef::Function(it) => it.id.into(),
|
|
||||||
CallableDef::Struct(it) => it.id.into(),
|
|
||||||
CallableDef::EnumVariant(it) => {
|
|
||||||
EnumVariantId { parent: it.parent.id, local_id: it.id }.into()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<VariantDef> for VariantId {
|
impl From<VariantDef> for VariantId {
|
||||||
fn from(def: VariantDef) -> Self {
|
fn from(def: VariantDef) -> Self {
|
||||||
match def {
|
match def {
|
||||||
|
|
|
@ -17,7 +17,7 @@ use std::ops::Deref;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::{fmt, iter, mem};
|
use std::{fmt, iter, mem};
|
||||||
|
|
||||||
use hir_def::{generics::GenericParams, AdtId};
|
use hir_def::{generics::GenericParams, AdtId, GenericDefId};
|
||||||
use ra_db::{impl_intern_key, salsa};
|
use ra_db::{impl_intern_key, salsa};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -176,7 +176,7 @@ impl TypeCtor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_generic_def(self) -> Option<crate::GenericDef> {
|
pub fn as_generic_def(self) -> Option<GenericDefId> {
|
||||||
match self {
|
match self {
|
||||||
TypeCtor::Bool
|
TypeCtor::Bool
|
||||||
| TypeCtor::Char
|
| TypeCtor::Char
|
||||||
|
@ -193,7 +193,7 @@ impl TypeCtor {
|
||||||
| TypeCtor::Closure { .. } => None,
|
| TypeCtor::Closure { .. } => None,
|
||||||
TypeCtor::Adt(adt) => Some(adt.into()),
|
TypeCtor::Adt(adt) => Some(adt.into()),
|
||||||
TypeCtor::FnDef(callable) => Some(callable.into()),
|
TypeCtor::FnDef(callable) => Some(callable.into()),
|
||||||
TypeCtor::AssociatedType(type_alias) => Some(type_alias.into()),
|
TypeCtor::AssociatedType(type_alias) => Some(type_alias.id.into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ use hir_def::{
|
||||||
path::{GenericArg, PathSegment},
|
path::{GenericArg, PathSegment},
|
||||||
resolver::{HasResolver, Resolver, TypeNs},
|
resolver::{HasResolver, Resolver, TypeNs},
|
||||||
type_ref::{TypeBound, TypeRef},
|
type_ref::{TypeBound, TypeRef},
|
||||||
AdtId, GenericDefId, LocalStructFieldId, VariantId,
|
AdtId, EnumVariantId, GenericDefId, LocalStructFieldId, VariantId,
|
||||||
};
|
};
|
||||||
use ra_arena::map::ArenaMap;
|
use ra_arena::map::ArenaMap;
|
||||||
|
|
||||||
|
@ -605,9 +605,9 @@ impl TraitEnvironment {
|
||||||
/// Resolve the where clause(s) of an item with generics.
|
/// Resolve the where clause(s) of an item with generics.
|
||||||
pub(crate) fn generic_predicates_query(
|
pub(crate) fn generic_predicates_query(
|
||||||
db: &impl HirDatabase,
|
db: &impl HirDatabase,
|
||||||
def: GenericDef,
|
def: GenericDefId,
|
||||||
) -> Arc<[GenericPredicate]> {
|
) -> Arc<[GenericPredicate]> {
|
||||||
let resolver = GenericDefId::from(def).resolver(db);
|
let resolver = def.resolver(db);
|
||||||
resolver
|
resolver
|
||||||
.where_predicates_in_scope()
|
.where_predicates_in_scope()
|
||||||
.flat_map(|pred| GenericPredicate::from_where_predicate(db, &resolver, pred))
|
.flat_map(|pred| GenericPredicate::from_where_predicate(db, &resolver, pred))
|
||||||
|
@ -819,12 +819,12 @@ impl CallableDef {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<CallableDef> for GenericDef {
|
impl From<CallableDef> for GenericDefId {
|
||||||
fn from(def: CallableDef) -> GenericDef {
|
fn from(def: CallableDef) -> GenericDefId {
|
||||||
match def {
|
match def {
|
||||||
CallableDef::Function(f) => f.into(),
|
CallableDef::Function(f) => f.id.into(),
|
||||||
CallableDef::Struct(s) => s.into(),
|
CallableDef::Struct(s) => s.id.into(),
|
||||||
CallableDef::EnumVariant(e) => e.into(),
|
CallableDef::EnumVariant(e) => EnumVariantId::from(e).into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ use chalk_ir::{
|
||||||
};
|
};
|
||||||
use chalk_rust_ir::{AssociatedTyDatum, AssociatedTyValue, ImplDatum, StructDatum, TraitDatum};
|
use chalk_rust_ir::{AssociatedTyDatum, AssociatedTyValue, ImplDatum, StructDatum, TraitDatum};
|
||||||
|
|
||||||
use hir_def::lang_item::LangItemTarget;
|
use hir_def::{lang_item::LangItemTarget, GenericDefId};
|
||||||
use hir_expand::name;
|
use hir_expand::name;
|
||||||
|
|
||||||
use ra_db::salsa::{InternId, InternKey};
|
use ra_db::salsa::{InternId, InternKey};
|
||||||
|
@ -19,7 +19,7 @@ use crate::{
|
||||||
db::HirDatabase,
|
db::HirDatabase,
|
||||||
ty::display::HirDisplay,
|
ty::display::HirDisplay,
|
||||||
ty::{ApplicationTy, GenericPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk},
|
ty::{ApplicationTy, GenericPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk},
|
||||||
Crate, GenericDef, ImplBlock, Trait, TypeAlias,
|
Crate, ImplBlock, Trait, TypeAlias,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// This represents a trait whose name we could not resolve.
|
/// This represents a trait whose name we could not resolve.
|
||||||
|
@ -402,7 +402,7 @@ fn make_binders<T>(value: T, num_vars: usize) -> chalk_ir::Binders<T> {
|
||||||
|
|
||||||
fn convert_where_clauses(
|
fn convert_where_clauses(
|
||||||
db: &impl HirDatabase,
|
db: &impl HirDatabase,
|
||||||
def: GenericDef,
|
def: GenericDefId,
|
||||||
substs: &Substs,
|
substs: &Substs,
|
||||||
) -> Vec<chalk_ir::QuantifiedWhereClause<ChalkIr>> {
|
) -> Vec<chalk_ir::QuantifiedWhereClause<ChalkIr>> {
|
||||||
let generic_predicates = db.generic_predicates(def);
|
let generic_predicates = db.generic_predicates(def);
|
||||||
|
@ -561,7 +561,7 @@ pub(crate) fn trait_datum_query(
|
||||||
marker: false,
|
marker: false,
|
||||||
fundamental: false,
|
fundamental: false,
|
||||||
};
|
};
|
||||||
let where_clauses = convert_where_clauses(db, trait_.into(), &bound_vars);
|
let where_clauses = convert_where_clauses(db, trait_.id.into(), &bound_vars);
|
||||||
let associated_ty_ids = trait_
|
let associated_ty_ids = trait_
|
||||||
.items(db)
|
.items(db)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -643,7 +643,7 @@ fn impl_block_datum(
|
||||||
} else {
|
} else {
|
||||||
chalk_rust_ir::ImplType::External
|
chalk_rust_ir::ImplType::External
|
||||||
};
|
};
|
||||||
let where_clauses = convert_where_clauses(db, impl_block.into(), &bound_vars);
|
let where_clauses = convert_where_clauses(db, impl_block.id.into(), &bound_vars);
|
||||||
let negative = impl_block.is_negative(db);
|
let negative = impl_block.is_negative(db);
|
||||||
debug!(
|
debug!(
|
||||||
"impl {:?}: {}{} where {:?}",
|
"impl {:?}: {}{} where {:?}",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue