Skip to content

Commit

Permalink
Merge pull request #18447 from ChayimFriedman2/cleanup-tylowerctx
Browse files Browse the repository at this point in the history
Avoid interior mutability in `TyLoweringContext`
  • Loading branch information
Veykril authored Oct 31, 2024
2 parents 1aac2c6 + 4317927 commit 86a850d
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 224 deletions.
18 changes: 10 additions & 8 deletions crates/hir-ty/src/chalk_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ pub(crate) fn associated_ty_data_query(
let type_alias_data = db.type_alias_data(type_alias);
let generic_params = generics(db.upcast(), type_alias.into());
let resolver = hir_def::resolver::HasResolver::resolver(type_alias, db.upcast());
let ctx =
let mut ctx =
crate::TyLoweringContext::new(db, &resolver, &type_alias_data.types_map, type_alias.into())
.with_type_param_mode(crate::lower::ParamLoweringMode::Variable);

Expand All @@ -627,14 +627,16 @@ pub(crate) fn associated_ty_data_query(
.build();
let self_ty = TyKind::Alias(AliasTy::Projection(pro_ty)).intern(Interner);

let mut bounds: Vec<_> = type_alias_data
.bounds
.iter()
.flat_map(|bound| ctx.lower_type_bound(bound, self_ty.clone(), false))
.filter_map(|pred| generic_predicate_to_inline_bound(db, &pred, &self_ty))
.collect();
let mut bounds = Vec::new();
for bound in &type_alias_data.bounds {
ctx.lower_type_bound(bound, self_ty.clone(), false).for_each(|pred| {
if let Some(pred) = generic_predicate_to_inline_bound(db, &pred, &self_ty) {
bounds.push(pred);
}
});
}

if !ctx.unsized_types.borrow().contains(&self_ty) {
if !ctx.unsized_types.contains(&self_ty) {
let sized_trait = db
.lang_item(resolver.krate(), LangItem::Sized)
.and_then(|lang_item| lang_item.as_trait().map(to_chalk_trait_id));
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-ty/src/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,7 @@ impl<'a> InferenceContext<'a> {
Some(path) => path,
None => return (self.err_ty(), None),
};
let ctx = crate::lower::TyLoweringContext::new(
let mut ctx = crate::lower::TyLoweringContext::new(
self.db,
&self.resolver,
&self.body.types,
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-ty/src/infer/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl InferenceContext<'_> {
let last = path.segments().last()?;

// Don't use `self.make_ty()` here as we need `orig_ns`.
let ctx = crate::lower::TyLoweringContext::new(
let mut ctx = crate::lower::TyLoweringContext::new(
self.db,
&self.resolver,
&self.body.types,
Expand Down
Loading

0 comments on commit 86a850d

Please sign in to comment.