rust/rust-compile-resolve-path.o \
rust/rust-macro-expand.o \
rust/rust-cfg-strip.o \
+ rust/rust-early-cfg-strip.o \
rust/rust-expand-visitor.o \
rust/rust-ast-builder.o \
rust/rust-derive.o \
namespace Rust {
+void expand_cfg_attrs (AST::AttrVec &attrs);
+
// forward declare
struct ExpansionCfg;
--- /dev/null
+// Copyright (C) 2026 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include "rust-early-cfg-strip.h"
+#include "rust-cfg-strip.h"
+
+namespace Rust {
+
+void
+EarlyCfgStrip::go (AST::Crate &crate)
+{
+ visit (crate);
+}
+
+void
+EarlyCfgStrip::visit (AST::Crate &crate)
+{
+ expand_cfg_attrs (crate.inner_attrs);
+
+ AST::DefaultASTVisitor::visit (crate);
+}
+
+} // namespace Rust
--- /dev/null
+// Copyright (C) 2026 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#ifndef RUST_EARLY_CFG_STRIP_H
+#define RUST_EARLY_CFG_STRIP_H
+
+#include "rust-ast-visitor.h"
+
+namespace Rust {
+
+/**
+ * Some parts cannot be stripped during the expansion passes
+ */
+class EarlyCfgStrip : AST::DefaultASTVisitor
+{
+public:
+ using DefaultASTVisitor::visit;
+
+ void go (AST::Crate &crate);
+
+ void visit (AST::Crate &crate) override;
+};
+
+} // namespace Rust
+
+#endif
#include "rust-early-name-resolver-2.0.h"
#include "rust-late-name-resolver-2.0.h"
#include "rust-resolve-builtins.h"
+#include "rust-early-cfg-strip.h"
#include "rust-cfg-strip.h"
#include "rust-expand-visitor.h"
#include "rust-unicode.h"
Analysis::AttributeChecker ().go (parsed_crate);
- if (!has_attribute (parsed_crate, std::string (Values::Attributes::NO_CORE)))
+ EarlyCfgStrip ().go (parsed_crate);
+
+ auto parsed_crate_features
+ = Features::FeatureCollector{}.collect (parsed_crate);
+
+ // Do not inject core if some errors were emitted
+ if (!saw_errors ()
+ && !has_attribute (parsed_crate,
+ std::string (Values::Attributes::NO_CORE)))
{
parsed_crate.inject_extern_crate ("core");
}
// feature gating
if (last_step == CompileOptions::CompileStep::FeatureGating)
return;
- auto parsed_crate_features
- = Features::FeatureCollector{}.collect (parsed_crate);
+
FeatureGate (parsed_crate_features).check (parsed_crate);
if (last_step == CompileOptions::CompileStep::NameResolution)