Skip to content

Commit 9ee5b51

Browse files
committed
extern-types: Lower to HIR::ExternalTypeItem properly
gcc/rust/ChangeLog: * hir/rust-ast-lower-extern.h: Lower to HIR::ExternalTypeItem nodes. * hir/tree/rust-hir-item.h (class ExternalTypeItem): Create private visibility by default as extern types have no visibility - add a comment about the correctness of this.
1 parent 8e3c34a commit 9ee5b51

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

gcc/rust/hir/rust-ast-lower-extern.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "rust-ast-lower-base.h"
2323
#include "rust-ast-lower-type.h"
2424
#include "rust-ast-lower.h"
25+
#include "rust-hir-full-decls.h"
2526

2627
namespace Rust {
2728
namespace HIR {
@@ -116,7 +117,13 @@ class ASTLoweringExternItem : public ASTLoweringBase
116117

117118
void visit (AST::ExternalTypeItem &type) override
118119
{
119-
rust_sorry_at (type.get_locus (), "extern types are not implemented yet");
120+
auto crate_num = mappings->get_current_crate ();
121+
Analysis::NodeMapping mapping (crate_num, type.get_node_id (),
122+
mappings->get_next_hir_id (crate_num),
123+
mappings->get_next_localdef_id (crate_num));
124+
125+
translated = new HIR::ExternalTypeItem (mapping, type.get_identifier (),
126+
type.get_locus ());
120127
}
121128

122129
private:

gcc/rust/hir/tree/rust-hir-item.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -3152,16 +3152,20 @@ class ExternalFunctionItem : public ExternalItem
31523152

31533153
class ExternalTypeItem : public ExternalItem
31543154
{
3155+
public:
31553156
ExternalTypeItem (Analysis::NodeMapping mappings, Identifier item_name,
3156-
Visibility vis, AST::AttrVec outer_attrs, location_t locus)
3157+
location_t locus)
31573158
: ExternalItem (std::move (mappings), std::move (item_name),
3158-
std::move (vis), std::move (outer_attrs), locus)
3159+
Visibility (Visibility::PRIVATE),
3160+
/* FIXME: Is that correct? */
3161+
{}, locus)
31593162
{}
31603163

31613164
ExternalTypeItem (ExternalTypeItem const &other) : ExternalItem (other) {}
31623165

31633166
ExternalTypeItem (ExternalTypeItem &&other) = default;
31643167
ExternalTypeItem &operator= (ExternalTypeItem &&other) = default;
3168+
ExternalTypeItem &operator= (ExternalTypeItem const &other) = default;
31653169

31663170
std::string as_string () const override;
31673171

@@ -3171,6 +3175,8 @@ class ExternalTypeItem : public ExternalItem
31713175
ExternKind get_extern_kind () override { return ExternKind::Type; }
31723176

31733177
protected:
3178+
/* Use covariance to implement clone function as returning this object
3179+
* rather than base */
31743180
ExternalTypeItem *clone_external_item_impl () const override
31753181
{
31763182
return new ExternalTypeItem (*this);

0 commit comments

Comments
 (0)