Skip to content

Commit

Permalink
Stabilize Span::resolved_at + Span::located_at with hygiene feature
Browse files Browse the repository at this point in the history
These were stabilized in Rust in
rust-lang/rust#69041
  • Loading branch information
kevinmehall committed May 18, 2020
1 parent f093323 commit facc69f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ default = ["proc-macro"]
# of a token.
span-locations = []

# Span::mixed_site, Span::resolved_at, and Span::located_at. Requires rustc 1.45+
hygiene = []

# This feature no longer means anything.
Expand Down
4 changes: 2 additions & 2 deletions src/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,15 +384,15 @@ impl Span {
Span::call_site()
}

#[cfg(procmacro2_semver_exempt)]
#[cfg(hygiene)]
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)]
#[cfg(hygiene)]
pub fn located_at(&self, other: Span) -> Span {
other
}
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,17 +371,17 @@ impl Span {
/// Creates a new span with the same line/column information as `self` but
/// that resolves symbols as though it were at `other`.
///
/// This method is semver exempt and not exposed by default.
#[cfg(procmacro2_semver_exempt)]
/// This method requires the `"hygiene"` feature to be enabled.
#[cfg(hygiene)]
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`.
///
/// This method is semver exempt and not exposed by default.
#[cfg(procmacro2_semver_exempt)]
/// This method requires the `"hygiene"` feature to be enabled.
#[cfg(hygiene)]
pub fn located_at(&self, other: Span) -> Span {
Span::_new(self.inner.located_at(other.inner))
}
Expand Down
4 changes: 2 additions & 2 deletions src/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ impl Span {
}
}

#[cfg(super_unstable)]
#[cfg(hygiene)]
pub fn resolved_at(&self, other: Span) -> Span {
match (self, other) {
(Span::Compiler(a), Span::Compiler(b)) => Span::Compiler(a.resolved_at(b)),
Expand All @@ -403,7 +403,7 @@ impl Span {
}
}

#[cfg(super_unstable)]
#[cfg(hygiene)]
pub fn located_at(&self, other: Span) -> Span {
match (self, other) {
(Span::Compiler(a), Span::Compiler(b)) => Span::Compiler(a.located_at(b)),
Expand Down

0 comments on commit facc69f

Please sign in to comment.