Combine std_inject::{no_core, no_std} into std_inject::injected_crate_name.
This commit is contained in:
parent
75c155b834
commit
2df25adbed
4 changed files with 15 additions and 25 deletions
|
|
@ -95,13 +95,7 @@ pub fn lower_crate(sess: &Session,
|
|||
let _ignore = sess.dep_graph.in_ignore();
|
||||
|
||||
LoweringContext {
|
||||
crate_root: if std_inject::no_core(krate) {
|
||||
None
|
||||
} else if std_inject::no_std(krate) {
|
||||
Some("core")
|
||||
} else {
|
||||
Some("std")
|
||||
},
|
||||
crate_root: std_inject::injected_crate_name(krate),
|
||||
sess: sess,
|
||||
parent_def: None,
|
||||
resolver: resolver,
|
||||
|
|
|
|||
|
|
@ -739,13 +739,7 @@ impl<'a> ExtCtxt<'a> {
|
|||
}
|
||||
|
||||
pub fn initialize(&mut self, user_exts: Vec<NamedSyntaxExtension>, krate: &ast::Crate) {
|
||||
if std_inject::no_core(&krate) {
|
||||
self.crate_root = None;
|
||||
} else if std_inject::no_std(&krate) {
|
||||
self.crate_root = Some("core");
|
||||
} else {
|
||||
self.crate_root = Some("std");
|
||||
}
|
||||
self.crate_root = std_inject::injected_crate_name(krate);
|
||||
|
||||
for (name, extension) in user_exts {
|
||||
let ident = ast::Ident::with_empty_ctxt(name);
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ pub fn print_crate<'a>(cm: &'a CodeMap,
|
|||
out,
|
||||
ann,
|
||||
is_expanded);
|
||||
if is_expanded && !std_inject::no_std(krate) {
|
||||
if is_expanded && !std_inject::injected_crate_name(krate).is_none() {
|
||||
// We need to print `#![no_std]` (and its feature gate) so that
|
||||
// compiling pretty-printed source won't inject libstd again.
|
||||
// However we don't want these attributes in the AST because
|
||||
|
|
|
|||
|
|
@ -34,23 +34,25 @@ fn ignored_span(sess: &ParseSess, sp: Span) -> Span {
|
|||
return sp;
|
||||
}
|
||||
|
||||
pub fn no_core(krate: &ast::Crate) -> bool {
|
||||
attr::contains_name(&krate.attrs, "no_core")
|
||||
}
|
||||
|
||||
pub fn no_std(krate: &ast::Crate) -> bool {
|
||||
attr::contains_name(&krate.attrs, "no_std") || no_core(krate)
|
||||
pub fn injected_crate_name(krate: &ast::Crate) -> Option<&'static str> {
|
||||
if attr::contains_name(&krate.attrs, "no_core") {
|
||||
None
|
||||
} else if attr::contains_name(&krate.attrs, "no_std") {
|
||||
Some("core")
|
||||
} else {
|
||||
Some("std")
|
||||
}
|
||||
}
|
||||
|
||||
pub fn maybe_inject_crates_ref(sess: &ParseSess,
|
||||
mut krate: ast::Crate,
|
||||
alt_std_name: Option<String>)
|
||||
-> ast::Crate {
|
||||
if no_core(&krate) {
|
||||
return krate;
|
||||
}
|
||||
let name = match injected_crate_name(&krate) {
|
||||
Some(name) => name,
|
||||
None => return krate,
|
||||
};
|
||||
|
||||
let name = if no_std(&krate) { "core" } else { "std" };
|
||||
let crate_name = token::intern(&alt_std_name.unwrap_or(name.to_string()));
|
||||
|
||||
krate.module.items.insert(0, P(ast::Item {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue