@@ -40,6 +40,7 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
40
40
let items = stable_mir:: all_local_items ( ) ;
41
41
check_foo ( * get_item ( & items, ( ItemKind :: Static , "FOO" ) ) . unwrap ( ) ) ;
42
42
check_bar ( * get_item ( & items, ( ItemKind :: Static , "BAR" ) ) . unwrap ( ) ) ;
43
+ check_len ( * get_item ( & items, ( ItemKind :: Static , "LEN" ) ) . unwrap ( ) ) ;
43
44
ControlFlow :: Continue ( ( ) )
44
45
}
45
46
@@ -76,6 +77,19 @@ fn check_bar(item: CrateItem) {
76
77
assert_eq ! ( allocation. bytes[ 0 ] . unwrap( ) , Char :: CapitalB . to_u8( ) ) ;
77
78
assert_eq ! ( allocation. bytes[ 1 ] . unwrap( ) , Char :: SmallA . to_u8( ) ) ;
78
79
assert_eq ! ( allocation. bytes[ 2 ] . unwrap( ) , Char :: SmallR . to_u8( ) ) ;
80
+ assert_eq ! ( std:: str :: from_utf8( & allocation. raw_bytes( ) . unwrap( ) ) , Ok ( "Bar" ) ) ;
81
+ }
82
+
83
+ /// Check the allocation data for `LEN`.
84
+ ///
85
+ /// ```no_run
86
+ /// static LEN: usize = 2;
87
+ /// ```
88
+ fn check_len ( item : CrateItem ) {
89
+ let def = StaticDef :: try_from ( item) . unwrap ( ) ;
90
+ let alloc = def. eval_initializer ( ) . unwrap ( ) ;
91
+ assert ! ( alloc. provenance. ptrs. is_empty( ) ) ;
92
+ assert_eq ! ( alloc. read_uint( ) , Ok ( 2 ) ) ;
79
93
}
80
94
81
95
// Use internal API to find a function in a crate.
@@ -109,11 +123,13 @@ fn generate_input(path: &str) -> std::io::Result<()> {
109
123
write ! (
110
124
file,
111
125
r#"
126
+ static LEN: usize = 2;
112
127
static FOO: [&str; 2] = ["hi", "there"];
113
128
static BAR: &str = "Bar";
114
129
115
130
pub fn main() {{
116
131
println!("{{FOO:?}}! {{BAR}}");
132
+ assert_eq!(FOO.len(), LEN);
117
133
}}"#
118
134
) ?;
119
135
Ok ( ( ) )
0 commit comments