Skip to content

Commit bee59d6

Browse files
powerboat9P-E-P
authored andcommitted
Reduce usage of rust-session-manager.h
gcc/rust/ChangeLog: * util/rust-edition.cc: New file. * util/rust-edition.h: New file. * Make-lang.in: Add rust-edition.o to the object list. * ast/rust-pattern.cc: Remove inclusion of rust-session-manager.h. * expand/rust-macro-expand.cc: Likewise. * expand/rust-macro-builtins-helpers.h: Likewise. * expand/rust-macro-builtins-include.cc: Include rust-session-manager.h. * expand/rust-macro-builtins-utility.cc: Likewise. * lex/rust-lex.cc: Include rust-edition.h instead of rust-session-manager.h. (Lexer::classify_keyword): Use get_rust_edition instead of Session and CompileOptions. * parse/rust-parse-impl.h: Include rust-edition.h instead of rust-session-manager.h. (Parser::parse_async_item): Use get_rust_edition instead of Session and CompileOptions. * checks/errors/rust-feature.h: Include rust-edition.h instead of rust-session-manager.h. (class Feature): Use Rust::Edition instead of Rust::CompileOptions::Edition. Signed-off-by: Owen Avery <[email protected]>
1 parent 9e6d06e commit bee59d6

11 files changed

+91
-13
lines changed

gcc/rust/Make-lang.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ GRS_OBJS = \
235235
rust/rust-unicode.o \
236236
rust/rust-punycode.o \
237237
rust/rust-unwrap-segment.o \
238+
rust/rust-edition.o \
238239
rust/rust-expand-format-args.o \
239240
rust/rust-lang-item.o \
240241
rust/rust-collect-lang-items.o \

gcc/rust/ast/rust-pattern.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ along with GCC; see the file COPYING3. If not see
2222
#include "rust-diagnostics.h"
2323
#include "rust-ast-visitor.h"
2424
#include "rust-macro.h"
25-
#include "rust-session-manager.h"
2625
#include "rust-lex.h"
2726
#include "rust-parse.h"
2827
#include "rust-operators.h"

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#ifndef RUST_FEATURE_H
2020
#define RUST_FEATURE_H
2121

22-
#include "rust-session-manager.h"
22+
#include "rust-edition.h"
2323
#include "optional.h"
2424

2525
namespace Rust {
@@ -66,7 +66,7 @@ class Feature
6666
Feature (Name name, State state, const char *name_str,
6767
const char *rustc_since,
6868
tl::optional<unsigned> issue_number = tl::nullopt,
69-
const tl::optional<CompileOptions::Edition> &edition = tl::nullopt,
69+
const tl::optional<Edition> &edition = tl::nullopt,
7070
const char *description = "")
7171
: m_state (state), m_name (name), m_name_str (name_str),
7272
m_rustc_since (rustc_since), m_issue (issue_number), edition (edition),
@@ -78,7 +78,7 @@ class Feature
7878
std::string m_name_str;
7979
std::string m_rustc_since;
8080
tl::optional<unsigned> m_issue;
81-
tl::optional<CompileOptions::Edition> edition;
81+
tl::optional<Edition> edition;
8282
std::string m_description; // TODO: Switch to optional?
8383

8484
static const std::map<std::string, Name> name_hash_map;

gcc/rust/expand/rust-macro-builtins-helpers.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include "rust-macro-invoc-lexer.h"
3030
#include "rust-macro.h"
3131
#include "rust-parse.h"
32-
#include "rust-session-manager.h"
3332
#include "rust-system.h"
3433
#include "rust-token.h"
3534
namespace Rust {

gcc/rust/expand/rust-macro-builtins-include.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "rust-common.h"
2121
#include "rust-macro-builtins.h"
2222
#include "rust-macro-builtins-helpers.h"
23+
#include "rust-session-manager.h"
2324
#include "optional.h"
2425
namespace Rust {
2526
/* Expand builtin macro include_bytes!("filename"), which includes the contents

gcc/rust/expand/rust-macro-builtins-utility.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "rust-ast-builder.h"
2121
#include "rust-macro-builtins.h"
2222
#include "rust-macro-builtins-helpers.h"
23+
#include "rust-session-manager.h"
2324

2425
namespace Rust {
2526

gcc/rust/expand/rust-macro-expand.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "rust-parse.h"
2727
#include "rust-cfg-strip.h"
2828
#include "rust-early-name-resolver.h"
29-
#include "rust-session-manager.h"
3029
#include "rust-proc-macro.h"
3130

3231
namespace Rust {

gcc/rust/lex/rust-lex.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "rust-lex.h"
2222
#include "rust-diagnostics.h"
2323
#include "rust-linemap.h"
24-
#include "rust-session-manager.h"
24+
#include "rust-edition.h"
2525
#include "safe-ctype.h"
2626
#include "cpplib.h"
2727
#include "rust-keyword-values.h"
@@ -277,9 +277,7 @@ Lexer::classify_keyword (const std::string &str)
277277
// https://doc.rust-lang.org/reference/keywords.html#reserved-keywords
278278

279279
// `try` is not a reserved keyword before 2018
280-
if (Session::get_instance ().options.get_edition ()
281-
== CompileOptions::Edition::E2015
282-
&& id == TRY)
280+
if (get_rust_edition () == Edition::E2015 && id == TRY)
283281
return IDENTIFIER;
284282

285283
return id;

gcc/rust/parse/rust-parse-impl.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include "rust-dir-owner.h"
3333
#include "rust-attribute-values.h"
3434
#include "rust-keyword-values.h"
35-
#include "rust-session-manager.h"
35+
#include "rust-edition.h"
3636

3737
#include "optional.h"
3838

@@ -1453,8 +1453,7 @@ Parser<ManagedTokenSource>::parse_async_item (AST::Visibility vis,
14531453
auto offset = (lexer.peek_token ()->get_id () == CONST) ? 1 : 0;
14541454
const_TokenPtr t = lexer.peek_token (offset);
14551455

1456-
if (Session::get_instance ().options.get_edition ()
1457-
== CompileOptions::Edition::E2015)
1456+
if (get_rust_edition () == Edition::E2015)
14581457
{
14591458
add_error (Error (t->get_locus (), ErrorCode::E0670,
14601459
"%<async fn%> is not permitted in Rust 2015"));

gcc/rust/util/rust-edition.cc

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (C) 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+
#include "rust-edition.h"
20+
#include "rust-session-manager.h"
21+
22+
namespace Rust {
23+
24+
Edition
25+
get_rust_edition ()
26+
{
27+
switch (Session::get_instance ().options.get_edition ())
28+
{
29+
case CompileOptions::Edition::E2015:
30+
return Edition::E2015;
31+
case CompileOptions::Edition::E2018:
32+
return Edition::E2018;
33+
case CompileOptions::Edition::E2021:
34+
return Edition::E2021;
35+
default:
36+
rust_unreachable ();
37+
}
38+
}
39+
40+
} // namespace Rust

gcc/rust/util/rust-edition.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (C) 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_EDITION_H
20+
#define RUST_EDITION_H
21+
22+
/*
23+
* This header exists to avoid including rust-session-manager.h
24+
* when we only need information on the selected rust edition
25+
*/
26+
27+
namespace Rust {
28+
29+
enum class Edition
30+
{
31+
E2015,
32+
E2018,
33+
E2021
34+
};
35+
36+
Edition
37+
get_rust_edition ();
38+
39+
} // namespace Rust
40+
41+
#endif // !RUST_EDITION_H

0 commit comments

Comments
 (0)