]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Non-allowed default type paramters
authorMuhammad Mahad <mahadtxt@gmail.com>
Mon, 14 Aug 2023 12:09:25 +0000 (17:09 +0500)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 18:00:32 +0000 (19:00 +0100)
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>
gcc/rust/hir/rust-ast-lower-item.cc
gcc/testsuite/rust/compile/generics10.rs

index 6eaf75ffd0b4bcd7d2962a0f9fd66bc5a6840b6f..6d91c23e8d23c009989f59ae2349c5a82de8286c 100644 (file)
@@ -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;
index a734fa8a19786da45c9efff65116478441a5bd91..c66a08f7e169edbd6051ca89c04bdf862777410b 100644 (file)
@@ -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)
     }