@@ -9,8 +9,22 @@ use crate::{test_db::TestDB, Interner, Substitution};
9
9
10
10
use super :: layout_of_ty;
11
11
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) ;
14
28
let module_id = db. module_for_file ( file_id) ;
15
29
let def_map = module_id. def_map ( & db) ;
16
30
let scope = & def_map[ module_id. local_id ] . scope ;
@@ -20,15 +34,11 @@ fn eval_goal(ra_fixture: &str) -> Result<Layout, LayoutError> {
20
34
. find_map ( |x| match x {
21
35
hir_def:: ModuleDefId :: AdtId ( x) => {
22
36
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 ( ) ,
26
40
} ;
27
- if name == "Goal" {
28
- Some ( x)
29
- } else {
30
- None
31
- }
41
+ ( name == "Goal" ) . then ( || x)
32
42
}
33
43
_ => None ,
34
44
} )
@@ -38,15 +48,15 @@ fn eval_goal(ra_fixture: &str) -> Result<Layout, LayoutError> {
38
48
}
39
49
40
50
#[ 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 ( ) ;
43
53
assert_eq ! ( l. size. bytes( ) , size) ;
44
54
assert_eq ! ( l. align. abi. bytes( ) , align) ;
45
55
}
46
56
47
57
#[ track_caller]
48
58
fn check_fail ( ra_fixture : & str , e : LayoutError ) {
49
- let r = eval_goal ( ra_fixture) ;
59
+ let r = eval_goal ( ra_fixture, "" ) ;
50
60
assert_eq ! ( r, Err ( e) ) ;
51
61
}
52
62
@@ -56,7 +66,8 @@ macro_rules! size_and_align {
56
66
#[ allow( dead_code) ]
57
67
$( $t) *
58
68
check_size_and_align(
59
- & format!( "//- minicore: {}\n {}" , stringify!( $( $x) ,* ) , stringify!( $( $t) * ) ) ,
69
+ stringify!( $( $t) * ) ,
70
+ & format!( "//- minicore: {}\n " , stringify!( $( $x) ,* ) ) ,
60
71
:: std:: mem:: size_of:: <Goal >( ) as u64 ,
61
72
:: std:: mem:: align_of:: <Goal >( ) as u64 ,
62
73
) ;
@@ -68,6 +79,7 @@ macro_rules! size_and_align {
68
79
$( $t) *
69
80
check_size_and_align(
70
81
stringify!( $( $t) * ) ,
82
+ "" ,
71
83
:: std:: mem:: size_of:: <Goal >( ) as u64 ,
72
84
:: std:: mem:: align_of:: <Goal >( ) as u64 ,
73
85
) ;
0 commit comments