Skip to content

Commit 056997e

Browse files
authored
Unrolled build for rust-lang#135440
Rollup merge of rust-lang#135440 - lcnr:yeeeeeeeeeeeeeeeeeeeeeeet, r=compiler-errors rm unnecessary `OpaqueTypeDecl` wrapper
2 parents 1ab85fb + 87f03a4 commit 056997e

File tree

7 files changed

+24
-32
lines changed

7 files changed

+24
-32
lines changed

compiler/rustc_borrowck/src/type_check/opaque_types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ pub(super) fn take_opaques_and_register_member_constraints<'tcx>(
2525
let opaque_types = infcx
2626
.take_opaque_types()
2727
.into_iter()
28-
.map(|(opaque_type_key, decl)| {
29-
let hidden_type = infcx.resolve_vars_if_possible(decl.hidden_type);
28+
.map(|(opaque_type_key, hidden_type)| {
29+
let hidden_type = infcx.resolve_vars_if_possible(hidden_type);
3030
register_member_constraints(
3131
typeck,
3232
&mut member_constraints,

compiler/rustc_hir_analysis/src/check/check.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,9 @@ fn check_opaque_meets_bounds<'tcx>(
436436
} else {
437437
// Check that any hidden types found during wf checking match the hidden types that `type_of` sees.
438438
for (mut key, mut ty) in infcx.take_opaque_types() {
439-
ty.hidden_type.ty = infcx.resolve_vars_if_possible(ty.hidden_type.ty);
439+
ty.ty = infcx.resolve_vars_if_possible(ty.ty);
440440
key = infcx.resolve_vars_if_possible(key);
441-
sanity_check_found_hidden_type(tcx, key, ty.hidden_type)?;
441+
sanity_check_found_hidden_type(tcx, key, ty)?;
442442
}
443443
Ok(())
444444
}
@@ -1873,7 +1873,7 @@ pub(super) fn check_coroutine_obligations(
18731873
// Check that any hidden types found when checking these stalled coroutine obligations
18741874
// are valid.
18751875
for (key, ty) in infcx.take_opaque_types() {
1876-
let hidden_type = infcx.resolve_vars_if_possible(ty.hidden_type);
1876+
let hidden_type = infcx.resolve_vars_if_possible(ty);
18771877
let key = infcx.resolve_vars_if_possible(key);
18781878
sanity_check_found_hidden_type(tcx, key, hidden_type)?;
18791879
}

compiler/rustc_hir_typeck/src/writeback.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -562,9 +562,9 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
562562
// types or by using this function at the end of writeback and running it as a
563563
// fixpoint.
564564
let opaque_types = self.fcx.infcx.clone_opaque_types();
565-
for (opaque_type_key, decl) in opaque_types {
566-
let hidden_type = self.resolve(decl.hidden_type, &decl.hidden_type.span);
567-
let opaque_type_key = self.resolve(opaque_type_key, &decl.hidden_type.span);
565+
for (opaque_type_key, hidden_type) in opaque_types {
566+
let hidden_type = self.resolve(hidden_type, &hidden_type.span);
567+
let opaque_type_key = self.resolve(opaque_type_key, &hidden_type.span);
568568

569569
if !self.fcx.next_trait_solver() {
570570
if let ty::Alias(ty::Opaque, alias_ty) = hidden_type.ty.kind()

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,12 @@ impl<'tcx> InferCtxt<'tcx> {
155155
.opaque_type_storage
156156
.opaque_types
157157
.iter()
158-
.map(|(k, v)| (*k, v.hidden_type.ty))
158+
.map(|(k, v)| (*k, v.ty))
159159
.collect()
160160
}
161161

162162
fn take_opaque_types_for_query_response(&self) -> Vec<(ty::OpaqueTypeKey<'tcx>, Ty<'tcx>)> {
163-
self.take_opaque_types().into_iter().map(|(k, v)| (k, v.hidden_type.ty)).collect()
163+
self.take_opaque_types().into_iter().map(|(k, v)| (k, v.ty)).collect()
164164
}
165165

166166
/// Given the (canonicalized) result to a canonical query,

compiler/rustc_infer/src/infer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl<'tcx> InferCtxtInner<'tcx> {
234234
pub fn iter_opaque_types(
235235
&self,
236236
) -> impl Iterator<Item = (ty::OpaqueTypeKey<'tcx>, ty::OpaqueHiddenType<'tcx>)> + '_ {
237-
self.opaque_type_storage.opaque_types.iter().map(|(&k, v)| (k, v.hidden_type))
237+
self.opaque_type_storage.opaque_types.iter().map(|(&k, &v)| (k, v))
238238
}
239239
}
240240

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

+1-12
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,9 @@ use crate::traits::{self, Obligation, PredicateObligations};
1919

2020
mod table;
2121

22-
pub(crate) type OpaqueTypeMap<'tcx> = FxIndexMap<OpaqueTypeKey<'tcx>, OpaqueTypeDecl<'tcx>>;
22+
pub(crate) type OpaqueTypeMap<'tcx> = FxIndexMap<OpaqueTypeKey<'tcx>, OpaqueHiddenType<'tcx>>;
2323
pub(crate) use table::{OpaqueTypeStorage, OpaqueTypeTable};
2424

25-
/// Information about the opaque types whose values we
26-
/// are inferring in this function (these are the `impl Trait` that
27-
/// appear in the return type).
28-
#[derive(Clone, Debug)]
29-
pub struct OpaqueTypeDecl<'tcx> {
30-
/// The hidden types that have been inferred for this opaque type.
31-
/// There can be multiple, but they are all `lub`ed together at the end
32-
/// to obtain the canonical hidden type.
33-
pub hidden_type: OpaqueHiddenType<'tcx>,
34-
}
35-
3625
impl<'tcx> InferCtxt<'tcx> {
3726
/// This is a backwards compatibility hack to prevent breaking changes from
3827
/// lazy TAIT around RPIT handling.

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

+12-9
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,27 @@ use rustc_middle::bug;
33
use rustc_middle::ty::{self, OpaqueHiddenType, OpaqueTypeKey, Ty};
44
use tracing::instrument;
55

6-
use super::{OpaqueTypeDecl, OpaqueTypeMap};
6+
use super::OpaqueTypeMap;
77
use crate::infer::snapshot::undo_log::{InferCtxtUndoLogs, UndoLog};
88

99
#[derive(Default, Debug, Clone)]
1010
pub(crate) struct OpaqueTypeStorage<'tcx> {
1111
/// Opaque types found in explicit return types and their
1212
/// associated fresh inference variable. Writeback resolves these
1313
/// variables to get the concrete type, which can be used to
14-
/// 'de-opaque' OpaqueTypeDecl, after typeck is done with all functions.
14+
/// 'de-opaque' OpaqueHiddenType, after typeck is done with all functions.
1515
pub opaque_types: OpaqueTypeMap<'tcx>,
1616
}
1717

1818
impl<'tcx> OpaqueTypeStorage<'tcx> {
1919
#[instrument(level = "debug")]
20-
pub(crate) fn remove(&mut self, key: OpaqueTypeKey<'tcx>, idx: Option<OpaqueHiddenType<'tcx>>) {
21-
if let Some(idx) = idx {
22-
self.opaque_types.get_mut(&key).unwrap().hidden_type = idx;
20+
pub(crate) fn remove(
21+
&mut self,
22+
key: OpaqueTypeKey<'tcx>,
23+
prev: Option<OpaqueHiddenType<'tcx>>,
24+
) {
25+
if let Some(prev) = prev {
26+
*self.opaque_types.get_mut(&key).unwrap() = prev;
2327
} else {
2428
// FIXME(#120456) - is `swap_remove` correct?
2529
match self.opaque_types.swap_remove(&key) {
@@ -59,13 +63,12 @@ impl<'a, 'tcx> OpaqueTypeTable<'a, 'tcx> {
5963
key: OpaqueTypeKey<'tcx>,
6064
hidden_type: OpaqueHiddenType<'tcx>,
6165
) -> Option<Ty<'tcx>> {
62-
if let Some(decl) = self.storage.opaque_types.get_mut(&key) {
63-
let prev = std::mem::replace(&mut decl.hidden_type, hidden_type);
66+
if let Some(entry) = self.storage.opaque_types.get_mut(&key) {
67+
let prev = std::mem::replace(entry, hidden_type);
6468
self.undo_log.push(UndoLog::OpaqueTypes(key, Some(prev)));
6569
return Some(prev.ty);
6670
}
67-
let decl = OpaqueTypeDecl { hidden_type };
68-
self.storage.opaque_types.insert(key, decl);
71+
self.storage.opaque_types.insert(key, hidden_type);
6972
self.undo_log.push(UndoLog::OpaqueTypes(key, None));
7073
None
7174
}

0 commit comments

Comments
 (0)