Skip to content

Commit 5671a59

Browse files
authored
Merge pull request #311 from dtolnay/cfg
Try to diagnose "cannot find type SourceFile" errors better
2 parents 3ff70da + dc609ab commit 5671a59

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/lib.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@
106106
clippy::vec_init_then_push
107107
)]
108108

109+
#[cfg(all(procmacro2_semver_exempt, wrap_proc_macro, not(super_unstable)))]
110+
compile_error! {"\
111+
Something is not right. If you've tried to turn on \
112+
procmacro2_semver_exempt, you need to ensure that it \
113+
is turned on for the compilation of the proc-macro2 \
114+
build script as well.
115+
"}
116+
109117
#[cfg(use_proc_macro)]
110118
extern crate proc_macro;
111119

@@ -295,15 +303,15 @@ impl Error for LexError {}
295303
/// The source file of a given `Span`.
296304
///
297305
/// This type is semver exempt and not exposed by default.
298-
#[cfg(procmacro2_semver_exempt)]
306+
#[cfg(all(procmacro2_semver_exempt, any(not(wrap_proc_macro), super_unstable)))]
299307
#[cfg_attr(doc_cfg, doc(cfg(procmacro2_semver_exempt)))]
300308
#[derive(Clone, PartialEq, Eq)]
301309
pub struct SourceFile {
302310
inner: imp::SourceFile,
303311
_marker: Marker,
304312
}
305313

306-
#[cfg(procmacro2_semver_exempt)]
314+
#[cfg(all(procmacro2_semver_exempt, any(not(wrap_proc_macro), super_unstable)))]
307315
impl SourceFile {
308316
fn _new(inner: imp::SourceFile) -> Self {
309317
SourceFile {
@@ -336,7 +344,7 @@ impl SourceFile {
336344
}
337345
}
338346

339-
#[cfg(procmacro2_semver_exempt)]
347+
#[cfg(all(procmacro2_semver_exempt, any(not(wrap_proc_macro), super_unstable)))]
340348
impl Debug for SourceFile {
341349
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
342350
Debug::fmt(&self.inner, f)
@@ -461,7 +469,7 @@ impl Span {
461469
/// The original source file into which this span points.
462470
///
463471
/// This method is semver exempt and not exposed by default.
464-
#[cfg(procmacro2_semver_exempt)]
472+
#[cfg(all(procmacro2_semver_exempt, any(not(wrap_proc_macro), super_unstable)))]
465473
#[cfg_attr(doc_cfg, doc(cfg(procmacro2_semver_exempt)))]
466474
pub fn source_file(&self) -> SourceFile {
467475
SourceFile::_new(self.inner.source_file())

0 commit comments

Comments
 (0)