Daily bump.
[official-gcc.git] / libgrust / libproc_macro / span.rs
blobd6af551102a3e945b29a588c4e9c1700ae82921d
1 // Copyright (C) 2023-2024 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU Proc Macro Library.  This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
14 // Under Section 7 of GPL version 3, you are granted additional
15 // permissions described in the GCC Runtime Library Exception, version
16 // 3.1, as published by the Free Software Foundation.
18 // You should have received a copy of the GNU General Public License and
19 // a copy of the GCC Runtime Library Exception along with this program;
20 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
21 // <http://www.gnu.org/licenses/>.
23 use bridge;
24 use std::fmt;
26 /// A region of source code along with macro expansion information.
27 #[derive(Copy, Clone)]
28 pub struct Span(pub(crate) bridge::span::Span);
30 impl Span {
31     // TODO: Add experimental API functions for this type
33     /// Creates a new span that resolves at the macro call location.
34     pub fn call_site() -> Self {
35         Span(bridge::span::Span::call_site())
36     }
38     /// Creates a new span that resolved sometimes at macro call site, and
39     /// sometimes at macro definition site.
40     pub fn mixed_site() -> Self {
41         Span(bridge::span::Span::mixed_site())
42     }
44     /// Creates a new span with the same line/column informations but that
45     /// resolve symbols as though it were at `other`.
46     ///
47     /// # Arguments
48     ///
49     /// * `other` - Other span to resolve at.
50     pub fn resolved_at(&self, other: Span) -> Self {
51         Span(self.0.resolved_at(other.0))
52     }
54     /// Creates a new span with the same name resolution behavior as self, but
55     /// with the line/column information of `other`.
56     ///
57     /// # Arguments
58     ///
59     /// * `other` - Other span containing the line/column informations to use.
60     pub fn located_at(&self, other: Span) -> Self {
61         Span(self.0.located_at(other.0))
62     }
64     /// Return the source text behind a span.
65     pub fn source_text(&self) -> Option<String> {
66         self.0.source_text()
67     }
70 impl fmt::Debug for Span {
71     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
72         self.0.fmt(f)
73     }