mirror of
https://gitee.com/openharmony/third_party_rust_proc-macro2
synced 2024-11-23 15:29:39 +00:00
Span::resolved_at and Span::located_at to combine behavior of two spans
This commit is contained in:
parent
71c4b88c5c
commit
4e8e3973f7
12
src/lib.rs
12
src/lib.rs
@ -162,6 +162,18 @@ impl Span {
|
||||
Span(imp::Span::def_site())
|
||||
}
|
||||
|
||||
/// Creates a new span with the same line/column information as `self` but
|
||||
/// that resolves symbols as though it were at `other`.
|
||||
pub fn resolved_at(&self, other: Span) -> Span {
|
||||
Span(self.0.resolved_at(other.0))
|
||||
}
|
||||
|
||||
/// Creates a new span with the same name resolution behavior as `self` but
|
||||
/// with the line/column information of `other`.
|
||||
pub fn located_at(&self, other: Span) -> Span {
|
||||
Span(self.0.located_at(other.0))
|
||||
}
|
||||
|
||||
/// This method is only available when the `"nightly"` feature is enabled.
|
||||
#[cfg(feature = "nightly")]
|
||||
pub fn unstable(self) -> proc_macro::Span {
|
||||
|
@ -334,6 +334,17 @@ impl Span {
|
||||
Span::call_site()
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
pub fn located_at(&self, other: Span) -> Span {
|
||||
other
|
||||
}
|
||||
|
||||
#[cfg(procmacro2_semver_exempt)]
|
||||
pub fn source_file(&self) -> SourceFile {
|
||||
CODEMAP.with(|cm| {
|
||||
|
@ -225,6 +225,14 @@ impl Span {
|
||||
Span(proc_macro::Span::def_site())
|
||||
}
|
||||
|
||||
pub fn resolved_at(&self, other: Span) -> Span {
|
||||
Span(self.0.resolved_at(other.0))
|
||||
}
|
||||
|
||||
pub fn located_at(&self, other: Span) -> Span {
|
||||
Span(self.0.located_at(other.0))
|
||||
}
|
||||
|
||||
pub fn unstable(self) -> proc_macro::Span {
|
||||
self.0
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user