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

gccrs: Fix ICE when typechecking non-trait item when we expect one #3187

Merged
merged 1 commit into from
Oct 2, 2024

Conversation

philberty
Copy link
Member

We just had an assertion here for this case where we expect a trait. This changes the assertion into error handling producing the correct error code with fixit suggestion like rustc.

test.rs:7:6: error: Expected a trait found ‘Foo’ [E0404]
    7 | impl Foo for Bar {}
      |      ^~~
      |      not a trait
test.rs:10:11: error: Expected a trait found ‘Foo’ [E0404]
   10 | fn baz<T: Foo>(t: T) {}
      |           ^~~
      |           not a trait

Fixes #2499

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_path_to_trait): use error handling instead of assertion
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): reuse trait reference
* typecheck/rust-hir-type-check-item.h: update prototype

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-2499.rs: New test.

We just had an assertion here for this case where we expect a trait.
This changes the assertion into error handling producing the correct
error code with fixit suggestion like rustc.

Fixes #2499

gcc/rust/ChangeLog:

	* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_path_to_trait):
	use error handling instead of assertion
	* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): reuse trait reference
	* typecheck/rust-hir-type-check-item.h: update prototype

gcc/testsuite/ChangeLog:

	* rust/compile/nr2/exclude: nr2 cant handle this
	* rust/compile/issue-2499.rs: New test.

Signed-off-by: Philip Herron <[email protected]>
@philberty philberty added this pull request to the merge queue Oct 2, 2024
Merged via the queue into master with commit af0f0e3 Oct 2, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

ICE when non-trait type was used in trait position
1 participant