https://gcc.gnu.org/g:4c7524197b7167ecce1d82be7d81a0002db00cec
commit r17-6658-g4c7524197b7167ecce1d82be7d81a0002db00cec Author: Enes Cevik <[email protected]> Date: Sat Nov 14 19:14:53 2026 +0300 gccrs: Improve feature gate error formatting 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]> Diff: --- .../checks/errors/feature/rust-feature-gate.cc | 28 ++++++++-------------- gcc/testsuite/rust/compile/feature_rust_attri0.rs | 2 +- gcc/testsuite/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 43a8a6199c30..bea7e1306e0e 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 71d320977ee2..2a2ec52bfe3d 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 58d5fe3879c5..57de20d214d1 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 {}
