proc_macro2/probe/proc_macro_span.rs
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, no_std)]
6#![cfg_attr(procmacro2_build_probe, feature(proc_macro_span))]
7
8extern crate alloc;
9extern crate proc_macro;
10extern crate std;
11
12use alloc::string::String;
13use core::ops::{Range, RangeBounds};
14use proc_macro::{Literal, Span};
15use std::path::PathBuf;
16
17pub fn byte_range(this: &Span) -> Range<usize> {
18 this.byte_range()
19}
20
21pub fn start(this: &Span) -> Span {
22 this.start()
23}
24
25pub fn end(this: &Span) -> Span {
26 this.end()
27}
28
29pub fn line(this: &Span) -> usize {
30 this.line()
31}
32
33pub fn column(this: &Span) -> usize {
34 this.column()
35}
36
37pub fn file(this: &Span) -> String {
38 this.file()
39}
40
41pub fn local_file(this: &Span) -> Option<PathBuf> {
42 this.local_file()
43}
44
45pub fn join(this: &Span, other: Span) -> Option<Span> {
46 this.join(other)
47}
48
49pub fn subspan<R: RangeBounds<usize>>(this: &Literal, range: R) -> Option<Span> {
50 this.subspan(range)
51}
52
53// Include in sccache cache key.
54#[cfg(procmacro2_build_probe)]
55const _: Option<&str> = option_env!("RUSTC_BOOTSTRAP");