public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Arthur Cohen <cohenarthur@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r14-7931] gccrs: Non-allowed default type paramters
Date: Tue, 16 Jan 2024 18:08:22 +0000 (GMT)	[thread overview]
Message-ID: <20240116180822.0ACE03857C43@sourceware.org> (raw)

https://gcc.gnu.org/g:dd343c42d25d2ab2cc1549c5cf608d7d6b3f0589

commit r14-7931-gdd343c42d25d2ab2cc1549c5cf608d7d6b3f0589
Author: Muhammad Mahad <mahadtxt@gmail.com>
Date:   Mon Aug 14 17:09:25 2023 +0500

    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>

Diff:
---
 gcc/rust/hir/rust-ast-lower-item.cc      | 24 +++++++++++++++++-------
 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 6eaf75ffd0b..6d91c23e8d2 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 a734fa8a197..c66a08f7e16 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)
     }

                 reply	other threads:[~2024-01-16 18:08 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240116180822.0ACE03857C43@sourceware.org \
    --to=cohenarthur@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).