Skip to content

Commit e78151e

Browse files
committed
Disable std prelude
1 parent 2fbddd4 commit e78151e

File tree

8 files changed

+34
-1
lines changed

8 files changed

+34
-1
lines changed

src/fallback.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@ use crate::location::LineColumn;
55
use crate::parse::{self, Cursor};
66
use crate::rcvec::{RcVec, RcVecBuilder, RcVecIntoIter, RcVecMut};
77
use crate::{Delimiter, Spacing, TokenTree};
8+
use alloc::borrow::ToOwned as _;
9+
use alloc::boxed::Box;
810
#[cfg(all(span_locations, not(fuzzing)))]
911
use alloc::collections::BTreeMap;
12+
use alloc::format;
13+
use alloc::string::{String, ToString as _};
14+
#[cfg(all(span_locations, not(fuzzing)))]
15+
use alloc::vec;
16+
use alloc::vec::Vec;
1017
#[cfg(all(span_locations, not(fuzzing)))]
1118
use core::cell::RefCell;
1219
#[cfg(span_locations)]
@@ -27,6 +34,8 @@ use core::str::FromStr;
2734
use std::panic;
2835
#[cfg(span_locations)]
2936
use std::path::PathBuf;
37+
#[cfg(all(span_locations, not(fuzzing)))]
38+
use std::thread_local;
3039

3140
/// Force use of proc-macro2's fallback implementation of the API for now, even
3241
/// if the compiler's implementation is available.

src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
//! types make use of thread-local memory, meaning they cannot be accessed from
8484
//! a different thread.
8585
86+
#![no_std]
8687
#![doc(html_root_url = "https://docs.rs/proc-macro2/1.0.104")]
8788
#![cfg_attr(any(proc_macro_span, super_unstable), feature(proc_macro_span))]
8889
#![cfg_attr(super_unstable, feature(proc_macro_def_site))]
@@ -135,6 +136,7 @@ compile_error! {"\
135136
"}
136137

137138
extern crate alloc;
139+
extern crate std;
138140

139141
#[cfg(feature = "proc-macro")]
140142
extern crate proc_macro;
@@ -173,6 +175,11 @@ use crate::extra::DelimSpan;
173175
use crate::marker::{ProcMacroAutoTraits, MARKER};
174176
#[cfg(procmacro2_semver_exempt)]
175177
use crate::rustc_literal_escaper::MixedUnit;
178+
#[cfg(procmacro2_semver_exempt)]
179+
use alloc::borrow::ToOwned as _;
180+
use alloc::string::{String, ToString as _};
181+
#[cfg(procmacro2_semver_exempt)]
182+
use alloc::vec::Vec;
176183
use core::cmp::Ordering;
177184
use core::ffi::CStr;
178185
use core::fmt::{self, Debug, Display};

src/parse.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ use crate::fallback::{
33
TokenStreamBuilder,
44
};
55
use crate::{Delimiter, Punct, Spacing, TokenTree};
6+
use alloc::borrow::ToOwned as _;
7+
use alloc::string::ToString as _;
8+
use alloc::vec::Vec;
69
use core::char;
710
use core::str::{Bytes, CharIndices, Chars};
811

src/probe/proc_macro_span.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
// If the current toolchain is able to compile it, then proc-macro2 is able to
33
// offer these APIs too.
44

5+
#![cfg_attr(procmacro2_build_probe, no_std)]
56
#![cfg_attr(procmacro2_build_probe, feature(proc_macro_span))]
67

8+
extern crate alloc;
79
extern crate proc_macro;
10+
extern crate std;
811

12+
use alloc::string::String;
913
use core::ops::{Range, RangeBounds};
1014
use proc_macro::{Literal, Span};
1115
use std::path::PathBuf;

src/probe/proc_macro_span_file.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
// The subset of Span's API stabilized in Rust 1.88.
22

3+
#![cfg_attr(procmacro2_build_probe, no_std)]
4+
5+
extern crate alloc;
36
extern crate proc_macro;
47

8+
use alloc::string::String;
59
use proc_macro::Span;
610
use std::path::PathBuf;
711

src/probe/proc_macro_span_location.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// The subset of Span's API stabilized in Rust 1.88.
22

3+
#![cfg_attr(procmacro2_build_probe, no_std)]
4+
35
extern crate proc_macro;
46

57
use proc_macro::Span;

src/rcvec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use alloc::rc::Rc;
2-
use alloc::vec;
2+
use alloc::vec::{self, Vec};
33
use core::mem;
44
use core::panic::RefUnwindSafe;
55
use core::slice;

src/wrapper.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ use crate::probe::proc_macro_span_file;
99
#[cfg(all(span_locations, proc_macro_span_location))]
1010
use crate::probe::proc_macro_span_location;
1111
use crate::{Delimiter, Punct, Spacing, TokenTree};
12+
#[cfg(all(span_locations, not(proc_macro_span_file)))]
13+
use alloc::borrow::ToOwned as _;
14+
use alloc::string::{String, ToString as _};
15+
use alloc::vec::Vec;
1216
use core::ffi::CStr;
1317
use core::fmt::{self, Debug, Display};
1418
#[cfg(span_locations)]

0 commit comments

Comments
 (0)