nr2.0: Adjust resolution of modules#3826
Merged
Merged
Conversation
P-E-P
reviewed
Jun 20, 2025
| void | ||
| TopLevel::visit (AST::Module &module) | ||
| { | ||
| insert_or_error_out (module.get_name (), module, Namespace::Types); |
Member
There was a problem hiding this comment.
Can't wrap my mind around this line, why is it required to removed the module name from type namespace ?
Collaborator
Author
There was a problem hiding this comment.
To change the resolution order to non-modules -> lang items -> modules
Member
There was a problem hiding this comment.
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.
Collaborator
Author
There was a problem hiding this comment.
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)
P-E-P
approved these changes
Jun 30, 2025
This prioritizes resolution in the language prelude over resolution as a module. gcc/rust/ChangeLog: * resolve/rust-forever-stack.hxx (ForeverStack::resolve_path): Resolve final segments which point to modules. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Avoid inserting module names into ribs in the type namespace. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove issue-3315-2.rs. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This prioritizes resolution in the language prelude over resolution as a module.