mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Remove SourceMap
This commit is contained in:
parent
fe2b1615de
commit
72bb49467d
2 changed files with 11 additions and 34 deletions
|
@ -90,13 +90,6 @@ pub enum WherePredicateTypeTarget {
|
|||
TypeParam(LocalTypeParamId),
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub(crate) struct SourceMap {
|
||||
pub(crate) type_params: ArenaMap<LocalTypeParamId, Either<ast::TypeParam, ast::Trait>>,
|
||||
lifetime_params: ArenaMap<LocalLifetimeParamId, ast::LifetimeParam>,
|
||||
const_params: ArenaMap<LocalConstParamId, ast::ConstParam>,
|
||||
}
|
||||
|
||||
impl GenericParams {
|
||||
pub(crate) fn generic_params_query(
|
||||
db: &dyn DefDatabase,
|
||||
|
@ -153,14 +146,9 @@ impl GenericParams {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn fill(
|
||||
&mut self,
|
||||
lower_ctx: &LowerCtx,
|
||||
sm: &mut SourceMap,
|
||||
node: &dyn HasGenericParams,
|
||||
) {
|
||||
pub(crate) fn fill(&mut self, lower_ctx: &LowerCtx, node: &dyn HasGenericParams) {
|
||||
if let Some(params) = node.generic_param_list() {
|
||||
self.fill_params(lower_ctx, sm, params)
|
||||
self.fill_params(lower_ctx, params)
|
||||
}
|
||||
if let Some(where_clause) = node.where_clause() {
|
||||
self.fill_where_predicates(lower_ctx, where_clause);
|
||||
|
@ -180,12 +168,7 @@ impl GenericParams {
|
|||
}
|
||||
}
|
||||
|
||||
fn fill_params(
|
||||
&mut self,
|
||||
lower_ctx: &LowerCtx,
|
||||
sm: &mut SourceMap,
|
||||
params: ast::GenericParamList,
|
||||
) {
|
||||
fn fill_params(&mut self, lower_ctx: &LowerCtx, params: ast::GenericParamList) {
|
||||
for type_param in params.type_params() {
|
||||
let name = type_param.name().map_or_else(Name::missing, |it| it.as_name());
|
||||
// FIXME: Use `Path::from_src`
|
||||
|
@ -196,9 +179,7 @@ impl GenericParams {
|
|||
default,
|
||||
provenance: TypeParamProvenance::TypeParamList,
|
||||
};
|
||||
let param_id = self.types.alloc(param);
|
||||
sm.type_params.insert(param_id, Either::Left(type_param.clone()));
|
||||
|
||||
self.types.alloc(param);
|
||||
let type_ref = TypeRef::Path(name.into());
|
||||
self.fill_bounds(lower_ctx, &type_param, Either::Left(type_ref));
|
||||
}
|
||||
|
@ -206,8 +187,7 @@ impl GenericParams {
|
|||
let name =
|
||||
lifetime_param.lifetime().map_or_else(Name::missing, |lt| Name::new_lifetime(<));
|
||||
let param = LifetimeParamData { name: name.clone() };
|
||||
let param_id = self.lifetimes.alloc(param);
|
||||
sm.lifetime_params.insert(param_id, lifetime_param.clone());
|
||||
self.lifetimes.alloc(param);
|
||||
let lifetime_ref = LifetimeRef::new_name(name);
|
||||
self.fill_bounds(lower_ctx, &lifetime_param, Either::Right(lifetime_ref));
|
||||
}
|
||||
|
@ -215,8 +195,7 @@ impl GenericParams {
|
|||
let name = const_param.name().map_or_else(Name::missing, |it| it.as_name());
|
||||
let ty = const_param.ty().map_or(TypeRef::Error, |it| TypeRef::from_ast(lower_ctx, it));
|
||||
let param = ConstParamData { name, ty: Interned::new(ty) };
|
||||
let param_id = self.consts.alloc(param);
|
||||
sm.const_params.insert(param_id, const_param.clone());
|
||||
self.consts.alloc(param);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -662,11 +662,10 @@ impl<'a> Ctx<'a> {
|
|||
owner: GenericsOwner<'_>,
|
||||
node: &impl ast::HasGenericParams,
|
||||
) -> Interned<GenericParams> {
|
||||
let mut sm = &mut Default::default();
|
||||
let mut generics = GenericParams::default();
|
||||
match owner {
|
||||
GenericsOwner::Function(func) => {
|
||||
generics.fill(&self.body_ctx, sm, node);
|
||||
generics.fill(&self.body_ctx, node);
|
||||
// lower `impl Trait` in arguments
|
||||
for id in func.params.clone() {
|
||||
if let Param::Normal(ty) = &self.data().params[id] {
|
||||
|
@ -678,27 +677,26 @@ impl<'a> Ctx<'a> {
|
|||
| GenericsOwner::Enum
|
||||
| GenericsOwner::Union
|
||||
| GenericsOwner::TypeAlias => {
|
||||
generics.fill(&self.body_ctx, sm, node);
|
||||
generics.fill(&self.body_ctx, node);
|
||||
}
|
||||
GenericsOwner::Trait(trait_def) => {
|
||||
// traits get the Self type as an implicit first type parameter
|
||||
let self_param_id = generics.types.alloc(TypeParamData {
|
||||
generics.types.alloc(TypeParamData {
|
||||
name: Some(name![Self]),
|
||||
default: None,
|
||||
provenance: TypeParamProvenance::TraitSelf,
|
||||
});
|
||||
sm.type_params.insert(self_param_id, Either::Right(trait_def.clone()));
|
||||
// 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(name![Self].into());
|
||||
generics.fill_bounds(&self.body_ctx, trait_def, Either::Left(self_param));
|
||||
generics.fill(&self.body_ctx, &mut sm, node);
|
||||
generics.fill(&self.body_ctx, node);
|
||||
}
|
||||
GenericsOwner::Impl => {
|
||||
// Note that we don't add `Self` here: in `impl`s, `Self` is not a
|
||||
// type-parameter, but rather is a type-alias for impl's target
|
||||
// type, so this is handled by the resolver.
|
||||
generics.fill(&self.body_ctx, &mut sm, node);
|
||||
generics.fill(&self.body_ctx, node);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue