c++: Implement C++26 CWG2819 - Allow cv void * null pointer value conversion to objec...
[official-gcc.git] / libgrust / libproc_macro / ident.rs
blobcdbd2d38ddc5d4bf57ec5cdcefa5af85f9bae3bd
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;
25 use Span;
27 /// An identifier.
28 #[derive(Clone)]
29 pub struct Ident(pub(crate) bridge::ident::Ident);
31 impl Ident {
32     /// Creates a new identifier.
33     ///
34     /// # Arguments
35     ///
36     /// * `string` - A valid identifier.
37     /// * `span` - The span of the identifier.
38     ///
39     /// # Panics
40     ///
41     /// The `string` argument must be a valid identifier permitted by the
42     /// language, otherwise the function will panic.
43     pub fn new(string: &str, span: Span) -> Self {
44         Ident(bridge::ident::Ident::new(string, span.0))
45     }
47     /// Creates a new raw identifier.
48     ///
49     /// # Arguments
50     ///
51     /// * `string` - A valid identifier.
52     /// * `span` - The span of the identifier.
53     ///
54     /// # Panics
55     ///
56     /// The `string` argument must be a valid identifier permitted by the
57     /// language. Furthermore, it should not be a keyword used in path
58     /// segments, otherwise this function will panic.
59     pub fn new_raw(string: &str, span: Span) -> Self {
60         Ident(bridge::ident::Ident::new_raw(string, span.0))
61     }
63     /// Return the span of the identifier
64     pub fn span(&self) -> Span {
65         Span(self.0.span())
66     }
68     /// Change the span of the identifier.
69     ///
70     /// # Arguments
71     ///
72     /// * `span` - The new span value.
73     pub fn set_span(&mut self, span: Span) {
74         self.0.set_span(span.0);
75     }
78 impl fmt::Display for Ident {
79     /// Display as lossless converted string.
80     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
81         self.0.fmt(f)
82     }
85 impl fmt::Debug for Ident {
86     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
87         self.0.fmt(f)
88     }