Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inherit Implementation of type outside current crate - Internal Compile Error #2423

Closed
MahadMuhammad opened this issue Jul 13, 2023 · 3 comments · Fixed by #3280
Closed

Inherit Implementation of type outside current crate - Internal Compile Error #2423

MahadMuhammad opened this issue Jul 13, 2023 · 3 comments · Fixed by #3280
Assignees
Labels

Comments

@MahadMuhammad
Copy link
Contributor

Inherit Implementation of type outside current crate:

  • You can view the same on godbolt here & here

I tried this code from E0116:

#![allow(unused)]
fn main() {
impl Vec<u8> { } // error
}
  • Also, this
#![allow(unused)]
fn main() {
type Bytes = Vec<u8>;

impl Bytes { } // error, same as above
}

I Expected to see this happen:

  • GIve error like rustc.
  • i.e.,
    • error[E0116]: cannot define inherent impl for a type outside of the crate where the type is defined

Instead this happened:

  • First, it gives failed to resolve TypePath: x in this scope
  • Then, internal compiler error.
➜  gccrs-build gcc/crab1 ../mahad-testsuite/E0116A.rs 
../mahad-testsuite/E0116A.rs:3:6: error: failed to resolve TypePath: Vec<Type: u8> in this scope
    3 | impl Vec<u8> { } // error
      |      ^~~
crab1: internal compiler error: in visit, at rust/resolve/rust-ast-resolve-item.cc:574
0x7b8ce4 Rust::Resolver::ResolveItem::visit(Rust::AST::InherentImpl&)
	../../gccrs/gcc/rust/resolve/rust-ast-resolve-item.cc:574
0xbb2167 Rust::Resolver::ResolveItem::go(Rust::AST::Item*, Rust::Resolver::CanonicalPath const&, Rust::Resolver::CanonicalPath const&)
	../../gccrs/gcc/rust/resolve/rust-ast-resolve-item.cc:212
0xbc2bf8 Rust::Resolver::ResolveStmt::go(Rust::AST::Stmt*, Rust::Resolver::CanonicalPath const&, Rust::Resolver::CanonicalPath const&, Rust::Resolver::CanonicalPath const&)
	../../gccrs/gcc/rust/resolve/rust-ast-resolve-stmt.h:43
0xbc2bf8 Rust::Resolver::ResolveStmt::go(Rust::AST::Stmt*, Rust::Resolver::CanonicalPath const&, Rust::Resolver::CanonicalPath const&, Rust::Resolver::CanonicalPath const&)
	../../gccrs/gcc/rust/resolve/rust-ast-resolve-stmt.h:35
0xbc2bf8 Rust::Resolver::ResolveExpr::visit(Rust::AST::BlockExpr&)
	../../gccrs/gcc/rust/resolve/rust-ast-resolve-expr.cc:316
0xbc4aaf Rust::Resolver::ResolveExpr::go(Rust::AST::Expr*, Rust::Resolver::CanonicalPath const&, Rust::Resolver::CanonicalPath const&, bool)
	../../gccrs/gcc/rust/resolve/rust-ast-resolve-expr.cc:36
0xbb64f6 Rust::Resolver::ResolveItem::visit(Rust::AST::Function&)
	../../gccrs/gcc/rust/resolve/rust-ast-resolve-item.cc:540
0xbb2167 Rust::Resolver::ResolveItem::go(Rust::AST::Item*, Rust::Resolver::CanonicalPath const&, Rust::Resolver::CanonicalPath const&)
	../../gccrs/gcc/rust/resolve/rust-ast-resolve-item.cc:212
0xba68fa Rust::Resolver::NameResolution::go(Rust::AST::Crate&)
	../../gccrs/gcc/rust/resolve/rust-ast-resolve.cc:108
0xa6a839 Rust::Session::compile_crate(char const*)
	../../gccrs/gcc/rust/rust-session-manager.cc:595
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.
  • For Second Example:
➜  gccrs-build gcc/crab1 ../mahad-testsuite/E0116B.rs
../mahad-testsuite/E0116B.rs:5:6: error: failed to resolve TypePath: Bytes in this scope
    5 | impl Bytes { } // error, same as above
      |      ^~~~~
crab1: internal compiler error: in visit, at rust/resolve/rust-ast-resolve-item.cc:574
0x7b8ce4 Rust::Resolver::ResolveItem::visit(Rust::AST::InherentImpl&)
	../../gccrs/gcc/rust/resolve/rust-ast-resolve-item.cc:574
0xbb2167 Rust::Resolver::ResolveItem::go(Rust::AST::Item*, Rust::Resolver::CanonicalPath const&, Rust::Resolver::CanonicalPath const&)
	../../gccrs/gcc/rust/resolve/rust-ast-resolve-item.cc:212
0xbc2bf8 Rust::Resolver::ResolveStmt::go(Rust::AST::Stmt*, Rust::Resolver::CanonicalPath const&, Rust::Resolver::CanonicalPath const&, Rust::Resolver::CanonicalPath const&)
	../../gccrs/gcc/rust/resolve/rust-ast-resolve-stmt.h:43
