Skip to main content

proc_macro2/probe/
proc_macro_span.rs

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};
13
14pub fn byte_range(this: &Span) -> Range<usize> {
15    this.byte_range()
16}
17
18pub fn start(this: &Span) -> Span {
19    this.start()
20}
21
22pub fn end(this: &Span) -> Span {
23    this.end()
24}
25
26pub fn line(this: &Span) -> usize {
27    this.line()
28}
29
30pub fn column(this: &Span) -> usize {
31    this.column()
32}
33
34pub fn join(this: &Span, other: Span) -> Option<Span> {
35    this.join(other)
36}
37
38pub fn subspan<R: RangeBounds<usize>>(this: &Literal, range: R) -> Option<Span> {
39    this.subspan(range)
40}
41
42// Include in sccache cache key.
43#[cfg(procmacro2_build_probe)]
44const _: Option<&str> = option_env!("RUSTC_BOOTSTRAP");