Skip to content

Commit

Permalink
Defer stabilizing span hygiene until after 1.45 release
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed May 20, 2020
1 parent 0283321 commit fc5678f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ impl Span {
Span { lo: 0, hi: 0 }
}

#[cfg(procmacro2_semver_exempt)]
#[cfg(hygiene)]
pub fn mixed_site() -> Span {
Span::call_site()
Expand All @@ -384,13 +385,15 @@ impl Span {
Span::call_site()
}

#[cfg(procmacro2_semver_exempt)]
pub fn resolved_at(&self, _other: Span) -> Span {
// Stable spans consist only of line/column information, so
// `resolved_at` and `located_at` only select which span the
// caller wants line/column information from.
*self
}

#[cfg(procmacro2_semver_exempt)]
pub fn located_at(&self, other: Span) -> Span {
other
}
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ impl Span {
/// of the macro. This is the same hygiene behavior as `macro_rules`.
///
/// This function requires Rust 1.45 or later.
#[cfg(procmacro2_semver_exempt)]
#[cfg(hygiene)]
pub fn mixed_site() -> Span {
Span::_new(imp::Span::mixed_site())
Expand All @@ -368,12 +369,14 @@ impl Span {

/// Creates a new span with the same line/column information as `self` but
/// that resolves symbols as though it were at `other`.
#[cfg(procmacro2_semver_exempt)]
pub fn resolved_at(&self, other: Span) -> Span {
Span::_new(self.inner.resolved_at(other.inner))
}

/// Creates a new span with the same name resolution behavior as `self` but
/// with the line/column information of `other`.
#[cfg(procmacro2_semver_exempt)]
pub fn located_at(&self, other: Span) -> Span {
Span::_new(self.inner.located_at(other.inner))
}
Expand Down
3 changes: 3 additions & 0 deletions src/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ impl Span {
}
}

#[cfg(procmacro2_semver_exempt)]
#[cfg(hygiene)]
pub fn mixed_site() -> Span {
if inside_proc_macro() {
Expand All @@ -394,6 +395,7 @@ impl Span {
}
}

#[cfg(procmacro2_semver_exempt)]
pub fn resolved_at(&self, other: Span) -> Span {
match (self, other) {
#[cfg(hygiene)]
Expand All @@ -408,6 +410,7 @@ impl Span {
}
}

#[cfg(procmacro2_semver_exempt)]
pub fn located_at(&self, other: Span) -> Span {
match (self, other) {
#[cfg(hygiene)]
Expand Down

0 comments on commit fc5678f

Please sign in to comment.