0xbc2bf8 Rust::Resolver::ResolveStmt::go(Rust::AST::Stmt*, Rust::Resolver::CanonicalPath const&, Rust::Resolver::CanonicalPath const&, Rust::Resolver::CanonicalPath const&)
	../../gccrs/gcc/rust/resolve/rust-ast-resolve-stmt.h:35
0xbc2bf8 Rust::Resolver::ResolveExpr::visit(Rust::AST::BlockExpr&)
	../../gccrs/gcc/rust/resolve/rust-ast-resolve-expr.cc:316
0xbc4aaf Rust::Resolver::ResolveExpr::go(Rust::AST::Expr*, Rust::Resolver::CanonicalPath const&, Rust::Resolver::CanonicalPath const&, bool)
	../../gccrs/gcc/rust/resolve/rust-ast-resolve-expr.cc:36
0xbb64f6 Rust::Resolver::ResolveItem::visit(Rust::AST::Function&)
	../../gccrs/gcc/rust/resolve/rust-ast-resolve-item.cc:540
0xbb2167 Rust::Resolver::ResolveItem::go(Rust::AST::Item*, Rust::Resolver::CanonicalPath const&, Rust::Resolver::CanonicalPath const&)
	../../gccrs/gcc/rust/resolve/rust-ast-resolve-item.cc:212
0xba68fa Rust::Resolver::NameResolution::go(Rust::AST::Crate&)
	../../gccrs/gcc/rust/resolve/rust-ast-resolve.cc:108
0xa6a839 Rust::Session::compile_crate(char const*)
	../../gccrs/gcc/rust/rust-session-manager.cc:595
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.

Meta

  • What version of Rust GCC were you using, git sha b75357f.
  • Godbolt version:
    • gccrs (Compiler-Explorer-Build-gcc-a06cec181de6398231e0662c1ed83d905ad6d1d9-binutils-2.40) 13.0.1 20230417 (experimental)

@CohenArthur
Copy link
Member

The Vec type is not available in gccrs because we do not currently link against Rust's standard library.

@philberty
Copy link
Member

Marking as good first PR as this should be a simple fix to remove the assertion and do error handling to continue resolving

@MahadMuhammad MahadMuhammad moved this from Internal Compile Error to Todo in Error Code Support & Improving User Errors Aug 9, 2023
@Harshit933
Copy link

Harshit933 commented Jan 3, 2024

Hello, I would like to work on this issue

@philberty philberty assigned philberty and unassigned Harshit933 Nov 15, 2024
@philberty philberty added this to the Remaining typecheck issues milestone Dec 2, 2024
philberty added a commit that referenced this issue Dec 2, 2024
This was a handy debug assertion but only works for valid rust code. This
needs to handle the case where the type is not resolved which is a valid
case.

Fixes #2423

gcc/rust/ChangeLog:

	* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): remove assertions

gcc/testsuite/ChangeLog:

	* rust/compile/nr2/exclude: nr2 can't handle this
	* rust/compile/issue-2423.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
github-merge-queue bot pushed a commit that referenced this issue Dec 2, 2024
This was a handy debug assertion but only works for valid rust code. This
needs to handle the case where the type is not resolved which is a valid
case.

Fixes #2423

gcc/rust/ChangeLog:

	* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): remove assertions

gcc/testsuite/ChangeLog:

	* rust/compile/nr2/exclude: nr2 can't handle this
	* rust/compile/issue-2423.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
@github-project-automation github-project-automation bot moved this from Todo to Done in libcore 1.49 Dec 2, 2024
tschwinge pushed a commit that referenced this issue Dec 4, 2024
This was a handy debug assertion but only works for valid rust code. This
needs to handle the case where the type is not resolved which is a valid
case.

Fixes #2423

gcc/rust/ChangeLog:

	* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): remove assertions

gcc/testsuite/ChangeLog:

	* rust/compile/nr2/exclude: nr2 can't handle this
	* rust/compile/issue-2423.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Kamiinarii78 pushed a commit to Kamiinarii78/gccrs that referenced this issue Dec 12, 2024
This was a handy debug assertion but only works for valid rust code. This
needs to handle the case where the type is not resolved which is a valid
case.

Fixes Rust-GCC#2423

gcc/rust/ChangeLog:

	* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): remove assertions

gcc/testsuite/ChangeLog:

	* rust/compile/nr2/exclude: nr2 can't handle this
	* rust/compile/issue-2423.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
matthewjasper pushed a commit to matthewjasper/gccrs that referenced this issue Dec 21, 2024
This was a handy debug assertion but only works for valid rust code. This
needs to handle the case where the type is not resolved which is a valid
case.

Fixes Rust-GCC#2423

gcc/rust/ChangeLog:

	* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): remove assertions

gcc/testsuite/ChangeLog:

	* rust/compile/nr2/exclude: nr2 can't handle this
	* rust/compile/issue-2423.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants