|
1 |
| -use crate::ast; |
2 |
| -use crate::attr; |
3 |
| -use crate::edition::Edition; |
4 |
| -use crate::ext::hygiene::{ExpnId, MacroKind}; |
5 |
| -use crate::symbol::{Ident, Symbol, kw, sym}; |
6 |
| -use crate::source_map::{ExpnInfo, ExpnKind, dummy_spanned, respan}; |
7 |
| -use crate::ptr::P; |
8 |
| -use crate::tokenstream::TokenStream; |
9 |
| - |
10 |
| -use std::cell::Cell; |
11 |
| -use std::iter; |
| 1 | +use syntax::{ast, attr}; |
| 2 | +use syntax::edition::Edition; |
| 3 | +use syntax::ext::hygiene::{ExpnId, MacroKind}; |
| 4 | +use syntax::ptr::P; |
| 5 | +use syntax::source_map::{ExpnInfo, ExpnKind, dummy_spanned, respan}; |
| 6 | +use syntax::symbol::{Ident, Symbol, kw, sym}; |
| 7 | +use syntax::tokenstream::TokenStream; |
12 | 8 | use syntax_pos::DUMMY_SP;
|
13 | 9 |
|
14 |
| -pub fn injected_crate_name() -> Option<&'static str> { |
15 |
| - INJECTED_CRATE_NAME.with(|name| name.get()) |
16 |
| -} |
17 |
| - |
18 |
| -thread_local! { |
19 |
| - // A `Symbol` might make more sense here, but it doesn't work, probably for |
20 |
| - // reasons relating to the use of thread-local storage for the Symbol |
21 |
| - // interner. |
22 |
| - static INJECTED_CRATE_NAME: Cell<Option<&'static str>> = Cell::new(None); |
23 |
| -} |
| 10 | +use std::iter; |
24 | 11 |
|
25 |
| -pub fn maybe_inject_crates_ref( |
26 |
| - mut krate: ast::Crate, |
27 |
| - alt_std_name: Option<&str>, |
28 |
| - edition: Edition, |
29 |
| -) -> ast::Crate { |
| 12 | +pub fn inject( |
| 13 | + mut krate: ast::Crate, alt_std_name: Option<&str>, edition: Edition |
| 14 | +) -> (ast::Crate, Option<Symbol>) { |
30 | 15 | let rust_2018 = edition >= Edition::Edition2018;
|
31 | 16 |
|
32 | 17 | // the first name in this list is the crate name of the crate with the prelude
|
33 | 18 | let names: &[&str] = if attr::contains_name(&krate.attrs, sym::no_core) {
|
34 |
| - return krate; |
| 19 | + return (krate, None); |
35 | 20 | } else if attr::contains_name(&krate.attrs, sym::no_std) {
|
36 | 21 | if attr::contains_name(&krate.attrs, sym::compiler_builtins) {
|
37 | 22 | &["core"]
|
@@ -73,8 +58,6 @@ pub fn maybe_inject_crates_ref(
|
73 | 58 | // the prelude.
|
74 | 59 | let name = names[0];
|
75 | 60 |
|
76 |
| - INJECTED_CRATE_NAME.with(|opt_name| opt_name.set(Some(name))); |
77 |
| - |
78 | 61 | let span = DUMMY_SP.fresh_expansion(ExpnId::root(), ExpnInfo::allow_unstable(
|
79 | 62 | ExpnKind::Macro(MacroKind::Attr, sym::std_inject), DUMMY_SP, edition,
|
80 | 63 | [sym::prelude_import][..].into(),
|
@@ -108,5 +91,5 @@ pub fn maybe_inject_crates_ref(
|
108 | 91 | tokens: None,
|
109 | 92 | }));
|
110 | 93 |
|
111 |
| - krate |
| 94 | + (krate, Some(Symbol::intern(name))) |
112 | 95 | }
|
0 commit comments