Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/expr_store/lower/generics.rs')
-rw-r--r--crates/hir-def/src/expr_store/lower/generics.rs40
1 files changed, 15 insertions, 25 deletions
diff --git a/crates/hir-def/src/expr_store/lower/generics.rs b/crates/hir-def/src/expr_store/lower/generics.rs
index c570df42b2..5ffc4f5851 100644
--- a/crates/hir-def/src/expr_store/lower/generics.rs
+++ b/crates/hir-def/src/expr_store/lower/generics.rs
@@ -3,15 +3,12 @@
//! generic parameters. See also the `Generics` type and the `generics_of` query
//! in rustc.
-use std::sync::LazyLock;
-
use either::Either;
use hir_expand::name::{AsName, Name};
use intern::sym;
use la_arena::Arena;
use syntax::ast::{self, HasName, HasTypeBounds};
use thin_vec::ThinVec;
-use triomphe::Arc;
use crate::{
GenericDefId, TypeOrConstParamId, TypeParamId,
@@ -84,28 +81,16 @@ impl GenericParamsCollector {
)
}
- pub(crate) fn finish(self) -> Arc<GenericParams> {
- let Self { mut lifetimes, mut type_or_consts, mut where_predicates, parent: _ } = self;
-
- if lifetimes.is_empty() && type_or_consts.is_empty() && where_predicates.is_empty() {
- static EMPTY: LazyLock<Arc<GenericParams>> = LazyLock::new(|| {
- Arc::new(GenericParams {
- lifetimes: Arena::new(),
- type_or_consts: Arena::new(),
- where_predicates: Box::default(),
- })
- });
- return Arc::clone(&EMPTY);
- }
+ pub(crate) fn finish(self) -> GenericParams {
+ let Self { mut lifetimes, mut type_or_consts, where_predicates, parent: _ } = self;
lifetimes.shrink_to_fit();
type_or_consts.shrink_to_fit();
- where_predicates.shrink_to_fit();
- Arc::new(GenericParams {
+ GenericParams {
type_or_consts,
lifetimes,
where_predicates: where_predicates.into_boxed_slice(),
- })
+ }
}
fn lower_param_list(&mut self, ec: &mut ExprCollector<'_>, params: ast::GenericParamList) {
@@ -141,12 +126,17 @@ impl GenericParamsCollector {
const_param.ty(),
&mut ExprCollector::impl_trait_error_allocator,
);
- let param = ConstParamData {
- name,
- ty,
- default: const_param.default_val().map(|it| ec.lower_const_arg(it)),
- };
- let _idx = self.type_or_consts.alloc(param.into());
+ let default = const_param.default_val().map(|it| ec.lower_const_arg(it));
+ let param = ConstParamData { name, ty, default };
+ let idx = self.type_or_consts.alloc(param.into());
+ if let Some(default) = default
+ && let Some(const_expr_origins) = &mut ec.store.inference_roots
+ {
+ const_expr_origins.push((
+ default.expr,
+ crate::expr_store::RootExprOrigin::ConstParam(idx),
+ ));
+ }
}
ast::GenericParam::LifetimeParam(lifetime_param) => {
let lifetime = ec.lower_lifetime_ref_opt(lifetime_param.lifetime());