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