From: Philip Herron <[email protected]>
gcc/rust/ChangeLog:
* typecheck/rust-tyty-subst.cc: we can optionally apply inherited
arguments
gcc/testsuite/ChangeLog:
* rust/compile/gat2.rs: New test.
Signed-off-by: Philip Herron <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.
Commit on github:
https://github.com/Rust-GCC/gccrs/commit/30f1c92361a9d743d98b58774d4c2835cdd5635b
The commit has NOT been mentioned in any issue.
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4594
gcc/rust/typecheck/rust-tyty-subst.cc | 12 +++++++---
gcc/testsuite/rust/compile/gat2.rs | 33 +++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 3 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/gat2.rs
diff --git a/gcc/rust/typecheck/rust-tyty-subst.cc
b/gcc/rust/typecheck/rust-tyty-subst.cc
index f3873b8e6..6ee2a60df 100644
--- a/gcc/rust/typecheck/rust-tyty-subst.cc
+++ b/gcc/rust/typecheck/rust-tyty-subst.cc
@@ -706,10 +706,16 @@ SubstitutionRef::get_mappings_from_generic_args (
}
}
- // for inherited arguments
- size_t offs = used_arguments.size ();
+ // check if we need to use inherited arguments or nothing
+ size_t offs = 0;
size_t total_arguments
- = args.get_type_args ().size () + args.get_const_args ().size () + offs;
+ = args.get_type_args ().size () + args.get_const_args ().size ();
+ if (total_arguments < substitutions.size ())
+ {
+ offs = used_arguments.size ();
+ total_arguments += offs;
+ }
+
if (total_arguments > substitutions.size ())
{
rich_location r (line_table, args.get_locus ());
diff --git a/gcc/testsuite/rust/compile/gat2.rs
b/gcc/testsuite/rust/compile/gat2.rs
new file mode 100644
index 000000000..2aead485c
--- /dev/null
+++ b/gcc/testsuite/rust/compile/gat2.rs
@@ -0,0 +1,33 @@
+#![feature(lang_items)]
+
+#[lang = "sized"]
+trait Sized {}
+
+pub enum Option<T> {
+ Some(T),
+ None,
+}
+
+trait Foo {
+ type Bar<T>;
+
+ fn foo<T>(self) -> Self::Bar<T>;
+}
+
+impl Foo for i32 {
+ type Bar<T> = Option<T>;
+
+ fn foo<T>(self) -> Self::Bar<T> {
+ Option::None
+ }
+}
+
+pub fn main() -> i32 {
+ let a = 15;
+ let res: Option<i8> = a.foo::<i8>();
+
+ match res {
+ Option::None => 0,
+ Option::Some(_) => 1,
+ }
+}
base-commit: 568ff0de54e269986ac3caa47ce409ca6bce95af
--
2.54.0