mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-01 12:24:29 +00:00
Arena allocate LifetimeRefs
This commit is contained in:
parent
99a7e423e2
commit
61df8ec4b8
13 changed files with 126 additions and 60 deletions
|
|
@ -23,7 +23,8 @@ use hir_def::{
|
|||
nameres::DefMap,
|
||||
signatures::VariantFields,
|
||||
type_ref::{
|
||||
ConstRef, LifetimeRef, TraitBoundModifier, TypeBound, TypeRef, TypeRefId, UseArgRef,
|
||||
ConstRef, LifetimeRef, LifetimeRefId, TraitBoundModifier, TypeBound, TypeRef, TypeRefId,
|
||||
UseArgRef,
|
||||
},
|
||||
visibility::Visibility,
|
||||
};
|
||||
|
|
@ -2085,20 +2086,29 @@ impl<T: HirDisplayWithExpressionStore> HirDisplay for ExpressionStoreAdapter<'_,
|
|||
T::hir_fmt(&self.0, f, self.1)
|
||||
}
|
||||
}
|
||||
impl HirDisplayWithExpressionStore for LifetimeRef {
|
||||
impl HirDisplayWithExpressionStore for LifetimeRefId {
|
||||
fn hir_fmt(
|
||||
&self,
|
||||
f: &mut HirFormatter<'_>,
|
||||
_store: &ExpressionStore,
|
||||
store: &ExpressionStore,
|
||||
) -> Result<(), HirDisplayError> {
|
||||
match self {
|
||||
match &store[*self] {
|
||||
LifetimeRef::Named(name) => write!(f, "{}", name.display(f.db, f.edition())),
|
||||
LifetimeRef::Static => write!(f, "'static"),
|
||||
LifetimeRef::Placeholder => write!(f, "'_"),
|
||||
LifetimeRef::Error => write!(f, "'{{error}}"),
|
||||
&LifetimeRef::Param(lifetime_param_id) => {
|
||||
let generic_params = f.db.generic_params(lifetime_param_id.parent);
|
||||
write!(
|
||||
f,
|
||||
"{}",
|
||||
generic_params[lifetime_param_id.local_id].name.display(f.db, f.edition())
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HirDisplayWithExpressionStore for TypeRefId {
|
||||
fn hir_fmt(
|
||||
&self,
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ use hir_def::{
|
|||
layout::Integer,
|
||||
resolver::{HasResolver, ResolveValueResult, Resolver, TypeNs, ValueNs},
|
||||
signatures::{ConstSignature, StaticSignature},
|
||||
type_ref::{ConstRef, LifetimeRef, TypeRefId},
|
||||
type_ref::{ConstRef, LifetimeRefId, TypeRefId},
|
||||
};
|
||||
use hir_expand::{mod_path::ModPath, name::Name};
|
||||
use indexmap::IndexSet;
|
||||
|
|
@ -1391,7 +1391,7 @@ impl<'a> InferenceContext<'a> {
|
|||
self.result.standard_types.unknown.clone()
|
||||
}
|
||||
|
||||
fn make_body_lifetime(&mut self, lifetime_ref: &LifetimeRef) -> Lifetime {
|
||||
fn make_body_lifetime(&mut self, lifetime_ref: LifetimeRefId) -> Lifetime {
|
||||
let lt = self.with_ty_lowering(
|
||||
self.body,
|
||||
InferenceTyDiagnosticSource::Body,
|
||||
|
|
|
|||
|
|
@ -2099,7 +2099,7 @@ impl InferenceContext<'_> {
|
|||
) -> crate::GenericArg {
|
||||
match (param, arg) {
|
||||
(GenericParamDataRef::LifetimeParamData(_), GenericArg::Lifetime(lifetime)) => {
|
||||
self.ctx.make_body_lifetime(lifetime).cast(Interner)
|
||||
self.ctx.make_body_lifetime(*lifetime).cast(Interner)
|
||||
}
|
||||
(GenericParamDataRef::TypeParamData(_), GenericArg::Type(type_ref)) => {
|
||||
self.ctx.make_body_ty(*type_ref).cast(Interner)
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ use hir_def::{
|
|||
resolver::{HasResolver, LifetimeNs, Resolver, TypeNs},
|
||||
signatures::{FunctionSignature, TraitFlags, TypeAliasFlags},
|
||||
type_ref::{
|
||||
ConstRef, LifetimeRef, LiteralConstRef, PathId, TraitBoundModifier,
|
||||
ConstRef, LifetimeRefId, LiteralConstRef, PathId, TraitBoundModifier,
|
||||
TraitRef as HirTraitRef, TypeBound, TypeRef, TypeRefId,
|
||||
},
|
||||
};
|
||||
|
|
@ -370,7 +370,7 @@ impl<'a> TyLoweringContext<'a> {
|
|||
let lifetime = ref_
|
||||
.lifetime
|
||||
.as_ref()
|
||||
.map_or_else(error_lifetime, |lr| self.lower_lifetime(lr));
|
||||
.map_or_else(error_lifetime, |&lr| self.lower_lifetime(lr));
|
||||
TyKind::Ref(lower_to_chalk_mutability(ref_.mutability), lifetime, inner_ty)
|
||||
.intern(Interner)
|
||||
}
|
||||
|
|
@ -561,7 +561,7 @@ impl<'a> TyLoweringContext<'a> {
|
|||
let self_ty = self.lower_ty(*target);
|
||||
Either::Left(self.lower_type_bound(bound, self_ty, ignore_bindings))
|
||||
}
|
||||
WherePredicate::Lifetime { bound, target } => Either::Right(iter::once(
|
||||
&WherePredicate::Lifetime { bound, target } => Either::Right(iter::once(
|
||||
crate::wrap_empty_binders(WhereClause::LifetimeOutlives(LifetimeOutlives {
|
||||
a: self.lower_lifetime(bound),
|
||||
b: self.lower_lifetime(target),
|
||||
|
|
@ -604,7 +604,7 @@ impl<'a> TyLoweringContext<'a> {
|
|||
self.unsized_types.insert(self_ty);
|
||||
}
|
||||
}
|
||||
TypeBound::Lifetime(l) => {
|
||||
&TypeBound::Lifetime(l) => {
|
||||
let lifetime = self.lower_lifetime(l);
|
||||
clause = Some(crate::wrap_empty_binders(WhereClause::TypeOutlives(TypeOutlives {
|
||||
ty: self_ty,
|
||||
|
|
@ -755,8 +755,8 @@ impl<'a> TyLoweringContext<'a> {
|
|||
ImplTrait { bounds: crate::make_single_type_binders(predicates) }
|
||||
}
|
||||
|
||||
pub fn lower_lifetime(&self, lifetime: &LifetimeRef) -> Lifetime {
|
||||
match self.resolver.resolve_lifetime(lifetime) {
|
||||
pub fn lower_lifetime(&self, lifetime: LifetimeRefId) -> Lifetime {
|
||||
match self.resolver.resolve_lifetime(&self.store[lifetime]) {
|
||||
Some(resolution) => match resolution {
|
||||
LifetimeNs::Static => static_lifetime(),
|
||||
LifetimeNs::LifetimeParam(id) => match self.type_param_mode {
|
||||
|
|
|
|||
|
|
@ -702,7 +702,7 @@ impl<'a, 'b> PathLoweringContext<'a, 'b> {
|
|||
) -> crate::GenericArg {
|
||||
match (param, arg) {
|
||||
(GenericParamDataRef::LifetimeParamData(_), GenericArg::Lifetime(lifetime)) => {
|
||||
self.ctx.ctx.lower_lifetime(lifetime).cast(Interner)
|
||||
self.ctx.ctx.lower_lifetime(*lifetime).cast(Interner)
|
||||
}
|
||||
(GenericParamDataRef::TypeParamData(_), GenericArg::Type(type_ref)) => {
|
||||
self.ctx.ctx.lower_ty(*type_ref).cast(Interner)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue