diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-04-30 16:22:15 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2021-04-30 17:10:00 +0100 |
commit | 2216cab0c9f694016d6cc220cfa8f5c23ba5f465 (patch) | |
tree | 6ac4d268325bf75dfc747c12ff18122826a5c151 /gcc | |
parent | feaafdfecf4aa0575768deaa837323c3d86f678f (diff) | |
download | gcc-2216cab0c9f694016d6cc220cfa8f5c23ba5f465.zip gcc-2216cab0c9f694016d6cc220cfa8f5c23ba5f465.tar.gz gcc-2216cab0c9f694016d6cc220cfa8f5c23ba5f465.tar.bz2 |
Defaults to type params are not allowed here
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/hir/rust-ast-lower-item.h | 23 | ||||
-rw-r--r-- | gcc/testsuite/rust.test/xfail_compile/generics10.rs | 12 |
2 files changed, 35 insertions, 0 deletions
diff --git a/gcc/rust/hir/rust-ast-lower-item.h b/gcc/rust/hir/rust-ast-lower-item.h index 18ead3c..fe0b791 100644 --- a/gcc/rust/hir/rust-ast-lower-item.h +++ b/gcc/rust/hir/rust-ast-lower-item.h @@ -349,6 +349,29 @@ public: { generic_params = lower_generic_params (impl_block.get_generic_params ()); + + for (auto &generic_param : generic_params) + { + switch (generic_param->get_kind ()) + { + case HIR::GenericParam::GenericKind::TYPE: { + const HIR::TypeParam &t + = static_cast<const HIR::TypeParam &> (*generic_param); + + if (t.has_type ()) + { + // see https://github.com/rust-lang/rust/issues/36887 + rust_error_at ( + t.get_locus (), + "defaults for type parameters are not allowed here"); + } + } + break; + + default: + break; + } + } } HIR::Type *trait_type diff --git a/gcc/testsuite/rust.test/xfail_compile/generics10.rs b/gcc/testsuite/rust.test/xfail_compile/generics10.rs new file mode 100644 index 0000000..a734fa8 --- /dev/null +++ b/gcc/testsuite/rust.test/xfail_compile/generics10.rs @@ -0,0 +1,12 @@ +struct Foo<A, B>(A, B); + +impl<X = i32> Foo<X, f32> { // { dg-error "defaults for type parameters are not allowed here" } + fn new(a: X, b: f32) -> Self { + Self(a, b) + } +} + +fn main() { + let a; + a = Foo::new(123, 456f32); +} |