Rust-GCC / Rust-GCC/gccrs

Issues when resolving public unloaded modules

Open
#2,986 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug name resolution
Dominant language
C++
Stars
2.9k
Forks
231
Avg merge
19h 55m
Merged PRs (30d)
67

Description

With the following directory structure

test.rs
foo/
    mod.rs
    bar.rs

and the following files:

// test.rs
pub mod foo;

use foo::bar::f;

fn main() {
    f()
}
// foo/mod.rs
pub mod bar;
pub fn f() {}

we fail to name resolve modules and compile the code, whereas rustc does not show any errors.

arthur@platypus ~/G/r/gccrs (master)> build/gcc/crab1 test.rs
test.rs:1:5: error: no candidate found for module foo
    1 | pub mod foo;
      |     ^~~

Analyzing compilation unit

Time variable                                   usr           sys          wall           GGC
 TOTAL                              :   0.00          0.00          0.00          150k
Extra diagnostic checks enabled; compiler may run slowly.
Configure with --enable-checking=release to disable checks.

with name resolution 2.0:

arthur@platypus ~/G/r/gccrs (master) [1]> build/gcc/crab1 test.rs -frust-name-resolution-2.0
test.rs:3:10: error: failed to resolve path segment ‘bar’ [E0433]
    3 | use foo::bar::f;
      |          ^~~
test.rs:3:10: error: failed to resolve path segment ‘bar’ [E0433]
test.rs:3:10: error: failed to resolve path segment ‘bar’ [E0433]
test.rs:3:15: error: unresolved import ‘foo::bar::f’ [E0433]
    3 | use foo::bar::f;
      |               ^
crab1: internal compiler error: in visit, at rust/resolve/rust-late-name-resolver-2.0.cc:205
0x259c2e0 Rust::Resolver2_0::Late::visit(Rust::AST::PathInExpression&)
	/home/arthur/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/resolve/rust-late-name-resolver-2.0.cc:205
0x233fd3d Rust::AST::PathInExpression::accept_vis(Rust::AST::ASTVisitor&)
	/home/arthur/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/ast/rust-path.cc:189
0x236c8ed void Rust::AST::DefaultASTVisitor::visit<Rust::AST::Expr>(Rust::AST::Expr&)
	../../gcc/rust/ast/rust-ast-visitor.h:396
0x2367c92 Rust::AST::DefaultASTVisitor::visit(Rust::AST::CallExpr&)
	/home/arthur/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/ast/rust-ast-visitor.cc:411
0x225efd0 Rust::AST::CallExpr::accept_vis(Rust::AST::ASTVisitor&)
	/home/arthur/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/ast/rust-ast.cc:4479
0x2581d4d Rust::Resolver2_0::DefaultResolver::visit(Rust::AST::BlockExpr&)::$_0::operator()() const
	/home/arthur/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/resolve/rust-default-resolver.cc:38
0x2581c74 void std::__invoke_impl<void, Rust::Resolver2_0::DefaultResolver::visit(Rust::AST::BlockExpr&)::$_0&>(std::__invoke_other, Rust::Resolver2_0::DefaultResolver::visit(Rust::AST::BlockExpr&)::$_0&)
	/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../include/c++/13.2.1/bits/invoke.h:61
0x2581c24 std::enable_if<is_invocable_r_v<void, Rust::Resolver2_0::DefaultResolver::visit(Rust::AST::BlockExpr&)::$_0&>, void>::type std::__invoke_r<void, Rust::Resolver2_0::DefaultResolver::visit(Rust::AST::BlockExpr&)::$_0&>(Rust::Resolver2_0::DefaultResolver::visit(Rust::AST::BlockExpr&)::$_0&)
	/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../include/c++/13.2.1/bits/invoke.h:111
0x2581b4c std::_Function_handler<void (), Rust::Resolver2_0::DefaultResolver::visit(Rust::AST::BlockExpr&)::$_0>::_M_invoke(std::_Any_data const&)
	/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../include/c++/13.2.1/bits/std_function.h:290
0x257ad24 std::function<void ()>::operator()() const
	/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../include/c++/13.2.1/bits/std_function.h:591
0x2579a86 Rust::Resolver2_0::NameResolutionContext::scoped(Rust::Resolver2_0::Rib, unsigned int, std::function<void ()>, tl::optional<Rust::Identifier>)
	/home/arthur/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/resolve/rust-name-resolution-context.cc:97
0x257fb8e Rust::Resolver2_0::DefaultResolver::visit(Rust::AST::BlockExpr&)
	/home/arthur/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/resolve/rust-default-resolver.cc:41
0x225f090 Rust::AST::BlockExpr::accept_vis(Rust::AST::ASTVisitor&)
	/home/arthur/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/ast/rust-ast.cc:4503
0x25826a7 Rust::Resolver2_0::DefaultResolver::visit(Rust::AST::Function&)::$_0::operator()() const
	/home/arthur/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/resolve/rust-default-resolver.cc:86
0x25824a4 void std::__invoke_impl<void, Rust::Resolver2_0::DefaultResolver::visit(Rust::AST::Function&)::$_0&>(std::__invoke_other, Rust::Resolver2_0::DefaultResolver::visit(Rust::AST::Function&)::$_0&)
	/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../include/c++/13.2.1/bits/invoke.h:61
0x2582454 std::enable_if<is_invocable_r_v<void, Rust::Resolver2_0::DefaultResolver::visit(Rust::AST::Function&)::$_0&>, void>::type std::__invoke_r<void, Rust::Resolver2_0::DefaultResolver::visit(Rust::AST::Function&)::$_0&>(Rust::Resolver2_0::DefaultResolver::visit(Rust::AST::Function&)::$_0&)
	/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../include/c++/13.2.1/bits/invoke.h:111
0x258237c std::_Function_handler<void (), Rust::Resolver2_0::DefaultResolver::visit(Rust::AST::Function&)::$_0>::_M_invoke(std::_Any_data const&)
	/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../include/c++/13.2.1/bits/std_function.h:290
0x257ad24 std::function<void ()>::operator()() const
	/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../include/c++/13.2.1/bits/std_function.h:591
0x2579a86 Rust::Resolver2_0::NameResolutionContext::scoped(Rust::Resolver2_0::Rib, unsigned int, std::function<void ()>, tl::optional<Rust::Identifier>)
	/home/arthur/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/resolve/rust-name-resolution-context.cc:97
0x257ff14 Rust::Resolver2_0::DefaultResolver::visit(Rust::AST::Function&)
	/home/arthur/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/resolve/rust-default-resolver.cc:89
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the test.rs module layout and reproduce the failure with and without -frust-name-resolution-2.0. Read rust-late-name-resolver-2.0.cc, rust-default-resolver.cc, and rust-name-resolution-context.cc around the reported stack frames. Done means the sample resolves foo::bar::f and compiles without unresolved-module errors or an internal compiler error.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.