Skip to content

Commit 2fc6f80

Browse files
committed
Review comments. Move resolve_vars_if_possible into fn and add test minimizations.
1 parent 8b17827 commit 2fc6f80

File tree

2 files changed

+36
-15
lines changed

2 files changed

+36
-15
lines changed

compiler/rustc_hir_typeck/src/opaque_types.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,9 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
2828
pub(super) fn try_handle_opaque_type_uses_next(&mut self) {
2929
// We clone the opaques instead of stealing them here as we still need
3030
// to use them after fallback.
31-
let mut opaque_types: Vec<_> = self.infcx.clone_opaque_types();
32-
for entry in &mut opaque_types {
33-
*entry = self.resolve_vars_if_possible(*entry);
34-
}
35-
debug!(?opaque_types);
31+
let opaque_types: Vec<_> = self.infcx.clone_opaque_types();
3632

37-
self.compute_definition_site_hidden_types(&opaque_types, false);
33+
self.compute_definition_site_hidden_types(opaque_types, false);
3834
}
3935

4036
/// This takes all the opaque type uses during HIR typeck. It first computes
@@ -49,16 +45,12 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
4945
pub(super) fn handle_opaque_type_uses_next(&mut self) {
5046
// We clone the opaques instead of stealing them here as they are still used for
5147
// normalization in the next generation trait solver.
52-
let mut opaque_types: Vec<_> = self.infcx.clone_opaque_types();
48+
let opaque_types: Vec<_> = self.infcx.clone_opaque_types();
5349
let num_entries = self.inner.borrow_mut().opaque_types().num_entries();
5450
let prev = self.checked_opaque_types_storage_entries.replace(Some(num_entries));
5551
debug_assert_eq!(prev, None);
56-
for entry in &mut opaque_types {
57-
*entry = self.resolve_vars_if_possible(*entry);
58-
}
59-
debug!(?opaque_types);
6052

61-
self.compute_definition_site_hidden_types(&opaque_types, true);
53+
self.compute_definition_site_hidden_types(opaque_types, true);
6254
}
6355
}
6456

@@ -96,9 +88,14 @@ impl<'tcx> UsageKind<'tcx> {
9688
impl<'tcx> FnCtxt<'_, 'tcx> {
9789
fn compute_definition_site_hidden_types(
9890
&mut self,
99-
opaque_types: &[(OpaqueTypeKey<'tcx>, OpaqueHiddenType<'tcx>)],
91+
mut opaque_types: Vec<(OpaqueTypeKey<'tcx>, OpaqueHiddenType<'tcx>)>,
10092
error_on_missing_defining_use: bool,
10193
) {
94+
for entry in opaque_types.iter_mut() {
95+
*entry = self.resolve_vars_if_possible(*entry);
96+
}
97+
debug!(?opaque_types);
98+
10299
let tcx = self.tcx;
103100
let TypingMode::Analysis { defining_opaque_types_and_generators } = self.typing_mode()
104101
else {
@@ -116,7 +113,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
116113
// store this), because we can go from `UnconstrainedHiddenType` to
117114
// `HasDefiningUse` (because of fallback)
118115
let mut usage_kind = UsageKind::None;
119-
for &(opaque_type_key, hidden_type) in opaque_types {
116+
for &(opaque_type_key, hidden_type) in &opaque_types {
120117
if opaque_type_key.def_id != def_id {
121118
continue;
122119
}
@@ -129,7 +126,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
129126
}
130127

131128
if let UsageKind::HasDefiningUse(ty) = usage_kind {
132-
for &(opaque_type_key, hidden_type) in opaque_types {
129+
for &(opaque_type_key, hidden_type) in &opaque_types {
133130
if opaque_type_key.def_id != def_id {
134131
continue;
135132
}

tests/ui/traits/next-solver/opaques/hidden-types-equate-before-fallback.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,28 @@ impl FileSystem {
2323
}
2424
}
2525

26+
struct FileSystem2;
27+
impl FileSystem2 {
28+
fn build<T, U>() -> impl Sized {
29+
if false {
30+
Self::build::<U, T>()
31+
} else {
32+
loop {}
33+
};
34+
1u32
35+
}
36+
}
37+
38+
struct FileSystem3;
39+
impl FileSystem3 {
40+
fn build<'a>() -> impl Sized + use<'a> {
41+
if false {
42+
Self::build()
43+
} else {
44+
loop {}
45+
};
46+
1u32
47+
}
48+
}
49+
2650
fn main() {}

0 commit comments

Comments
 (0)