diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-03-31 15:55:41 +0100 |
---|---|---|
committer | Philip Herron <herron.philip@googlemail.com> | 2021-03-31 18:22:02 +0100 |
commit | 4aa5396e5c61cb1421d1a6c473e297b1528680a8 (patch) | |
tree | 47b3a88d303528e03fcbb48da85d4717e499a160 /gcc | |
parent | d7593fec92166db4d454fdf241b1fde6922d72f2 (diff) | |
download | gcc-4aa5396e5c61cb1421d1a6c473e297b1528680a8.zip gcc-4aa5396e5c61cb1421d1a6c473e297b1528680a8.tar.gz gcc-4aa5396e5c61cb1421d1a6c473e297b1528680a8.tar.bz2 |
Fixed bug TyTy::SubstitutionRef::needs_substitution
When we have Types capable of type substitution it only needs substituted
if it was not already substituted and it actually has substitutions defined
Fixes #311
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-expr.h | 2 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-tyty.cc | 6 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-tyty.h | 5 | ||||
-rw-r--r-- | gcc/testsuite/rust.test/compile/generics12.rs | 16 |
4 files changed, 24 insertions, 5 deletions
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h index dc4aaa7..6c31ab3 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.h +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h @@ -243,7 +243,7 @@ public: if (receiver_tyty->get_kind () == TyTy::TypeKind::ADT) { TyTy::ADTType *adt = static_cast<TyTy::ADTType *> (receiver_tyty); - if (adt->has_substitutions ()) + if (adt->has_substitutions () && fn->needs_substitution ()) { rust_assert (adt->was_substituted ()); lookup diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index 3fad7d9..ae17baf 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -362,7 +362,6 @@ ADTType * ADTType::handle_substitions (SubstitutionArgumentMappings subst_mappings) { if (subst_mappings.size () != get_num_substitutions ()) - { rust_error_at (subst_mappings.get_locus (), "invalid number of generic arguments to generic ADT type"); @@ -565,8 +564,9 @@ FnType::handle_substitions (SubstitutionArgumentMappings subst_mappings) { if (subst_mappings.size () != get_num_substitutions ()) { - rust_error_at (subst_mappings.get_locus (), - "invalid number of generic arguments to generic ADT type"); + rust_error_at ( + subst_mappings.get_locus (), + "invalid number of generic arguments to generic Function type"); return nullptr; } diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index 0cf7d30..3bc06b1 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -527,7 +527,10 @@ public: } } - bool needs_substitution () const { return used_arguments.is_error (); } + bool needs_substitution () const + { + return has_substitutions () && used_arguments.is_error (); + } bool was_substituted () const { return !needs_substitution (); } diff --git a/gcc/testsuite/rust.test/compile/generics12.rs b/gcc/testsuite/rust.test/compile/generics12.rs new file mode 100644 index 0000000..0be8b0e --- /dev/null +++ b/gcc/testsuite/rust.test/compile/generics12.rs @@ -0,0 +1,16 @@ +struct GenericStruct<T>(T, usize); + +impl GenericStruct<i32> { + fn new(a: i32, b: usize) -> Self { + GenericStruct(a, b) + } + + fn get(self) -> i32 { + self.0 + } +} + +fn main() { + let a: GenericStruct<i32> = GenericStruct::<i32>::new(123, 456); + let aa: i32 = a.get(); +} |