projects/linux·blob master · refs

53 lines · 1.1 KiB

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