From 308fd792af6c220b505515e6d40e7ba0f9820cf5 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Wed, 2 Oct 2024 15:47:33 +0100 Subject: gccrs: Fix ICE when typechecking non-trait item when we expect one 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 --- gcc/testsuite/rust/compile/issue-2499.rs | 11 +++++++++++ gcc/testsuite/rust/compile/nr2/exclude | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/rust/compile/issue-2499.rs (limited to 'gcc/testsuite/rust/compile') diff --git a/gcc/testsuite/rust/compile/issue-2499.rs b/gcc/testsuite/rust/compile/issue-2499.rs new file mode 100644 index 0000000..662d58f --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-2499.rs @@ -0,0 +1,11 @@ +#[lang = "sized"] +pub trait Sized {} + +struct Foo; +struct Bar; + +impl Foo for Bar {} +// { dg-error "Expected a trait found .Foo. .E0404." "" { target *-*-* } .-1 } + +fn baz(t: T) {} +// { dg-error "Expected a trait found .Foo. .E0404." "" { target *-*-* } .-1 } diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude index e792462..dec3bdd 100644 --- a/gcc/testsuite/rust/compile/nr2/exclude +++ b/gcc/testsuite/rust/compile/nr2/exclude @@ -254,4 +254,5 @@ issue-3139-2.rs issue-3139-3.rs issue-3036.rs issue-2951.rs -issue-2203.rs \ No newline at end of file +issue-2203.rs +issue-2499.rs \ No newline at end of file -- cgit v1.1