diff options
author | Muhammad Mahad <mahadtxt@gmail.com> | 2023-08-14 17:09:25 +0500 |
---|---|---|
committer | CohenArthur <arthur.cohen@embecosm.com> | 2023-08-17 13:33:38 +0000 |
commit | 8ac2e43fb27170442d26e03271ba8b8775f1eb84 (patch) | |
tree | 121a57ca556e0c63bee75653d63b1e68a5bacb47 | |
parent | d4bf5e3f23bfbbfc3b42ca523fc6f46cae064808 (diff) | |
download | gcc-8ac2e43fb27170442d26e03271ba8b8775f1eb84.zip gcc-8ac2e43fb27170442d26e03271ba8b8775f1eb84.tar.gz gcc-8ac2e43fb27170442d26e03271ba8b8775f1eb84.tar.bz2 |
gccrs: Non-allowed default type paramters
gcc/rust/ChangeLog:
* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit):
Added more helpful error message.
gcc/testsuite/ChangeLog:
* rust/compile/generics10.rs: for dejagnu.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
-rw-r--r-- | gcc/rust/hir/rust-ast-lower-item.cc | 24 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/generics10.rs | 2 |
2 files changed, 18 insertions, 8 deletions
diff --git a/gcc/rust/hir/rust-ast-lower-item.cc b/gcc/rust/hir/rust-ast-lower-item.cc index 3c24a3e..d94383b 100644 --- a/gcc/rust/hir/rust-ast-lower-item.cc +++ b/gcc/rust/hir/rust-ast-lower-item.cc @@ -499,10 +499,15 @@ ASTLoweringItem::visit (AST::InherentImpl &impl_block) if (t.has_type ()) { - // see https://github.com/rust-lang/rust/issues/36887 - rust_error_at ( + rich_location rich_locus (line_table, t.get_locus ()); + rich_locus.add_fixit_replace ( t.get_locus (), - "defaults for type parameters are not allowed here"); + "for more information, see issue #36887 " + "<https://github.com/rust-lang/rust/issues/36887>"); + rust_error_at (rich_locus, + "defaults for type parameters are only " + "allowed in %<struct%>, %<enum%>, %<type%>, " + "or %<trait%> definitions"); } } break; @@ -645,10 +650,15 @@ ASTLoweringItem::visit (AST::TraitImpl &impl_block) 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"); + rich_location rich_locus (line_table, t.get_locus ()); + rich_locus.add_fixit_replace ( + t.get_locus (), "for more information, see issue #36887 " + "<https://github.com/rust-lang/rust/" + "issues/36887>"); + rust_error_at (rich_locus, + "defaults for type parameters are only " + "allowed in %<struct%>, %<enum%>, %<type%>, " + "or %<trait%> definitions"); } } break; diff --git a/gcc/testsuite/rust/compile/generics10.rs b/gcc/testsuite/rust/compile/generics10.rs index a734fa8..c66a08f 100644 --- a/gcc/testsuite/rust/compile/generics10.rs +++ b/gcc/testsuite/rust/compile/generics10.rs @@ -1,6 +1,6 @@ struct Foo<A, B>(A, B); -impl<X = i32> Foo<X, f32> { // { dg-error "defaults for type parameters are not allowed here" } +impl<X = i32> Foo<X, f32> { // { dg-error "defaults for type parameters are only allowed in .struct., .enum., .type., or .trait. definitions" } fn new(a: X, b: f32) -> Self { Self(a, b) } |