Skip to content

Commit 1e81ca3

Browse files
authoredJan 9, 2023
Rollup merge of rust-lang#106204 - compiler-errors:no-take-opaques-in-compare, r=oli-obk
No need to take opaques in `check_type_bounds` `InferCtxt` already has its defining use anchor set to err r? `@oli-obk`
2 parents 91d750d + f769d34 commit 1e81ca3

File tree

11 files changed

+14
-36
lines changed

11 files changed

+14
-36
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
@@ -209,7 +209,7 @@ pub(crate) fn type_check<'mir, 'tcx>(
209209
);
210210

211211
translate_outlives_facts(&mut checker);
212-
let opaque_type_values = infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
212+
let opaque_type_values = infcx.take_opaque_types();
213213

214214
let opaque_type_values = opaque_type_values
215215
.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_analysis/src/check/compare_impl_item.rs

+1-17
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ fn compare_asyncness<'tcx>(
424424
ty::Alias(ty::Opaque, ..) => {
425425
// allow both `async fn foo()` and `fn foo() -> impl Future`
426426
}
427-
ty::Error(rustc_errors::ErrorGuaranteed { .. }) => {
427+
ty::Error(_) => {
428428
// We don't know if it's ok, but at least it's already an error.
429429
}
430430
_ => {
@@ -1972,22 +1972,6 @@ pub(super) fn check_type_bounds<'tcx>(
19721972
&outlives_environment,
19731973
)?;
19741974

1975-
let constraints = infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
1976-
for (key, value) in constraints {
1977-
infcx
1978-
.err_ctxt()
1979-
.report_mismatched_types(
1980-
&ObligationCause::misc(
1981-
value.hidden_type.span,
1982-
tcx.hir().local_def_id_to_hir_id(impl_ty.def_id.expect_local()),
1983-
),
1984-
tcx.mk_opaque(key.def_id.to_def_id(), key.substs),
1985-
value.hidden_type.ty,
1986-
TypeError::Mismatch,
1987-
)
1988-
.emit();
1989-
}
1990-
19911975
Ok(())
19921976
}
19931977

‎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)