1
1
// 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
3
3
4
4
// ignore-stage1
5
5
// ignore-cross-compile
14
14
extern crate rustc_middle;
15
15
#[ macro_use]
16
16
extern crate rustc_smir;
17
- extern crate stable_mir;
18
17
extern crate rustc_driver;
19
18
extern crate rustc_interface;
19
+ extern crate stable_mir;
20
20
21
- use rustc_middle:: ty:: TyCtxt ;
22
21
use mir:: { mono:: Instance , TerminatorKind :: * } ;
23
- use stable_mir:: ty:: { TyKind , RigidTy } ;
24
- use stable_mir:: * ;
22
+ use rustc_middle:: ty:: TyCtxt ;
25
23
use rustc_smir:: rustc_internal;
24
+ use stable_mir:: ty:: { RigidTy , TyKind } ;
25
+ use stable_mir:: * ;
26
26
use std:: io:: Write ;
27
27
use std:: ops:: ControlFlow ;
28
28
@@ -33,16 +33,16 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
33
33
let items = stable_mir:: all_local_items ( ) ;
34
34
35
35
// 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 ( ) ) ;
39
38
assert_eq ! ( mono. len( ) , 3 , "Expected 2 mono functions and one constant" ) ;
40
39
assert_eq ! ( generic. len( ) , 2 , "Expected 2 generic functions" ) ;
41
40
42
41
// 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 > > ( ) ;
46
46
assert_eq ! ( instances. len( ) , mono. len( ) ) ;
47
47
48
48
// For all generic items, try_from should fail.
@@ -58,19 +58,22 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
58
58
fn test_body ( body : mir:: Body ) {
59
59
for term in body. blocks . iter ( ) . map ( |bb| & bb. terminator ) {
60
60
match & term. kind {
61
- Call { func, .. } => {
61
+ Call { func, .. } => {
62
62
let TyKind :: RigidTy ( ty) = func. ty ( & body. locals ) . kind ( ) else { unreachable ! ( ) } ;
63
63
let RigidTy :: FnDef ( def, args) = ty else { unreachable ! ( ) } ;
64
64
let result = Instance :: resolve ( def, & args) ;
65
65
assert ! ( result. is_ok( ) ) ;
66
66
}
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
+ }
69
73
}
70
74
}
71
75
}
72
76
73
-
74
77
/// This test will generate and analyze a dummy crate using the stable mir.
75
78
/// For that, it will first write the dummy crate into a file.
76
79
/// Then it will create a `StableMir` using custom arguments and then
0 commit comments