diff options
author | Philip Herron <herron.philip@googlemail.com> | 2023-03-24 22:17:36 +0000 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 18:21:14 +0100 |
commit | a64474937c5114b3ef31bc4f5111526665b7dde1 (patch) | |
tree | 20a966088b94a2d105421913bb983b7990dbdb52 | |
parent | a2232ff6171ab727fe994c40621831ca409987ae (diff) | |
download | gcc-a64474937c5114b3ef31bc4f5111526665b7dde1.zip gcc-a64474937c5114b3ef31bc4f5111526665b7dde1.tar.gz gcc-a64474937c5114b3ef31bc4f5111526665b7dde1.tar.bz2 |
gccrs: Fix ICE on parsing trait object missing dyn keyword
Trait objects are not required to use the 'dyn' keyword though it is
depreciated in later editions/version of Rustc. This patch handles the case
when we query the type for an HIR::Item which happens to be an HIR::Trait
and return a trait object or error.
Fixes #2037
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): return a TraitObject
gcc/testsuite/ChangeLog:
* rust/compile/issue-2037.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-item.cc | 12 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/issue-2037.rs | 13 |
2 files changed, 24 insertions, 1 deletions
diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.cc b/gcc/rust/typecheck/rust-hir-type-check-item.cc index 571e86c..2116a9b 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-item.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-item.cc @@ -456,7 +456,17 @@ TypeCheckItem::visit (HIR::Module &module) void TypeCheckItem::visit (HIR::Trait &trait) { - TraitResolver::Resolve (trait); + TraitReference *trait_ref = TraitResolver::Resolve (trait); + if (trait_ref->is_error ()) + { + infered = new TyTy::ErrorType (trait.get_mappings ().get_hirid ()); + return; + } + + RustIdent ident{CanonicalPath::create_empty (), trait.get_locus ()}; + infered = new TyTy::DynamicObjectType ( + trait.get_mappings ().get_hirid (), ident, + {TyTy::TypeBoundPredicate (*trait_ref, trait.get_locus ())}); } void diff --git a/gcc/testsuite/rust/compile/issue-2037.rs b/gcc/testsuite/rust/compile/issue-2037.rs new file mode 100644 index 0000000..ec27a0d --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-2037.rs @@ -0,0 +1,13 @@ +trait Foo { + fn bar(&mut self, other: &mut Foo); +} + +struct Baz; + +impl Foo for Baz { + fn bar(&mut self, other: &Foo) {} + // { dg-error "expected" "" { target *-*-* } .-1 } + // { dg-error "method .bar. has an incompatible type for trait .Foo." "" { target *-*-* } .-2 } +} + +fn main() {} |