Skip to content

Commit

Permalink
attributes: Start handling prelude_import properly
Browse files Browse the repository at this point in the history
This commit adds basic handling for the `#[prelude_import]` attribute,
without doing anything functionality wise.

gcc/rust/ChangeLog:

	* checks/errors/rust-feature-gate.cc (FeatureGate::visit): Add base
	feature gating for `#[feature(prelude_import)]`.
	* checks/errors/rust-feature-gate.h: Likewise.
	* checks/errors/rust-feature.cc (Feature::create): Likewise.
	* checks/errors/rust-feature.h: Likewise.
	* util/rust-attribute-values.h: Add base handling for `#[prelude_import]`
	attribute.
	* util/rust-attributes.cc: Likewise.

gcc/testsuite/ChangeLog:

	* rust/compile/prelude_import.rs: New test.
  • Loading branch information
CohenArthur committed Aug 22, 2024
1 parent 51948d2 commit 06e8b82
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 2 deletions.
8 changes: 8 additions & 0 deletions gcc/rust/checks/errors/rust-feature-gate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,12 @@ FeatureGate::visit (AST::RangePattern &pattern)
"exclusive range pattern syntax is experimental");
}

void
FeatureGate::visit (AST::UseTreeGlob &use)
{
// At the moment, UseTrees do not have outer attributes, but they should. we
// need to eventually gate `#[prelude_import]` on use-trees based on the
// #[feature(prelude_import)]
}

} // namespace Rust
2 changes: 1 addition & 1 deletion gcc/rust/checks/errors/rust-feature-gate.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class FeatureGate : public AST::DefaultASTVisitor
void visit (AST::TypeBoundWhereClauseItem &item) override {}
void visit (AST::Module &module) override {}
void visit (AST::ExternCrate &crate) override {}
void visit (AST::UseTreeGlob &use_tree) override {}
void visit (AST::UseTreeGlob &use_tree) override;
void visit (AST::UseTreeList &use_tree) override {}
void visit (AST::UseTreeRebind &use_tree) override {}
void visit (AST::UseDeclaration &use_decl) override {}
Expand Down
4 changes: 4 additions & 0 deletions gcc/rust/checks/errors/rust-feature.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ Feature::create (Feature::Name name)
return Feature (Feature::Name::EXCLUSIVE_RANGE_PATTERN,
Feature::State::ACTIVE, "exclusive_range_pattern",
"1.11.0", 37854, tl::nullopt, "");
case Feature::Name::PRELUDE_IMPORT:
return Feature (Feature::Name::PRELUDE_IMPORT, Feature::State::ACTIVE,
"prelude_import", "1.0.0", 0, tl::nullopt, "");
default:
rust_unreachable ();
}
Expand All @@ -79,6 +82,7 @@ const std::map<std::string, Feature::Name> Feature::name_hash_map = {
{"dropck_eyepatch", Feature::Name::DROPCK_EYEPATCH},
{"raw_ref_op", Feature::Name::RAW_REF_OP},
{"exclusive_range_pattern", Feature::Name::EXCLUSIVE_RANGE_PATTERN},
{"prelude_import", Feature::Name::PRELUDE_IMPORT},
}; // namespace Rust

tl::optional<Feature::Name>
Expand Down
1 change: 1 addition & 0 deletions gcc/rust/checks/errors/rust-feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Feature
DROPCK_EYEPATCH,
RAW_REF_OP,
EXCLUSIVE_RANGE_PATTERN,
PRELUDE_IMPORT,
};

const std::string &as_string () { return m_name_str; }
Expand Down
1 change: 1 addition & 0 deletions gcc/rust/util/rust-attribute-values.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Attributes
static constexpr auto &RUSTC_CONST_STABLE = "rustc_const_stable";
static constexpr auto &RUSTC_CONST_UNSTABLE = "rustc_const_unstable";
static constexpr auto &MAY_DANGLE = "may_dangle";
static constexpr auto &PRELUDE_IMPORT = "prelude_import";
};
} // namespace Values
} // namespace Rust
Expand Down
3 changes: 2 additions & 1 deletion gcc/rust/util/rust-attributes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ static const BuiltinAttrDefinition __definitions[]
{Attrs::UNSTABLE, STATIC_ANALYSIS},
// assuming we keep these for static analysis
{Attrs::RUSTC_CONST_STABLE, STATIC_ANALYSIS},
{Attrs::RUSTC_CONST_UNSTABLE, STATIC_ANALYSIS}};
{Attrs::RUSTC_CONST_UNSTABLE, STATIC_ANALYSIS},
{Attrs::PRELUDE_IMPORT, NAME_RESOLUTION}};

BuiltinAttributeMappings *
BuiltinAttributeMappings::get ()
Expand Down
12 changes: 12 additions & 0 deletions gcc/testsuite/rust/compile/prelude_import.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#![feature(prelude_import)]

mod core {
mod prelude {
mod v1 {
// hehe
}
}
}

#[prelude_import]
use core::prelude::v1::*;

0 comments on commit 06e8b82

Please sign in to comment.