@@ -364,46 +364,67 @@ HIRCompileBase::handle_inline_attribute_on_fndecl (tree fndecl,
364
364
}
365
365
366
366
const AST::AttrInput &input = attr.get_attr_input ();
367
- bool is_token_tree
368
- = input.get_attr_input_type () == AST::AttrInput::AttrInputType::TOKEN_TREE;
369
- rust_assert (is_token_tree);
370
- const auto &option = static_cast <const AST::DelimTokenTree &> (input);
371
- AST::AttrInputMetaItemContainer *meta_item = option.parse_to_meta_item ();
372
- if (meta_item->get_items ().size () != 1 )
367
+ auto input_type = input.get_attr_input_type ();
368
+
369
+ if (input_type == AST::AttrInput::AttrInputType::LITERAL)
373
370
{
371
+ // Handle #[inline = "..."] syntax
374
372
rich_location rich_locus (line_table, attr.get_locus ());
375
- rich_locus.add_fixit_replace (" expected one argument" );
376
- rust_error_at (rich_locus, ErrorCode::E0534 ,
377
- " invalid number of arguments" );
373
+ rich_locus.add_fixit_replace (" #[inline(always)] or #[inline(never)]" );
374
+ rust_error_at (rich_locus, ErrorCode::E0535 ,
375
+ " invalid syntax, %<inline%> attribute does not accept "
376
+ " value with %<=%>, use parentheses instead: "
377
+ " %<#[inline(always)]%> or %<#[inline(never)]%>" );
378
378
return ;
379
379
}
380
+ else if (input_type == AST::AttrInput::AttrInputType::TOKEN_TREE)
381
+ {
382
+ const auto &option = static_cast <const AST::DelimTokenTree &> (input);
383
+ AST::AttrInputMetaItemContainer *meta_item = option.parse_to_meta_item ();
384
+ if (meta_item->get_items ().size () != 1 )
385
+ {
386
+ rich_location rich_locus (line_table, attr.get_locus ());
387
+ rich_locus.add_fixit_replace (" expected one argument" );
388
+ rust_error_at (rich_locus, ErrorCode::E0534 ,
389
+ " invalid number of arguments" );
390
+ return ;
391
+ }
380
392
381
- const std::string inline_option
382
- = meta_item->get_items ().at (0 )->as_string ();
393
+ const std::string inline_option
394
+ = meta_item->get_items ().at (0 )->as_string ();
383
395
384
- // we only care about NEVER and ALWAYS else its an error
385
- bool is_always = inline_option.compare (" always" ) == 0 ;
386
- bool is_never = inline_option.compare (" never" ) == 0 ;
396
+ // we only care about NEVER and ALWAYS else its an error
397
+ bool is_always = inline_option.compare (" always" ) == 0 ;
398
+ bool is_never = inline_option.compare (" never" ) == 0 ;
387
399
388
- // #[inline(never)]
389
- if (is_never)
390
- {
391
- DECL_UNINLINABLE (fndecl) = 1 ;
392
- }
393
- // #[inline(always)]
394
- else if (is_always)
395
- {
396
- DECL_DECLARED_INLINE_P (fndecl) = 1 ;
397
- DECL_ATTRIBUTES (fndecl) = tree_cons (get_identifier (" always_inline" ),
398
- NULL , DECL_ATTRIBUTES (fndecl));
400
+ // #[inline(never)]
401
+ if (is_never)
402
+ {
403
+ DECL_UNINLINABLE (fndecl) = 1 ;
404
+ }
405
+ // #[inline(always)]
406
+ else if (is_always)
407
+ {
408
+ DECL_DECLARED_INLINE_P (fndecl) = 1 ;
409
+ DECL_ATTRIBUTES (fndecl)
410
+ = tree_cons (get_identifier (" always_inline" ), NULL ,
411
+ DECL_ATTRIBUTES (fndecl));
412
+ }
413
+ else
414
+ {
415
+ rich_location rich_locus (line_table, attr.get_locus ());
416
+ rich_locus.add_fixit_replace (" unknown inline option" );
417
+ rust_error_at (rich_locus, ErrorCode::E0535 ,
418
+ " invalid argument, %<inline%> attribute only accepts "
419
+ " %<always%> or %<never%>" );
420
+ }
399
421
}
400
422
else
401
423
{
424
+ // Handle unexpected input type
402
425
rich_location rich_locus (line_table, attr.get_locus ());
403
- rich_locus.add_fixit_replace (" unknown inline option" );
404
- rust_error_at (rich_locus, ErrorCode::E0535 ,
405
- " invalid argument, %<inline%> attribute only accepts "
406
- " %<always%> or %<never%>" );
426
+ rust_error_at (rich_locus,
427
+ " unexpected attribute input type for inline attribute" );
407
428
}
408
429
}
409
430
0 commit comments