Skip to content
Open
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/resolve/rust-late-name-resolver-2.0.cc
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,14 @@ resolve_type_path_like (NameResolutionContext &ctx, bool block_big_self,
"declared identifiers");
}

if (Analysis::Mappings::get ().is_module (resolved->get_node_id ()))
{
rust_error_at (type.get_locus (), ErrorCode::E0573,
"expected type, found module %qs",
unwrap_segment_error_string (type).c_str ());
return;
}

ctx.map_usage (Usage (type.get_node_id ()),
Definition (resolved->get_node_id ()));
}
Expand Down
8 changes: 6 additions & 2 deletions gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,16 @@ TopLevel::go (AST::Crate &crate)
void
TopLevel::visit (AST::Module &module)
{
DefaultResolver::visit (module);

if (Analysis::Mappings::get ().lookup_glob_container (module.get_node_id ())
== tl::nullopt)
Analysis::Mappings::get ().insert_glob_container (module.get_node_id (),
&module);

insert_or_error_out (module.get_name (), module, Namespace::Types);

Analysis::Mappings::get ().insert_module_id (module.get_node_id ());

DefaultResolver::visit (module);
}

void
Expand Down
12 changes: 12 additions & 0 deletions gcc/rust/util/rust-hir-map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,18 @@ Mappings::insert_glob_container (NodeId id, AST::GlobContainer *container)
glob_containers[id] = container;
}

void
Mappings::insert_module_id (NodeId id)
{
module_ids.insert (id);
}

bool
Mappings::is_module (NodeId id)
{
return module_ids.find (id) != module_ids.end ();
}

tl::optional<AST::GlobContainer *>
Mappings::lookup_glob_container (NodeId id)
{
Expand Down
7 changes: 7 additions & 0 deletions gcc/rust/util/rust-hir-map.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ class Mappings

void insert_glob_container (NodeId, AST::GlobContainer *);
tl::optional<AST::GlobContainer *> lookup_glob_container (NodeId id);

void insert_module_id (NodeId);
bool is_module (NodeId id);

void insert_module_child (NodeId module, NodeId child);
tl::optional<std::vector<NodeId> &> lookup_module_children (NodeId module);

Expand Down Expand Up @@ -438,10 +442,13 @@ class Mappings
// Module tree maps

// Maps each module's node id to a list of its children
// TODO: I think these are only used by the old resolved and can be removed
std::map<NodeId, std::vector<NodeId>> module_child_map;
std::map<NodeId, std::vector<Resolver::CanonicalPath>> module_child_items;
std::map<NodeId, NodeId> child_to_parent_module_map;

std::map<NodeId, AST::GlobContainer *> glob_containers;
std::set<NodeId> module_ids;

// AST mappings
std::map<NodeId, AST::Item *> ast_item_mappings;
Expand Down
5 changes: 5 additions & 0 deletions gcc/testsuite/rust/compile/mod_in_types_ns.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mod foo {
mod bar {}

struct bar; // { dg-error "defined multiple times" }
}
5 changes: 5 additions & 0 deletions gcc/testsuite/rust/compile/mod_in_types_ns2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mod foo {
mod bar {}

fn baz() -> bar {} // { dg-error "expected type, found module" }
}
Loading