33//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/resolution.html#selection
44
55use std:: cell:: { Cell , RefCell } ;
6+ use std:: cmp;
67use std:: fmt:: { self , Display } ;
78use std:: ops:: ControlFlow ;
8- use std:: { assert_matches, cmp} ;
99
1010use hir:: def:: DefKind ;
1111use rustc_data_structures:: fx:: { FxIndexMap , FxIndexSet } ;
@@ -210,7 +210,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
210210 /// Enables tracking of intercrate ambiguity causes. See
211211 /// the documentation of [`Self::intercrate_ambiguity_causes`] for more.
212212 pub fn enable_tracking_intercrate_ambiguity_causes ( & mut self ) {
213- assert_matches ! ( self . infcx. typing_mode( ) , TypingMode :: Coherence ) ;
213+ match self . infcx . typing_mode ( ) {
214+ TypingMode :: Coherence => { }
215+ TypingMode :: Analysis { .. }
216+ | TypingMode :: Borrowck { .. }
217+ | TypingMode :: PostBorrowckAnalysis { .. }
218+ | TypingMode :: PostAnalysis => bug ! ( ) ,
219+ }
220+
214221 assert ! ( self . intercrate_ambiguity_causes. is_none( ) ) ;
215222 self . intercrate_ambiguity_causes = Some ( FxIndexSet :: default ( ) ) ;
216223 debug ! ( "selcx: enable_tracking_intercrate_ambiguity_causes" ) ;
@@ -222,7 +229,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
222229 pub fn take_intercrate_ambiguity_causes (
223230 & mut self ,
224231 ) -> FxIndexSet < IntercrateAmbiguityCause < ' tcx > > {
225- assert_matches ! ( self . infcx. typing_mode( ) , TypingMode :: Coherence ) ;
232+ match self . infcx . typing_mode ( ) {
233+ TypingMode :: Coherence => { }
234+ TypingMode :: Analysis { .. }
235+ | TypingMode :: Borrowck { .. }
236+ | TypingMode :: PostBorrowckAnalysis { .. }
237+ | TypingMode :: PostAnalysis => bug ! ( ) ,
238+ }
239+
226240 self . intercrate_ambiguity_causes . take ( ) . unwrap_or_default ( )
227241 }
228242
@@ -1016,8 +1030,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
10161030 previous_stack : TraitObligationStackList < ' o , ' tcx > ,
10171031 mut obligation : PolyTraitObligation < ' tcx > ,
10181032 ) -> Result < EvaluationResult , OverflowError > {
1019- if !matches ! ( self . infcx. typing_mode( ) , TypingMode :: Coherence )
1020- && obligation. is_global ( )
1033+ if match self . infcx . typing_mode ( ) {
1034+ TypingMode :: Coherence => false ,
1035+ TypingMode :: Analysis { .. }
1036+ | TypingMode :: Borrowck { .. }
1037+ | TypingMode :: PostBorrowckAnalysis { .. }
1038+ | TypingMode :: PostAnalysis => true ,
1039+ } && obligation. is_global ( )
10211040 && obligation. param_env . caller_bounds ( ) . iter ( ) . all ( |bound| bound. has_param ( ) )
10221041 {
10231042 // If a param env has no global bounds, global obligations do not
@@ -2548,7 +2567,13 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
25482567 nested_obligations. extend ( obligations) ;
25492568
25502569 if impl_trait_header. polarity == ty:: ImplPolarity :: Reservation
2551- && !matches ! ( self . infcx. typing_mode( ) , TypingMode :: Coherence )
2570+ && match self . infcx . typing_mode ( ) {
2571+ TypingMode :: Coherence => false ,
2572+ TypingMode :: Analysis { .. }
2573+ | TypingMode :: Borrowck { .. }
2574+ | TypingMode :: PostBorrowckAnalysis { .. }
2575+ | TypingMode :: PostAnalysis => true ,
2576+ }
25522577 {
25532578 debug ! ( "reservation impls only apply in intercrate mode" ) ;
25542579 return Err ( ( ) ) ;
0 commit comments