Skip to content
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
42 changes: 41 additions & 1 deletion gcc/rust/resolve/rust-forever-stack.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ ForeverStack<N>::resolve_path (
if (!res)
res = get_lang_prelude (seg.as_string ());

if (!res && N == Namespace::Types)
if (N == Namespace::Types && !res)
{
if (seg.is_crate_path_seg ())
{
Expand Down Expand Up @@ -719,6 +719,26 @@ ForeverStack<N>::resolve_path (
// TODO: does NonShadowable matter?
return Rib::Definition::NonShadowable (id);
}
else
{
// HACK: check for a module after we check the language prelude
for (auto &kv :
find_closest_module (starting_point.get ()).children)
{
auto &link = kv.first;

if (link.path.map_or (
[&seg] (Identifier path) {
auto &path_str = path.as_string ();
return path_str == seg.as_string ();
},
false))
{
insert_segment_resolution (outer_seg, kv.second.id);
return Rib::Definition::NonShadowable (kv.second.id);
}
}
}
}

if (res && !res->is_ambiguous ())
Expand Down Expand Up @@ -751,6 +771,26 @@ ForeverStack<N>::resolve_path (
if (!res)
res = get_lang_prelude (seg_name);

if (N == Namespace::Types && !res)
{
// HACK: check for a module after we check the language prelude
for (auto &kv : final_node.children)
{
auto &link = kv.first;

if (link.path.map_or (
[&seg_name] (Identifier path) {
auto &path_str = path.as_string ();
return path_str == seg_name;
},
false))
{
insert_segment_resolution (segments.back (), kv.second.id);
return Rib::Definition::NonShadowable (kv.second.id);
}
}
}

if (res && !res->is_ambiguous ())
insert_segment_resolution (segments.back (), res->get_node_id ());

Expand Down
2 changes: 0 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 @@ -101,8 +101,6 @@ TopLevel::go (AST::Crate &crate)
void
TopLevel::visit (AST::Module &module)
{
insert_or_error_out (module.get_name (), module, Namespace::Types);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't wrap my mind around this line, why is it required to removed the module name from type namespace ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To change the resolution order to non-modules -> lang items -> modules

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel we're doing something wrong somewhere, rustc resolves modules first during top level and from what I heard struggles with their implementation. I'll need some time to think about that.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm seeing

            // In `a(::assoc_item)*` `a` cannot be a module. If `a` does resolve to a module we
            // don't report an error right away, but try to fallback to a primitive type.
            // So, we are still able to successfully resolve something like
            //
            // use std::u8; // bring module u8 in scope
            // fn f() -> u8 { // OK, resolves to primitive u8, not to std::u8
            //     u8::max_value() // OK, resolves to associated function <u8>::max_value,
            //                     // not to non-existent std::u8::max_value
            // }
            //
            // Such behavior is required for backward compatibility.
            // The same fallback is used when `a` resolves to nothing.

in the rustc source code (rustc_resolve/src/late.rs, 1.49)


// Parse the module's items if they haven't been expanded and the file
// should be parsed (i.e isn't hidden behind an untrue or impossible cfg
// directive
Expand Down
1 change: 0 additions & 1 deletion gcc/testsuite/rust/compile/nr2/exclude
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
issue-3315-2.rs
# please don't delete the trailing newline
Loading