@@ -9,8 +9,22 @@ use crate::{test_db::TestDB, Interner, Substitution};
99
1010use super :: layout_of_ty;
1111
12- fn eval_goal ( ra_fixture : & str ) -> Result < Layout , LayoutError > {
13- let ( db, file_id) = TestDB :: with_single_file ( ra_fixture) ;
12+ fn eval_goal ( ra_fixture : & str , minicore : & str ) -> Result < Layout , LayoutError > {
13+ // using unstable cargo features failed, fall back to using plain rustc
14+ let mut cmd = std:: process:: Command :: new ( "rustc" ) ;
15+ cmd. args ( & [ "-Z" , "unstable-options" , "--print" , "target-spec-json" ] )
16+ . env ( "RUSTC_BOOTSTRAP" , "1" ) ;
17+ let output = cmd. output ( ) . unwrap ( ) ;
18+ assert ! ( output. status. success( ) , "{}" , output. status) ;
19+ let stdout = String :: from_utf8 ( output. stdout ) . unwrap ( ) ;
20+ let target_data_layout =
21+ stdout. split_once ( r#""data-layout": ""# ) . unwrap ( ) . 1 . split_once ( '"' ) . unwrap ( ) . 0 . to_owned ( ) ;
22+
23+ let ra_fixture = format ! (
24+ "{minicore}//- /main.rs crate:test target_data_layout:{target_data_layout}\n {ra_fixture}" ,
25+ ) ;
26+
27+ let ( db, file_id) = TestDB :: with_single_file ( & ra_fixture) ;
1428 let module_id = db. module_for_file ( file_id) ;
1529 let def_map = module_id. def_map ( & db) ;
1630 let scope = & def_map[ module_id. local_id ] . scope ;
@@ -20,15 +34,11 @@ fn eval_goal(ra_fixture: &str) -> Result<Layout, LayoutError> {
2034 . find_map ( |x| match x {
2135 hir_def:: ModuleDefId :: AdtId ( x) => {
2236 let name = match x {
23- hir_def:: AdtId :: StructId ( x) => db. struct_data ( x) . name . to_string ( ) ,
24- hir_def:: AdtId :: UnionId ( x) => db. union_data ( x) . name . to_string ( ) ,
25- hir_def:: AdtId :: EnumId ( x) => db. enum_data ( x) . name . to_string ( ) ,
37+ hir_def:: AdtId :: StructId ( x) => db. struct_data ( x) . name . to_smol_str ( ) ,
38+ hir_def:: AdtId :: UnionId ( x) => db. union_data ( x) . name . to_smol_str ( ) ,
39+ hir_def:: AdtId :: EnumId ( x) => db. enum_data ( x) . name . to_smol_str ( ) ,
2640 } ;
27- if name == "Goal" {
28- Some ( x)
29- } else {
30- None
31- }
41+ ( name == "Goal" ) . then ( || x)
3242 }
3343 _ => None ,
3444 } )
@@ -38,15 +48,15 @@ fn eval_goal(ra_fixture: &str) -> Result<Layout, LayoutError> {
3848}
3949
4050#[ track_caller]
41- fn check_size_and_align ( ra_fixture : & str , size : u64 , align : u64 ) {
42- let l = eval_goal ( ra_fixture) . unwrap ( ) ;
51+ fn check_size_and_align ( ra_fixture : & str , minicore : & str , size : u64 , align : u64 ) {
52+ let l = eval_goal ( ra_fixture, minicore ) . unwrap ( ) ;
4353 assert_eq ! ( l. size. bytes( ) , size) ;
4454 assert_eq ! ( l. align. abi. bytes( ) , align) ;
4555}
4656
4757#[ track_caller]
4858fn check_fail ( ra_fixture : & str , e : LayoutError ) {
49- let r = eval_goal ( ra_fixture) ;
59+ let r = eval_goal ( ra_fixture, "" ) ;
5060 assert_eq ! ( r, Err ( e) ) ;
5161}
5262
@@ -56,7 +66,8 @@ macro_rules! size_and_align {
5666 #[ allow( dead_code) ]
5767 $( $t) *
5868 check_size_and_align(
59- & format!( "//- minicore: {}\n {}" , stringify!( $( $x) ,* ) , stringify!( $( $t) * ) ) ,
69+ stringify!( $( $t) * ) ,
70+ & format!( "//- minicore: {}\n " , stringify!( $( $x) ,* ) ) ,
6071 :: std:: mem:: size_of:: <Goal >( ) as u64 ,
6172 :: std:: mem:: align_of:: <Goal >( ) as u64 ,
6273 ) ;
@@ -68,6 +79,7 @@ macro_rules! size_and_align {
6879 $( $t) *
6980 check_size_and_align(
7081 stringify!( $( $t) * ) ,
82+ "" ,
7183 :: std:: mem:: size_of:: <Goal >( ) as u64 ,
7284 :: std:: mem:: align_of:: <Goal >( ) as u64 ,
7385 ) ;
0 commit comments