@@ -40,6 +40,7 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
4040 let items = stable_mir:: all_local_items ( ) ;
4141 check_foo ( * get_item ( & items, ( ItemKind :: Static , "FOO" ) ) . unwrap ( ) ) ;
4242 check_bar ( * get_item ( & items, ( ItemKind :: Static , "BAR" ) ) . unwrap ( ) ) ;
43+ check_len ( * get_item ( & items, ( ItemKind :: Static , "LEN" ) ) . unwrap ( ) ) ;
4344 ControlFlow :: Continue ( ( ) )
4445}
4546
@@ -76,6 +77,19 @@ fn check_bar(item: CrateItem) {
7677 assert_eq ! ( allocation. bytes[ 0 ] . unwrap( ) , Char :: CapitalB . to_u8( ) ) ;
7778 assert_eq ! ( allocation. bytes[ 1 ] . unwrap( ) , Char :: SmallA . to_u8( ) ) ;
7879 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 ) ) ;
7993}
8094
8195// Use internal API to find a function in a crate.
@@ -109,11 +123,13 @@ fn generate_input(path: &str) -> std::io::Result<()> {
109123 write ! (
110124 file,
111125 r#"
126+ static LEN: usize = 2;
112127 static FOO: [&str; 2] = ["hi", "there"];
113128 static BAR: &str = "Bar";
114129
115130 pub fn main() {{
116131 println!("{{FOO:?}}! {{BAR}}");
132+ assert_eq!(FOO.len(), LEN);
117133 }}"#
118134 ) ?;
119135 Ok ( ( ) )
0 commit comments