implement creating generics for impl traits in associated types

This commit is contained in:
dfireBird 2024-04-29 23:55:02 +05:30
parent f216be4a07
commit 40a677ddf0
No known key found for this signature in database
GPG key ID: 26D522CA5FC2B93D
6 changed files with 102 additions and 17 deletions

View file

@ -1,26 +1,34 @@
//! Context for lowering paths.
use std::cell::OnceCell;
use std::cell::{OnceCell, RefCell};
use hir_expand::{
span_map::{SpanMap, SpanMapRef},
AstId, HirFileId, InFile,
};
use intern::Interned;
use span::{AstIdMap, AstIdNode};
use syntax::ast;
use triomphe::Arc;
use crate::{db::DefDatabase, path::Path};
use crate::{db::DefDatabase, path::Path, type_ref::TypeBound};
pub struct LowerCtx<'a> {
pub db: &'a dyn DefDatabase,
file_id: HirFileId,
span_map: OnceCell<SpanMap>,
ast_id_map: OnceCell<Arc<AstIdMap>>,
impl_trait_bounds: RefCell<Vec<Vec<Interned<TypeBound>>>>,
}
impl<'a> LowerCtx<'a> {
pub fn new(db: &'a dyn DefDatabase, file_id: HirFileId) -> Self {
LowerCtx { db, file_id, span_map: OnceCell::new(), ast_id_map: OnceCell::new() }
LowerCtx {
db,
file_id,
span_map: OnceCell::new(),
ast_id_map: OnceCell::new(),
impl_trait_bounds: RefCell::new(Vec::new()),
}
}
pub fn with_span_map_cell(
@ -28,7 +36,13 @@ impl<'a> LowerCtx<'a> {
file_id: HirFileId,
span_map: OnceCell<SpanMap>,
) -> Self {
LowerCtx { db, file_id, span_map, ast_id_map: OnceCell::new() }
LowerCtx {
db,
file_id,
span_map,
ast_id_map: OnceCell::new(),
impl_trait_bounds: RefCell::new(Vec::new()),
}
}
pub(crate) fn span_map(&self) -> SpanMapRef<'_> {
@ -45,4 +59,12 @@ impl<'a> LowerCtx<'a> {
self.ast_id_map.get_or_init(|| self.db.ast_id_map(self.file_id)).ast_id(item),
)
}
pub fn update_impl_traits_bounds(&self, bounds: Vec<Interned<TypeBound>>) {
self.impl_trait_bounds.borrow_mut().push(bounds);
}
pub fn take_impl_traits_bounds(&self) -> Vec<Vec<Interned<TypeBound>>> {
self.impl_trait_bounds.borrow_mut().drain(..).collect()
}
}