|
32 | 32 | #include "rust-type-util.h"
|
33 | 33 | #include "rust-compile-implitem.h"
|
34 | 34 | #include "rust-attribute-values.h"
|
| 35 | +#include "rust-attributes.h" |
35 | 36 | #include "rust-immutable-name-resolution-context.h"
|
36 | 37 |
|
37 | 38 | #include "fold-const.h"
|
@@ -251,25 +252,21 @@ void
|
251 | 252 | HIRCompileBase::handle_link_section_attribute_on_fndecl (
|
252 | 253 | tree fndecl, const AST::Attribute &attr)
|
253 | 254 | {
|
254 |
| - if (!attr.has_attr_input ()) |
| 255 | + auto msg_str = Analysis::Attributes::extract_string_literal (attr); |
| 256 | + |
| 257 | + if (!msg_str.has_value ()) |
255 | 258 | {
|
256 | 259 | rust_error_at (attr.get_locus (),
|
257 |
| - "%<link_section%> expects exactly one argment"); |
| 260 | + "malformed %<link_section%> attribute input"); |
258 | 261 | return;
|
259 | 262 | }
|
260 | 263 |
|
261 |
| - rust_assert (attr.get_attr_input ().get_attr_input_type () |
262 |
| - == AST::AttrInput::AttrInputType::LITERAL); |
263 |
| - |
264 |
| - auto &literal = static_cast<AST::AttrInputLiteral &> (attr.get_attr_input ()); |
265 |
| - const auto &msg_str = literal.get_literal ().as_string (); |
266 |
| - |
267 | 264 | if (decl_section_name (fndecl))
|
268 | 265 | {
|
269 | 266 | rust_warning_at (attr.get_locus (), 0, "section name redefined");
|
270 | 267 | }
|
271 | 268 |
|
272 |
| - set_decl_section_name (fndecl, msg_str.c_str ()); |
| 269 | + set_decl_section_name (fndecl, msg_str->c_str ()); |
273 | 270 | }
|
274 | 271 |
|
275 | 272 | void
|
@@ -416,13 +413,10 @@ HIRCompileBase::handle_must_use_attribute_on_fndecl (tree fndecl,
|
416 | 413 |
|
417 | 414 | if (attr.has_attr_input ())
|
418 | 415 | {
|
419 |
| - rust_assert (attr.get_attr_input ().get_attr_input_type () |
420 |
| - == AST::AttrInput::AttrInputType::LITERAL); |
| 416 | + auto msg_str = Analysis::Attributes::extract_string_literal (attr); |
| 417 | + rust_assert (msg_str.has_value ()); |
421 | 418 |
|
422 |
| - auto &literal |
423 |
| - = static_cast<AST::AttrInputLiteral &> (attr.get_attr_input ()); |
424 |
| - const auto &msg_str = literal.get_literal ().as_string (); |
425 |
| - tree message = build_string (msg_str.size (), msg_str.c_str ()); |
| 419 | + tree message = build_string (msg_str->size (), msg_str->c_str ()); |
426 | 420 |
|
427 | 421 | value = tree_cons (nodiscard, message, NULL_TREE);
|
428 | 422 | }
|
|
0 commit comments