Skip to content

Commit

Permalink
Try to diagnose "cannot find type SourceFile" errors better
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Dec 14, 2021
1 parent 3ff70da commit dc609ab
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@
clippy::vec_init_then_push
)]

#[cfg(all(procmacro2_semver_exempt, wrap_proc_macro, not(super_unstable)))]
compile_error! {"\
Something is not right. If you've tried to turn on \
procmacro2_semver_exempt, you need to ensure that it \
is turned on for the compilation of the proc-macro2 \
build script as well.
"}

#[cfg(use_proc_macro)]
extern crate proc_macro;

Expand Down Expand Up @@ -295,15 +303,15 @@ impl Error for LexError {}
/// The source file of a given `Span`.
///
/// This type is semver exempt and not exposed by default.
#[cfg(procmacro2_semver_exempt)]
#[cfg(all(procmacro2_semver_exempt, any(not(wrap_proc_macro), super_unstable)))]
#[cfg_attr(doc_cfg, doc(cfg(procmacro2_semver_exempt)))]
#[derive(Clone, PartialEq, Eq)]
pub struct SourceFile {
inner: imp::SourceFile,
_marker: Marker,
}

#[cfg(procmacro2_semver_exempt)]
#[cfg(all(procmacro2_semver_exempt, any(not(wrap_proc_macro), super_unstable)))]
impl SourceFile {
fn _new(inner: imp::SourceFile) -> Self {
SourceFile {
Expand Down Expand Up @@ -336,7 +344,7 @@ impl SourceFile {
}
}

#[cfg(procmacro2_semver_exempt)]
#[cfg(all(procmacro2_semver_exempt, any(not(wrap_proc_macro), super_unstable)))]
impl Debug for SourceFile {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Debug::fmt(&self.inner, f)
Expand Down Expand Up @@ -461,7 +469,7 @@ impl Span {
/// The original source file into which this span points.
///
/// This method is semver exempt and not exposed by default.
#[cfg(procmacro2_semver_exempt)]
#[cfg(all(procmacro2_semver_exempt, any(not(wrap_proc_macro), super_unstable)))]
#[cfg_attr(doc_cfg, doc(cfg(procmacro2_semver_exempt)))]
pub fn source_file(&self) -> SourceFile {
SourceFile::_new(self.inner.source_file())
Expand Down

0 comments on commit dc609ab

Please sign in to comment.