proc_macro_span.rs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // SPDX-License-Identifier: Apache-2.0 OR MIT
  2. // This code exercises the surface area that we expect of Span's unstable API.
  3. // If the current toolchain is able to compile it, then proc-macro2 is able to
  4. // offer these APIs too.
  5. #![cfg_attr(procmacro2_build_probe, feature(proc_macro_span))]
  6. extern crate proc_macro;
  7. use core::ops::{Range, RangeBounds};
  8. use proc_macro::{Literal, Span};
  9. use std::path::PathBuf;
  10. pub fn byte_range(this: &Span) -> Range<usize> {
  11. this.byte_range()
  12. }
  13. pub fn start(this: &Span) -> Span {
  14. this.start()
  15. }
  16. pub fn end(this: &Span) -> Span {
  17. this.end()
  18. }
  19. pub fn line(this: &Span) -> usize {
  20. this.line()
  21. }
  22. pub fn column(this: &Span) -> usize {
  23. this.column()
  24. }
  25. pub fn file(this: &Span) -> String {
  26. this.file()
  27. }
  28. pub fn local_file(this: &Span) -> Option<PathBuf> {
  29. this.local_file()
  30. }
  31. pub fn join(this: &Span, other: Span) -> Option<Span> {
  32. this.join(other)
  33. }
  34. pub fn subspan<R: RangeBounds<usize>>(this: &Literal, range: R) -> Option<Span> {
  35. this.subspan(range)
  36. }
  37. // Include in sccache cache key.
  38. #[cfg(procmacro2_build_probe)]
  39. const _: Option<&str> = option_env!("RUSTC_BOOTSTRAP");