11// run-pass
2- // Test that users are able to use stable mir APIs to retrieve monomorphized instances
2+ //! Test that users are able to use stable mir APIs to retrieve monomorphized instances
33
44// ignore-stage1
55// ignore-cross-compile
1414extern crate rustc_middle;
1515#[ macro_use]
1616extern crate rustc_smir;
17- extern crate stable_mir;
1817extern crate rustc_driver;
1918extern crate rustc_interface;
19+ extern crate stable_mir;
2020
21- use rustc_middle:: ty:: TyCtxt ;
2221use mir:: { mono:: Instance , TerminatorKind :: * } ;
23- use stable_mir:: ty:: { TyKind , RigidTy } ;
24- use stable_mir:: * ;
22+ use rustc_middle:: ty:: TyCtxt ;
2523use rustc_smir:: rustc_internal;
24+ use stable_mir:: ty:: { RigidTy , TyKind } ;
25+ use stable_mir:: * ;
2626use std:: io:: Write ;
2727use std:: ops:: ControlFlow ;
2828
@@ -33,16 +33,16 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
3333 let items = stable_mir:: all_local_items ( ) ;
3434
3535 // Get all items and split generic vs monomorphic items.
36- let ( generic, mono) : ( Vec < _ > , Vec < _ > ) = items. into_iter ( ) . partition ( |item| {
37- item. requires_monomorphization ( )
38- } ) ;
36+ let ( generic, mono) : ( Vec < _ > , Vec < _ > ) =
37+ items. into_iter ( ) . partition ( |item| item. requires_monomorphization ( ) ) ;
3938 assert_eq ! ( mono. len( ) , 3 , "Expected 2 mono functions and one constant" ) ;
4039 assert_eq ! ( generic. len( ) , 2 , "Expected 2 generic functions" ) ;
4140
4241 // For all monomorphic items, get the correspondent instances.
43- let instances = mono. iter ( ) . filter_map ( |item| {
44- mir:: mono:: Instance :: try_from ( * item) . ok ( )
45- } ) . collect :: < Vec < mir:: mono:: Instance > > ( ) ;
42+ let instances = mono
43+ . iter ( )
44+ . filter_map ( |item| mir:: mono:: Instance :: try_from ( * item) . ok ( ) )
45+ . collect :: < Vec < mir:: mono:: Instance > > ( ) ;
4646 assert_eq ! ( instances. len( ) , mono. len( ) ) ;
4747
4848 // For all generic items, try_from should fail.
@@ -58,19 +58,22 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
5858fn test_body ( body : mir:: Body ) {
5959 for term in body. blocks . iter ( ) . map ( |bb| & bb. terminator ) {
6060 match & term. kind {
61- Call { func, .. } => {
61+ Call { func, .. } => {
6262 let TyKind :: RigidTy ( ty) = func. ty ( & body. locals ) . kind ( ) else { unreachable ! ( ) } ;
6363 let RigidTy :: FnDef ( def, args) = ty else { unreachable ! ( ) } ;
6464 let result = Instance :: resolve ( def, & args) ;
6565 assert ! ( result. is_ok( ) ) ;
6666 }
67- Goto { ..} | Assert { ..} | SwitchInt { ..} | Return | Drop { ..} => { /* Do nothing */ }
68- _ => { unreachable ! ( "Unexpected terminator {term:?}" ) }
67+ Goto { .. } | Assert { .. } | SwitchInt { .. } | Return | Drop { .. } => {
68+ /* Do nothing */
69+ }
70+ _ => {
71+ unreachable ! ( "Unexpected terminator {term:?}" )
72+ }
6973 }
7074 }
7175}
7276
73-
7477/// This test will generate and analyze a dummy crate using the stable mir.
7578/// For that, it will first write the dummy crate into a file.
7679/// Then it will create a `StableMir` using custom arguments and then
0 commit comments