Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle new lang items: Option::None, Option::Some, IntoIterator::into_iter, Iterator::next #3318

Merged
merged 2 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions gcc/rust/ast/rust-collect-lang-items.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,13 @@ CollectLangItems::visit (AST::TraitItemType &item)
DefaultASTVisitor::visit (item);
}

void
CollectLangItems::visit (AST::Function &item)
{
maybe_add_lang_item (item);

DefaultASTVisitor::visit (item);
}

} // namespace AST
} // namespace Rust
1 change: 1 addition & 0 deletions gcc/rust/ast/rust-collect-lang-items.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class CollectLangItems : public DefaultASTVisitor

void visit (AST::Trait &item) override;
void visit (AST::TraitItemType &item) override;
void visit (AST::Function &item) override;

private:
template <typename T> void maybe_add_lang_item (const T &item);
Expand Down
6 changes: 6 additions & 0 deletions gcc/rust/util/rust-lang-item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ const BiMap<std::string, LangItem::Kind> Rust::LangItem::lang_items = {{
{"str", Kind::STR},
{"f32_runtime", Kind::F32_RUNTIME},
{"f64_runtime", Kind::F64_RUNTIME},

{"Some", Kind::OPTION_SOME},
{"None", Kind::OPTION_NONE},

{"into_iter", Kind::INTOITER_INTOITER},
{"next", Kind::ITERATOR_NEXT},
}};

tl::optional<LangItem::Kind>
Expand Down
9 changes: 9 additions & 0 deletions gcc/rust/util/rust-lang-item.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ namespace Rust {
class LangItem
{
public:
// FIXME: We should clean up that enum to make it more inline with the list of
// lang-items in Rust 1.49
// https://github.com/rust-lang/rust/blob/1.49.0/compiler/rustc_hir/src/lang_items.rs
enum class Kind
{
// https://github.com/rust-lang/rust/blob/master/library/core/src/ops/arith.rs
Expand Down Expand Up @@ -116,6 +119,12 @@ class LangItem
STR,
F32_RUNTIME,
F64_RUNTIME,

OPTION_SOME,
OPTION_NONE,

INTOITER_INTOITER,
ITERATOR_NEXT,
};

static const BiMap<std::string, Kind> lang_items;
Expand Down
Loading