Skip to content

Commit f769d34

Browse files
committedJan 9, 2023
Assert defining anchor is set in take_opaque_types
1 parent 5132e13 commit f769d34

File tree

10 files changed

+13
-19
lines changed

10 files changed

+13
-19
lines changed
 

‎compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
318318

319319
// This is still required for many(half of the tests in ui/type-alias-impl-trait)
320320
// tests to pass
321-
let _ = infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
321+
let _ = infcx.take_opaque_types();
322322

323323
if errors.is_empty() {
324324
definition_ty

‎compiler/rustc_borrowck/src/type_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ pub(crate) fn type_check<'mir, 'tcx>(
208208
);
209209

210210
translate_outlives_facts(&mut checker);
211-
let opaque_type_values = infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
211+
let opaque_type_values = infcx.take_opaque_types();
212212

213213
let opaque_type_values = opaque_type_values
214214
.into_iter()

‎compiler/rustc_const_eval/src/util/compare_types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ pub fn is_subtype<'tcx>(
5858
// even if they're constrained in our current function.
5959
//
6060
// It seems very unlikely that this hides any bugs.
61-
let _ = infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
61+
let _ = infcx.take_opaque_types();
6262
errors.is_empty()
6363
}

‎compiler/rustc_hir_analysis/src/check/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ fn check_opaque_meets_bounds<'tcx>(
475475
}
476476
}
477477
// Clean up after ourselves
478-
let _ = infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
478+
let _ = infcx.take_opaque_types();
479479
}
480480

481481
fn is_enum_of_nonnullable_ptr<'tcx>(

‎compiler/rustc_hir_typeck/src/writeback.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
534534

535535
#[instrument(skip(self), level = "debug")]
536536
fn visit_opaque_types(&mut self) {
537-
let opaque_types =
538-
self.fcx.infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
537+
let opaque_types = self.fcx.infcx.take_opaque_types();
539538
for (opaque_type_key, decl) in opaque_types {
540539
let hidden_type = self.resolve(decl.hidden_type, &decl.hidden_type.span);
541540
let opaque_type_key = self.resolve(opaque_type_key, &decl.hidden_type.span);

‎compiler/rustc_infer/src/infer/canonical/query_response.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,7 @@ impl<'tcx> InferCtxt<'tcx> {
156156
/// As the new solver does canonicalization slightly differently, this is also used there
157157
/// for now. This should hopefully change fairly soon.
158158
pub fn take_opaque_types_for_query_response(&self) -> Vec<(Ty<'tcx>, Ty<'tcx>)> {
159-
self.inner
160-
.borrow_mut()
161-
.opaque_type_storage
162-
.take_opaque_types()
159+
std::mem::take(&mut self.inner.borrow_mut().opaque_type_storage.opaque_types)
163160
.into_iter()
164161
.map(|(k, v)| (self.tcx.mk_opaque(k.def_id.to_def_id(), k.substs), v.hidden_type.ty))
165162
.collect()

‎compiler/rustc_infer/src/infer/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,12 @@ impl<'tcx> InferCtxt<'tcx> {
13381338
var_infos
13391339
}
13401340

1341+
#[instrument(level = "debug", skip(self), ret)]
1342+
pub fn take_opaque_types(&self) -> opaque_types::OpaqueTypeMap<'tcx> {
1343+
debug_assert_ne!(self.defining_use_anchor, DefiningAnchor::Error);
1344+
std::mem::take(&mut self.inner.borrow_mut().opaque_type_storage.opaque_types)
1345+
}
1346+
13411347
pub fn ty_to_string(&self, t: Ty<'tcx>) -> String {
13421348
self.resolve_vars_if_possible(t).to_string()
13431349
}

‎compiler/rustc_infer/src/infer/opaque_types/table.rs

-5
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ impl<'tcx> OpaqueTypeStorage<'tcx> {
2929
}
3030
}
3131

32-
#[instrument(level = "debug", ret)]
33-
pub fn take_opaque_types(&mut self) -> OpaqueTypeMap<'tcx> {
34-
std::mem::take(&mut self.opaque_types)
35-
}
36-
3732
#[inline]
3833
pub(crate) fn with_log<'a>(
3934
&'a mut self,

‎compiler/rustc_trait_selection/src/traits/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,6 @@ pub fn impossible_predicates<'tcx>(
450450
}
451451
let errors = ocx.select_all_or_error();
452452

453-
// Clean up after ourselves
454-
let _ = infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
455-
456453
let result = !errors.is_empty();
457454
debug!("impossible_predicates = {:?}", result);
458455
result

‎compiler/rustc_traits/src/codegen.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub fn codegen_select_candidate<'tcx>(
8282
// Opaque types may have gotten their hidden types constrained, but we can ignore them safely
8383
// as they will get constrained elsewhere, too.
8484
// (ouz-a) This is required for `type-alias-impl-trait/assoc-projection-ice.rs` to pass
85-
let _ = infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
85+
let _ = infcx.take_opaque_types();
8686

8787
Ok(&*tcx.arena.alloc(impl_source))
8888
}

0 commit comments

Comments
 (0)
Please sign in to comment.