Debian Codegraph @

gcc/rust/checks/errors/rust-feature.h

raw
1 // Copyright (C) 2020-2025 Free Software Foundation, Inc.
2
3 // This file is part of GCC.
4
5 // GCC is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation; either version 3, or (at your option) any later
8 // version.
9
10 // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 // for more details.
14
15 // You should have received a copy of the GNU General Public License
16 // along with GCC; see the file COPYING3. If not see
17 // <http://www.gnu.org/licenses/>.
18
19 #ifndef RUST_FEATURE_H
20 #define RUST_FEATURE_H
21
22 #include "rust-edition.h"
23 #include "optional.h"
24
25 namespace Rust {
26
27 class Feature
28 {
29 public:
30 enum class State
31 {
32 ACCEPTED,
33 ACTIVE,
34 REMOVED,
35 STABILIZED,
36 };
37
38 enum class Name
39 {
40 ASSOCIATED_TYPE_BOUNDS,
41 INTRINSICS,
42 NEGATIVE_IMPLS,
43 RUSTC_ATTRS,
44 DECL_MACRO,
45 AUTO_TRAITS,
46 EXTERN_TYPES,
47 LANG_ITEMS,
48 NO_CORE,
49 BOX_SYNTAX,
50 DROPCK_EYEPATCH,
51 RAW_REF_OP,
52 EXCLUSIVE_RANGE_PATTERN,
53 PRELUDE_IMPORT,
54 MIN_SPECIALIZATION,
55 };
56
57 const std::string &as_string () { return m_name_str; }
58 Name name () { return m_name; }
59 const std::string &description () { return m_description; }
60 State state () { return m_state; }
61 tl::optional<unsigned> issue () { return m_issue; }
62
63 static tl::optional<Name> as_name (const std::string &name);
64 static Feature create (Name name);
65
66 private:
67 Feature (Name name, State state, const char *name_str,
68 const char *rustc_since,
69 tl::optional<unsigned> issue_number = tl::nullopt,
70 const tl::optional<Edition> &edition = tl::nullopt,
71 const char *description = "")
72 : m_state (state), m_name (name), m_name_str (name_str),
73 m_rustc_since (rustc_since), m_issue (issue_number), edition (edition),
74 m_description (description)
75 {}
76
77 State m_state;
78 Name m_name;
79 std::string m_name_str;
80 std::string m_rustc_since;
81 tl::optional<unsigned> m_issue;
82 tl::optional<Edition> edition;
83 std::string m_description; // TODO: Switch to optional?
84
85 static const std::map<std::string, Name> name_hash_map;
86 };
87
88 } // namespace Rust
89 #endif