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
6 changes: 6 additions & 0 deletions gcc/rust/resolve/rust-name-resolution-context.h
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,12 @@ class NameResolutionContext
tl::optional<NodeId> prelude;

private:
template <Namespace N>
bool
should_search_prelude (const typename ForeverStack<N>::Node *current_node,
const typename ForeverStack<N>::SegIterator &iterator,
const std::vector<ResolutionPath::Segment> &segments);

/**
* Resolve a path to its definition
*
Expand Down
23 changes: 22 additions & 1 deletion gcc/rust/resolve/rust-name-resolution-context.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@
namespace Rust {
namespace Resolver2_0 {

template <Namespace N>
bool
NameResolutionContext::should_search_prelude (
const typename ForeverStack<N>::Node *current_node,
const typename ForeverStack<N>::SegIterator &iterator,
const std::vector<ResolutionPath::Segment> &segments)
{
// Check whether the current_node is a root node
if (current_node->is_root ())
return true;

// Check whether we're at the start of a module (we can't travel elsewhere
// from the start of a module)
if (is_start (iterator, segments)
&& current_node->rib.kind == Rib::Kind::Module)
return true;

return false;
}

template <Namespace N>
tl::optional<Rib::Definition>
NameResolutionContext::resolve_path (
Expand Down Expand Up @@ -383,7 +403,8 @@ NameResolutionContext::resolve_segments (
}
}

if (current_node->is_root () && !searched_prelude)
if (!searched_prelude
&& should_search_prelude<N> (current_node, iterator, segments))
{
searched_prelude = true;
current_node = &stack.lang_prelude;
Expand Down
11 changes: 11 additions & 0 deletions gcc/testsuite/rust/compile/name_resolution28.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#![feature(no_core, lang_items)]
#![no_core]

pub mod lateresolve {
#![lang = "f32"]
impl f32 {
pub const RADIX: u32 = 2;
}

pub const _: u32 = f32::RADIX;
}
Loading