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 <herron.philip@googlemail.com>
}
}
- // 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 ());
--- /dev/null
+#![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,
+ }
+}