Skip to content

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

Merged
philberty merged 1 commit into
masterfrom
phil/trait-ice
Oct 2, 2024
Merged

gccrs: Fix ICE when typechecking non-trait item when we expect one#3187
philberty merged 1 commit into
masterfrom
phil/trait-ice

Conversation

@philberty

Copy link
Copy Markdown
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 <herron.philip@googlemail.com>
@philberty philberty requested review from CohenArthur and P-E-P October 2, 2024 14:54
@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
@philberty philberty deleted the phil/trait-ice branch November 1, 2024 16:22
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