diff options
Diffstat (limited to 'src/libsyntax/std_inject.rs')
| -rw-r--r-- | src/libsyntax/std_inject.rs | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/src/libsyntax/std_inject.rs b/src/libsyntax/std_inject.rs index daa51203287..28b9eaa54aa 100644 --- a/src/libsyntax/std_inject.rs +++ b/src/libsyntax/std_inject.rs @@ -40,7 +40,7 @@ pub fn maybe_inject_prelude(krate: ast::Crate) -> ast::Crate { } fn use_std(krate: &ast::Crate) -> bool { - !attr::contains_name(krate.attrs.index(&FullRange), "no_std") + !attr::contains_name(&krate.attrs[], "no_std") } fn no_prelude(attrs: &[ast::Attribute]) -> bool { @@ -48,7 +48,7 @@ fn no_prelude(attrs: &[ast::Attribute]) -> bool { } struct StandardLibraryInjector<'a> { - alt_std_name: Option<String>, + alt_std_name: Option<String> } impl<'a> fold::Folder for StandardLibraryInjector<'a> { @@ -56,7 +56,7 @@ impl<'a> fold::Folder for StandardLibraryInjector<'a> { // The name to use in `extern crate "name" as std;` let actual_crate_name = match self.alt_std_name { - Some(ref s) => token::intern_and_get_ident(s.index(&FullRange)), + Some(ref s) => token::intern_and_get_ident(&s[]), None => token::intern_and_get_ident("std"), }; @@ -84,14 +84,13 @@ impl<'a> fold::Folder for StandardLibraryInjector<'a> { fn inject_crates_ref(krate: ast::Crate, alt_std_name: Option<String>) -> ast::Crate { let mut fold = StandardLibraryInjector { - alt_std_name: alt_std_name, + alt_std_name: alt_std_name }; fold.fold_crate(krate) } struct PreludeInjector<'a>; - impl<'a> fold::Folder for PreludeInjector<'a> { fn fold_crate(&mut self, mut krate: ast::Crate) -> ast::Crate { // Add #![no_std] here, so we don't re-inject when compiling pretty-printed source. @@ -104,27 +103,17 @@ impl<'a> fold::Folder for PreludeInjector<'a> { attr::mark_used(&no_std_attr); krate.attrs.push(no_std_attr); - if !no_prelude(krate.attrs.index(&FullRange)) { - // only add `use std::prelude::*;` if there wasn't a - // `#![no_implicit_prelude]` at the crate level. - // fold_mod() will insert glob path. - let globs_attr = attr::mk_attr_inner(attr::mk_attr_id(), - attr::mk_list_item( - InternedString::new("feature"), - vec!( - attr::mk_word_item(InternedString::new("globs")), - ))); - // std_inject runs after feature checking so manually mark this attr - attr::mark_used(&globs_attr); - krate.attrs.push(globs_attr); - + // only add `use std::prelude::*;` if there wasn't a + // `#![no_implicit_prelude]` at the crate level. + // fold_mod() will insert glob path. + if !no_prelude(&krate.attrs[]) { krate.module = self.fold_mod(krate.module); } krate } fn fold_item(&mut self, item: P<ast::Item>) -> SmallVector<P<ast::Item>> { - if !no_prelude(item.attrs.index(&FullRange)) { + if !no_prelude(&item.attrs[]) { // only recur if there wasn't `#![no_implicit_prelude]` // on this item, i.e. this means that the prelude is not // implicitly imported though the whole subtree |
