From: Enes Cevik <[email protected]>

Use rust_inform to mention the tracking issue and suggest adding crate
attribute.

gcc/rust/ChangeLog:

        * checks/errors/feature/rust-feature-gate.cc (FeatureGate::gate):
        Improve error format.

gcc/testsuite/ChangeLog:

        * rust/compile/feature_rust_attri0.rs: Correct expected error.
        * rust/compile/lang_feature_gate.rs: Correct expected error.

Signed-off-by: Enes Cevik <[email protected]>

Tested on x86_64-pc-linux-gnu.

---
 .../errors/feature/rust-feature-gate.cc       | 28 +++++++------------
 .../rust/compile/feature_rust_attri0.rs       |  2 +-
 .../rust/compile/lang_feature_gate.rs         |  3 +-
 3 files changed, 13 insertions(+), 20 deletions(-)

diff --git a/gcc/rust/checks/errors/feature/rust-feature-gate.cc 
b/gcc/rust/checks/errors/feature/rust-feature-gate.cc
index 43a8a6199c3..bea7e1306e0 100644
--- a/gcc/rust/checks/errors/feature/rust-feature-gate.cc
+++ b/gcc/rust/checks/errors/feature/rust-feature-gate.cc
@@ -83,25 +83,17 @@ FeatureGate::gate (Feature::Name name, location_t loc,
   if (!features.valid_lang_features.count (name))
     {
       auto &feature = Feature::lookup (name);
+
+      rust_error_at (loc, ErrorCode::E0658, "%s", error_msg.c_str ());
+
+      // Mention the issue, if it is defined
       if (auto issue = feature.issue ())
-       {
-         auto issue_number = issue.value ();
-         const char *fmt_str
-           = "%s. see issue %u "
-             "<https://github.com/rust-lang/rust/issues/%u> for more "
-             "information. add `#![feature(%s)]` to the crate attributes to "
-             "enable.";
-         rust_error_at (loc, ErrorCode::E0658, fmt_str, error_msg.c_str (),
-                        issue_number, issue_number,
-                        feature.as_string ().c_str ());
-       }
-      else
-       {
-         const char *fmt_str
-           = "%s. add `#![feature(%s)]` to the crate attributes to enable.";
-         rust_error_at (loc, ErrorCode::E0658, fmt_str, error_msg.c_str (),
-                        feature.as_string ().c_str ());
-       }
+       rust_inform (loc, "see issue #%u <%s%u> for more information", *issue,
+                    "https://github.com/rust-lang/rust/issues/";, *issue);
+
+      rust_inform (loc,
+                  "add %<#![feature(%s)]%> to the crate attributes to enable",
+                  feature.as_string ().c_str ());
 
       return GateResult::Gated;
     }
diff --git a/gcc/testsuite/rust/compile/feature_rust_attri0.rs 
b/gcc/testsuite/rust/compile/feature_rust_attri0.rs
index 71d320977ee..2a2ec52bfe3 100644
--- a/gcc/testsuite/rust/compile/feature_rust_attri0.rs
+++ b/gcc/testsuite/rust/compile/feature_rust_attri0.rs
@@ -5,7 +5,7 @@ extern "C" {
     fn printf(s: *const i8, ...);
 }
 
-#[rustc_builtin_macro] //{ dg-error "internal implementation detail. " "" { 
target *-*-* }  }
+#[rustc_builtin_macro] //{ dg-error "internal implementation detail" }
 macro_rules! line {
     () => {{}};
 }
diff --git a/gcc/testsuite/rust/compile/lang_feature_gate.rs 
b/gcc/testsuite/rust/compile/lang_feature_gate.rs
index 58d5fe3879c..57de20d214d 100644
--- a/gcc/testsuite/rust/compile/lang_feature_gate.rs
+++ b/gcc/testsuite/rust/compile/lang_feature_gate.rs
@@ -1,5 +1,6 @@
 #![feature(no_core)]
 #![no_core]
 
-#[lang = "sized"] // { dg-error "lang items are subject to change. add 
.#!.feature.lang_items... to the crate attributes to enable" }
+#[lang = "sized"] // { dg-error "lang items are subject to change" }
+// { dg-message "add .#!.feature.lang_items... to the crate attributes to 
enable" "" { target *-*-* } .-1 }
 pub trait Sized {}
-- 
2.55.0

Reply via email to