https://gcc.gnu.org/g:46ff959633430ba511b6610be084b85cf06e8f1d
commit r17-3102-g46ff959633430ba511b6610be084b85cf06e8f1d Author: Enes Cevik <[email protected]> Date: Fri Jul 10 10:42:07 2026 +0300 gccrs: attr: Register rustc_conversion_suggestion This patch registers the 'rustc_conversion_suggestion' attribute. This attribute is needed for compiling the alloc crate, so we register it as a stub and the compiler will emit a warning when it encounters this attribute. gcc/rust/ChangeLog: * checks/errors/rust-builtin-attribute-checker.cc (attribute_checking_handlers): Add rustc_conversion_suggestion attribute to map. (check_valid_attribute_for_item): Add warning for new attribute. * util/rust-attribute-values.h (class Attributes): Add RUSTC_CONVERSION_SUGGESTION constexpr. * util/rust-attributes.cc (__definitions): Add BuiltinAttrDefinition for new attribute. gcc/testsuite/ChangeLog: * rust/compile/rustc_conversion_suggestion.rs: New test. Signed-off-by: Enes Cevik <[email protected]> Diff: --- gcc/rust/checks/errors/rust-builtin-attribute-checker.cc | 14 ++++++++++++++ gcc/rust/util/rust-attribute-values.h | 3 +++ gcc/rust/util/rust-attributes.cc | 3 ++- gcc/testsuite/rust/compile/rustc_conversion_suggestion.rs | 14 ++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/gcc/rust/checks/errors/rust-builtin-attribute-checker.cc b/gcc/rust/checks/errors/rust-builtin-attribute-checker.cc index c1ab0df5ecc9..d8a9bb0fb885 100644 --- a/gcc/rust/checks/errors/rust-builtin-attribute-checker.cc +++ b/gcc/rust/checks/errors/rust-builtin-attribute-checker.cc @@ -389,6 +389,7 @@ const std::unordered_map<std::string, std::function<void (AST::Attribute &)>> {Attrs::RUSTC_ALLOCATOR, handlers::expect_no_input}, {Attrs::RUSTC_ALLOCATOR_NOUNWIND, handlers::expect_no_input}, {Attrs::GLOBAL_ALLOCATOR, handlers::expect_no_input}, + {Attrs::RUSTC_CONVERSION_SUGGESTION, handlers::expect_no_input}, }; tl::optional<std::function<void (AST::Attribute &)>> @@ -450,6 +451,19 @@ check_valid_attribute_for_item (const AST::Attribute &attr, "to static items", attr.get_path ().as_string ().c_str ()); } + else if (attr.get_path () == Values::Attributes::RUSTC_CONVERSION_SUGGESTION) + { + auto attr_path = attr.get_path ().as_string (); + rust_warning_at (attr.get_locus (), 0, + "%<#[%s]%> is not implemented yet and has no effect", + attr_path.c_str ()); + if (item.get_item_kind () != AST::Item::Kind::Function) + { + rust_error_at (item.get_locus (), + "%<#[%s]%> can only be applied to functions", + attr_path.c_str ()); + } + } } BuiltinAttributeChecker::BuiltinAttributeChecker () {} diff --git a/gcc/rust/util/rust-attribute-values.h b/gcc/rust/util/rust-attribute-values.h index 4f8860747ea8..3ab91d35f9cc 100644 --- a/gcc/rust/util/rust-attribute-values.h +++ b/gcc/rust/util/rust-attribute-values.h @@ -115,6 +115,9 @@ public: static constexpr auto &RUSTC_ALLOCATOR = "rustc_allocator"; static constexpr auto &RUSTC_ALLOCATOR_NOUNWIND = "rustc_allocator_nounwind"; + + static constexpr auto &RUSTC_CONVERSION_SUGGESTION + = "rustc_conversion_suggestion"; }; } // namespace Values } // namespace Rust diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc index 97f9edeea8b6..2ae917fdb9f4 100644 --- a/gcc/rust/util/rust-attributes.cc +++ b/gcc/rust/util/rust-attributes.cc @@ -98,7 +98,8 @@ static const BuiltinAttrDefinition __definitions[] {Attrs::NEEDS_ALLOCATOR, CODE_GENERATION}, {Attrs::RUSTC_ALLOCATOR, CODE_GENERATION}, {Attrs::RUSTC_ALLOCATOR_NOUNWIND, CODE_GENERATION}, - {Attrs::GLOBAL_ALLOCATOR, CODE_GENERATION}}; + {Attrs::GLOBAL_ALLOCATOR, CODE_GENERATION}, + {Attrs::RUSTC_CONVERSION_SUGGESTION, TYPE_CHECK}}; static const std::set<std::string> __outer_attributes = {Attrs::INLINE, diff --git a/gcc/testsuite/rust/compile/rustc_conversion_suggestion.rs b/gcc/testsuite/rust/compile/rustc_conversion_suggestion.rs new file mode 100644 index 000000000000..e601ccf068ae --- /dev/null +++ b/gcc/testsuite/rust/compile/rustc_conversion_suggestion.rs @@ -0,0 +1,14 @@ +#![feature(no_core, rustc_attrs)] +#![no_core] + +#[rustc_conversion_suggestion] // { dg-warning "...rustc_conversion_suggestion.. is not implemented yet and has no effect" } +pub fn to_string() {} + +#[rustc_conversion_suggestion] // { dg-warning "...rustc_conversion_suggestion.. is not implemented yet and has no effect" } +const TO_STRING : i32 = 0; // { dg-error "...rustc_conversion_suggestion.. can only be applied to functions" } + +#[rustc_conversion_suggestion] // { dg-warning "...rustc_conversion_suggestion.. is not implemented yet and has no effect" } +static TO_STRING2 : i32 = 0; // { dg-error "...rustc_conversion_suggestion.. can only be applied to functions" } + +#[rustc_conversion_suggestion] // { dg-warning "...rustc_conversion_suggestion.. is not implemented yet and has no effect" } +struct TO_STRING3; // { dg-error "...rustc_conversion_suggestion.. can only be applied to functions" }
