File tree Expand file tree Collapse file tree 4 files changed +15
-25
lines changed Expand file tree Collapse file tree 4 files changed +15
-25
lines changed Original file line number Diff line number Diff line change @@ -95,13 +95,7 @@ pub fn lower_crate(sess: &Session,
95
95
let _ignore = sess. dep_graph . in_ignore ( ) ;
96
96
97
97
LoweringContext {
98
- crate_root : if std_inject:: no_core ( krate) {
99
- None
100
- } else if std_inject:: no_std ( krate) {
101
- Some ( "core" )
102
- } else {
103
- Some ( "std" )
104
- } ,
98
+ crate_root : std_inject:: injected_crate_name ( krate) ,
105
99
sess : sess,
106
100
parent_def : None ,
107
101
resolver : resolver,
Original file line number Diff line number Diff line change @@ -739,13 +739,7 @@ impl<'a> ExtCtxt<'a> {
739
739
}
740
740
741
741
pub fn initialize ( & mut self , user_exts : Vec < NamedSyntaxExtension > , krate : & ast:: Crate ) {
742
- if std_inject:: no_core ( & krate) {
743
- self . crate_root = None ;
744
- } else if std_inject:: no_std ( & krate) {
745
- self . crate_root = Some ( "core" ) ;
746
- } else {
747
- self . crate_root = Some ( "std" ) ;
748
- }
742
+ self . crate_root = std_inject:: injected_crate_name ( krate) ;
749
743
750
744
for ( name, extension) in user_exts {
751
745
let ident = ast:: Ident :: with_empty_ctxt ( name) ;
Original file line number Diff line number Diff line change @@ -112,7 +112,7 @@ pub fn print_crate<'a>(cm: &'a CodeMap,
112
112
out,
113
113
ann,
114
114
is_expanded) ;
115
- if is_expanded && !std_inject:: no_std ( krate) {
115
+ if is_expanded && !std_inject:: injected_crate_name ( krate) . is_none ( ) {
116
116
// We need to print `#![no_std]` (and its feature gate) so that
117
117
// compiling pretty-printed source won't inject libstd again.
118
118
// However we don't want these attributes in the AST because
Original file line number Diff line number Diff line change @@ -34,23 +34,25 @@ fn ignored_span(sess: &ParseSess, sp: Span) -> Span {
34
34
return sp;
35
35
}
36
36
37
- pub fn no_core ( krate : & ast:: Crate ) -> bool {
38
- attr:: contains_name ( & krate. attrs , "no_core" )
39
- }
40
-
41
- pub fn no_std ( krate : & ast:: Crate ) -> bool {
42
- attr:: contains_name ( & krate. attrs , "no_std" ) || no_core ( krate)
37
+ pub fn injected_crate_name ( krate : & ast:: Crate ) -> Option < & ' static str > {
38
+ if attr:: contains_name ( & krate. attrs , "no_core" ) {
39
+ None
40
+ } else if attr:: contains_name ( & krate. attrs , "no_std" ) {
41
+ Some ( "core" )
42
+ } else {
43
+ Some ( "std" )
44
+ }
43
45
}
44
46
45
47
pub fn maybe_inject_crates_ref ( sess : & ParseSess ,
46
48
mut krate : ast:: Crate ,
47
49
alt_std_name : Option < String > )
48
50
-> ast:: Crate {
49
- if no_core ( & krate) {
50
- return krate;
51
- }
51
+ let name = match injected_crate_name ( & krate) {
52
+ Some ( name) => name,
53
+ None => return krate,
54
+ } ;
52
55
53
- let name = if no_std ( & krate) { "core" } else { "std" } ;
54
56
let crate_name = token:: intern ( & alt_std_name. unwrap_or ( name. to_string ( ) ) ) ;
55
57
56
58
krate. module . items . insert ( 0 , P ( ast:: Item {
You can’t perform that action at this time.
0 commit comments