]> git.ipfire.org Git - thirdparty/gcc.git/commit
gccrs: Always emit the error highest in the type hierarchy
authorPhilip Herron <herron.philip@googlemail.com>
Tue, 20 May 2025 17:44:57 +0000 (18:44 +0100)
committerPhilip Herron <philip.herron@embecosm.com>
Tue, 27 May 2025 09:27:15 +0000 (09:27 +0000)
commitc77c3494f82da01c85a294a5f9c3a0c5496f8572
treecf9dcd5e07173b53eef5bd937350c9b9e49efe2b
parentba32a6e460813a94e5f129dbc0e259c300690385
gccrs: Always emit the error highest in the type hierarchy

The unify code was a bit dumb here where we always set emit_error to false for any
subtypes for example in comparing tuples we always emitted the whole tuple didnt
match the other tuple but really its much better to say expected bool got i32 because
the element types didn't match.

gcc/rust/ChangeLog:

* typecheck/rust-coercion.cc (TypeCoercionRules::coerce_unsized): dont emit error here
* typecheck/rust-unify.cc (UnifyRules::resolve_subtype): new helper to handle emit error
(UnifyRules::expect_adt): call resolve_subtype
(UnifyRules::expect_reference): likewise
(UnifyRules::expect_pointer): likewise
(UnifyRules::expect_array): likewise
(UnifyRules::expect_slice): likewise
(UnifyRules::expect_fndef): likewise
(UnifyRules::expect_fnptr): likewise
(UnifyRules::expect_tuple): likewise
(UnifyRules::expect_closure): likewise
(UnifyRules::expect_opaque): likeiwse
* typecheck/rust-unify.h: add new helper to header

gcc/testsuite/ChangeLog:

* rust/compile/traits9.rs: update errors
* rust/compile/unify-errors1.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/typecheck/rust-coercion.cc
gcc/rust/typecheck/rust-unify.cc
gcc/rust/typecheck/rust-unify.h
gcc/testsuite/rust/compile/traits9.rs
gcc/testsuite/rust/compile/unify-errors1.rs [new file with mode: 0644]