Skip to content

Commit b25a3de

Browse files
authored
Merge pull request rust-lang#18447 from ChayimFriedman2/cleanup-tylowerctx
Avoid interior mutability in `TyLoweringContext`
2 parents 2a9b851 + 5aff110 commit b25a3de

File tree

4 files changed

+201
-224
lines changed

4 files changed

+201
-224
lines changed

src/tools/rust-analyzer/crates/hir-ty/src/chalk_db.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ pub(crate) fn associated_ty_data_query(
615615
let type_alias_data = db.type_alias_data(type_alias);
616616
let generic_params = generics(db.upcast(), type_alias.into());
617617
let resolver = hir_def::resolver::HasResolver::resolver(type_alias, db.upcast());
618-
let ctx =
618+
let mut ctx =
619619
crate::TyLoweringContext::new(db, &resolver, &type_alias_data.types_map, type_alias.into())
620620
.with_type_param_mode(crate::lower::ParamLoweringMode::Variable);
621621

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

630-
let mut bounds: Vec<_> = type_alias_data
631-
.bounds
632-
.iter()
633-
.flat_map(|bound| ctx.lower_type_bound(bound, self_ty.clone(), false))
634-
.filter_map(|pred| generic_predicate_to_inline_bound(db, &pred, &self_ty))
635-
.collect();
630+
let mut bounds = Vec::new();
631+
for bound in &type_alias_data.bounds {
632+
ctx.lower_type_bound(bound, self_ty.clone(), false).for_each(|pred| {
633+
if let Some(pred) = generic_predicate_to_inline_bound(db, &pred, &self_ty) {
634+
bounds.push(pred);
635+
}
636+
});
637+
}
636638

637-
if !ctx.unsized_types.borrow().contains(&self_ty) {
639+
if !ctx.unsized_types.contains(&self_ty) {
638640
let sized_trait = db
639641
.lang_item(resolver.krate(), LangItem::Sized)
640642
.and_then(|lang_item| lang_item.as_trait().map(to_chalk_trait_id));

src/tools/rust-analyzer/crates/hir-ty/src/infer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1420,7 +1420,7 @@ impl<'a> InferenceContext<'a> {
14201420
Some(path) => path,
14211421
None => return (self.err_ty(), None),
14221422
};
1423-
let ctx = crate::lower::TyLoweringContext::new(
1423+
let mut ctx = crate::lower::TyLoweringContext::new(
14241424
self.db,
14251425
&self.resolver,
14261426
&self.body.types,

src/tools/rust-analyzer/crates/hir-ty/src/infer/path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl InferenceContext<'_> {
151151
let last = path.segments().last()?;
152152

153153
// Don't use `self.make_ty()` here as we need `orig_ns`.
154-
let ctx = crate::lower::TyLoweringContext::new(
154+
let mut ctx = crate::lower::TyLoweringContext::new(
155155
self.db,
156156
&self.resolver,
157157
&self.body.types,

0 commit comments

Comments
 (0)