@@ -34,8 +34,7 @@ use rustc_middle::util::Providers;
3434use rustc_middle:: { bug, query, span_bug} ;
3535use rustc_span:: source_map:: Spanned ;
3636use rustc_span:: { DUMMY_SP , sym} ;
37- use rustc_trait_selection:: traits;
38- use tracing:: { debug, trace} ;
37+ use tracing:: debug;
3938
4039#[ macro_use]
4140mod pass_manager;
@@ -142,6 +141,7 @@ declare_passes! {
142141 // Made public so that `mir_drops_elaborated_and_const_checked` can be overridden
143142 // by custom rustc drivers, running all the steps by themselves. See #114628.
144143 pub mod inline : Inline , ForceInline ;
144+ mod impossible_predicates : ImpossiblePredicates ;
145145 mod instsimplify : InstSimplify { BeforeInline , AfterSimplifyCfg } ;
146146 mod jump_threading : JumpThreading ;
147147 mod known_panics_lint : KnownPanicsLint ;
@@ -502,50 +502,6 @@ fn mir_drops_elaborated_and_const_checked(tcx: TyCtxt<'_>, def: LocalDefId) -> &
502502 body. tainted_by_errors = Some ( error_reported) ;
503503 }
504504
505- // Check if it's even possible to satisfy the 'where' clauses
506- // for this item.
507- //
508- // This branch will never be taken for any normal function.
509- // However, it's possible to `#!feature(trivial_bounds)]` to write
510- // a function with impossible to satisfy clauses, e.g.:
511- // `fn foo() where String: Copy {}`
512- //
513- // We don't usually need to worry about this kind of case,
514- // since we would get a compilation error if the user tried
515- // to call it. However, since we optimize even without any
516- // calls to the function, we need to make sure that it even
517- // makes sense to try to evaluate the body.
518- //
519- // If there are unsatisfiable where clauses, then all bets are
520- // off, and we just give up.
521- //
522- // We manually filter the predicates, skipping anything that's not
523- // "global". We are in a potentially generic context
524- // (e.g. we are evaluating a function without instantiating generic
525- // parameters, so this filtering serves two purposes:
526- //
527- // 1. We skip evaluating any predicates that we would
528- // never be able prove are unsatisfiable (e.g. `<T as Foo>`
529- // 2. We avoid trying to normalize predicates involving generic
530- // parameters (e.g. `<T as Foo>::MyItem`). This can confuse
531- // the normalization code (leading to cycle errors), since
532- // it's usually never invoked in this way.
533- let predicates = tcx
534- . predicates_of ( body. source . def_id ( ) )
535- . predicates
536- . iter ( )
537- . filter_map ( |( p, _) | if p. is_global ( ) { Some ( * p) } else { None } ) ;
538- if traits:: impossible_predicates ( tcx, traits:: elaborate ( tcx, predicates) . collect ( ) ) {
539- trace ! ( "found unsatisfiable predicates for {:?}" , body. source) ;
540- // Clear the body to only contain a single `unreachable` statement.
541- let bbs = body. basic_blocks . as_mut ( ) ;
542- bbs. raw . truncate ( 1 ) ;
543- bbs[ START_BLOCK ] . statements . clear ( ) ;
544- bbs[ START_BLOCK ] . terminator_mut ( ) . kind = TerminatorKind :: Unreachable ;
545- body. var_debug_info . clear ( ) ;
546- body. local_decls . raw . truncate ( body. arg_count + 1 ) ;
547- }
548-
549505 run_analysis_to_runtime_passes ( tcx, & mut body) ;
550506
551507 // Now that drop elaboration has been performed, we can check for
@@ -593,6 +549,7 @@ pub fn run_analysis_to_runtime_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'
593549/// After this series of passes, no lifetime analysis based on borrowing can be done.
594550fn run_analysis_cleanup_passes < ' tcx > ( tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
595551 let passes: & [ & dyn MirPass < ' tcx > ] = & [
552+ & impossible_predicates:: ImpossiblePredicates ,
596553 & cleanup_post_borrowck:: CleanupPostBorrowck ,
597554 & remove_noop_landing_pads:: RemoveNoopLandingPads ,
598555 & simplify:: SimplifyCfg :: PostAnalysis ,
0 commit comments