Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/rust/proc-macro2/probe/proc_macro_span.rs
38316 views
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
9
extern crate proc_macro;
10
11
use core::ops::{Range, RangeBounds};
12
use proc_macro::{Literal, Span};
13
use std::path::PathBuf;
14
15
pub fn byte_range(this: &Span) -> Range<usize> {
16
this.byte_range()
17
}
18
19
pub fn start(this: &Span) -> Span {
20
this.start()
21
}
22
23
pub fn end(this: &Span) -> Span {
24
this.end()
25
}
26
27
pub fn line(this: &Span) -> usize {
28
this.line()
29
}
30
31
pub fn column(this: &Span) -> usize {
32
this.column()
33
}
34
35
pub fn file(this: &Span) -> String {
36
this.file()
37
}
38
39
pub fn local_file(this: &Span) -> Option<PathBuf> {
40
this.local_file()
41
}
42
43
pub fn join(this: &Span, other: Span) -> Option<Span> {
44
this.join(other)
45
}
46
47
pub 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)]
53
const _: Option<&str> = option_env!("RUSTC_BOOTSTRAP");
54
55