@@ -44,27 +44,38 @@ thread_local! {
44
44
}
45
45
46
46
pub fn maybe_inject_crates_ref ( mut krate : ast:: Crate , alt_std_name : Option < & str > ) -> ast:: Crate {
47
- let name = if attr:: contains_name ( & krate. attrs , "no_core" ) {
47
+ // the first name in this list is the crate name of the crate with the prelude
48
+ let names: & [ & str ] = if attr:: contains_name ( & krate. attrs , "no_core" ) {
48
49
return krate;
49
50
} else if attr:: contains_name ( & krate. attrs , "no_std" ) {
50
- "core"
51
+ if attr:: contains_name ( & krate. attrs , "compiler_builtins" ) {
52
+ & [ "core" ]
53
+ } else {
54
+ & [ "core" , "compiler_builtins" ]
55
+ }
51
56
} else {
52
- "std"
57
+ & [ "std" ]
53
58
} ;
54
59
55
- INJECTED_CRATE_NAME . with ( |opt_name| opt_name. set ( Some ( name) ) ) ;
60
+ for name in names {
61
+ krate. module . items . insert ( 0 , P ( ast:: Item {
62
+ attrs : vec ! [ attr:: mk_attr_outer( DUMMY_SP ,
63
+ attr:: mk_attr_id( ) ,
64
+ attr:: mk_word_item( ast:: Ident :: from_str( "macro_use" ) ) ) ] ,
65
+ vis : dummy_spanned ( ast:: VisibilityKind :: Inherited ) ,
66
+ node : ast:: ItemKind :: ExternCrate ( alt_std_name. map ( Symbol :: intern) ) ,
67
+ ident : ast:: Ident :: from_str ( name) ,
68
+ id : ast:: DUMMY_NODE_ID ,
69
+ span : DUMMY_SP ,
70
+ tokens : None ,
71
+ } ) ) ;
72
+ }
56
73
57
- krate. module . items . insert ( 0 , P ( ast:: Item {
58
- attrs : vec ! [ attr:: mk_attr_outer( DUMMY_SP ,
59
- attr:: mk_attr_id( ) ,
60
- attr:: mk_word_item( ast:: Ident :: from_str( "macro_use" ) ) ) ] ,
61
- vis : dummy_spanned ( ast:: VisibilityKind :: Inherited ) ,
62
- node : ast:: ItemKind :: ExternCrate ( alt_std_name. map ( Symbol :: intern) ) ,
63
- ident : ast:: Ident :: from_str ( name) ,
64
- id : ast:: DUMMY_NODE_ID ,
65
- span : DUMMY_SP ,
66
- tokens : None ,
67
- } ) ) ;
74
+ // the crates have been injected, the assumption is that the first one is the one with
75
+ // the prelude.
76
+ let name = names[ 0 ] ;
77
+
78
+ INJECTED_CRATE_NAME . with ( |opt_name| opt_name. set ( Some ( name) ) ) ;
68
79
69
80
let span = ignored_span ( DUMMY_SP ) ;
70
81
krate. module . items . insert ( 0 , P ( ast:: Item {
0 commit comments