@@ -26,15 +26,15 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
2626 /// Unlike `handle_opaque_type_uses_next`, this does not report errors.
2727 #[ instrument( level = "debug" , skip( self ) ) ]
2828 pub ( super ) fn try_handle_opaque_type_uses_next ( & mut self ) {
29- // We clone the opaques instead of stealing them here as they are still used for
30- // normalization in the next generation trait solver .
29+ // We clone the opaques instead of stealing them here as we still need
30+ // to use them after fallback .
3131 let mut opaque_types: Vec < _ > = self . infcx . clone_opaque_types ( ) ;
3232 for entry in & mut opaque_types {
3333 * entry = self . resolve_vars_if_possible ( * entry) ;
3434 }
3535 debug ! ( ?opaque_types) ;
3636
37- self . compute_definition_site_hidden_types ( & opaque_types, true ) ;
37+ self . compute_definition_site_hidden_types ( & opaque_types, false ) ;
3838 }
3939
4040 /// This takes all the opaque type uses during HIR typeck. It first computes
@@ -58,7 +58,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
5858 }
5959 debug ! ( ?opaque_types) ;
6060
61- self . compute_definition_site_hidden_types ( & opaque_types, false ) ;
61+ self . compute_definition_site_hidden_types ( & opaque_types, true ) ;
6262 }
6363}
6464
@@ -97,7 +97,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
9797 fn compute_definition_site_hidden_types (
9898 & mut self ,
9999 opaque_types : & [ ( OpaqueTypeKey < ' tcx > , OpaqueHiddenType < ' tcx > ) ] ,
100- first_pass : bool ,
100+ error_on_missing_defining_use : bool ,
101101 ) {
102102 let tcx = self . tcx ;
103103 let TypingMode :: Analysis { defining_opaque_types_and_generators } = self . typing_mode ( )
@@ -138,19 +138,16 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
138138 self . demand_eqtype ( hidden_type. span , expected, hidden_type. ty ) ;
139139 }
140140
141- let prev = self . typeck_results . borrow_mut ( ) . hidden_types . insert ( def_id, ty) ;
142-
143- // We do want to insert opaque types the first pass, because
144- // we want to equate them. So, the second pass (where we
145- // report errors) may have a hidden type inserted.
146- if first_pass {
147- assert ! ( prev. is_none( ) ) ;
148- }
141+ // Being explicit here: it may be possible that we in a
142+ // previous call to this function we did an insert, but this
143+ // should be just fine, since they all get equated anyways and
144+ // we shouldn't ever go from `HasDefiningUse` to anyway else.
145+ let _ = self . typeck_results . borrow_mut ( ) . hidden_types . insert ( def_id, ty) ;
149146 }
150147
151148 // If this the first pass (`try_handle_opaque_type_uses_next`),
152149 // then do not report any errors.
153- if first_pass {
150+ if !error_on_missing_defining_use {
154151 continue ;
155152 }
156153
@@ -204,7 +201,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
204201
205202 #[ tracing:: instrument( skip( self ) , ret) ]
206203 fn consider_opaque_type_use (
207- & mut self ,
204+ & self ,
208205 opaque_type_key : OpaqueTypeKey < ' tcx > ,
209206 hidden_type : OpaqueHiddenType < ' tcx > ,
210207 ) -> UsageKind < ' tcx > {
0 commit comments