|
1 | 1 | use std::str::FromStr;
|
2 | 2 |
|
3 |
| -use rustc_ast::attr::list_contains_name; |
4 | 3 | use rustc_ast::expand::autodiff_attrs::{
|
5 | 4 | AutoDiffAttrs, DiffActivity, DiffMode, valid_input_activity, valid_ret_activity,
|
6 | 5 | };
|
@@ -386,24 +385,20 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
|
386 | 385 | let segments =
|
387 | 386 | set.path.segments.iter().map(|x| x.ident.name).collect::<Vec<_>>();
|
388 | 387 | match segments.as_slice() {
|
389 |
| - [sym::arm, sym::a32] | [sym::arm, sym::t32] => { |
390 |
| - if !tcx.sess.target.has_thumb_interworking { |
391 |
| - struct_span_code_err!( |
392 |
| - tcx.dcx(), |
393 |
| - attr.span, |
394 |
| - E0779, |
395 |
| - "target does not support `#[instruction_set]`" |
396 |
| - ) |
397 |
| - .emit(); |
398 |
| - None |
399 |
| - } else if segments[1] == sym::a32 { |
400 |
| - Some(InstructionSetAttr::ArmA32) |
401 |
| - } else if segments[1] == sym::t32 { |
402 |
| - Some(InstructionSetAttr::ArmT32) |
403 |
| - } else { |
404 |
| - unreachable!() |
405 |
| - } |
| 388 | + [sym::arm, sym::a32 | sym::t32] |
| 389 | + if !tcx.sess.target.has_thumb_interworking => |
| 390 | + { |
| 391 | + struct_span_code_err!( |
| 392 | + tcx.dcx(), |
| 393 | + attr.span, |
| 394 | + E0779, |
| 395 | + "target does not support `#[instruction_set]`" |
| 396 | + ) |
| 397 | + .emit(); |
| 398 | + None |
406 | 399 | }
|
| 400 | + [sym::arm, sym::a32] => Some(InstructionSetAttr::ArmA32), |
| 401 | + [sym::arm, sym::t32] => Some(InstructionSetAttr::ArmT32), |
407 | 402 | _ => {
|
408 | 403 | struct_span_code_err!(
|
409 | 404 | tcx.dcx(),
|
@@ -545,25 +540,27 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
|
545 | 540 | }
|
546 | 541 |
|
547 | 542 | if attr.is_word() {
|
548 |
| - InlineAttr::Hint |
549 |
| - } else if let Some(ref items) = attr.meta_item_list() { |
550 |
| - inline_span = Some(attr.span); |
551 |
| - if items.len() != 1 { |
552 |
| - struct_span_code_err!(tcx.dcx(), attr.span, E0534, "expected one argument").emit(); |
553 |
| - InlineAttr::None |
554 |
| - } else if list_contains_name(items, sym::always) { |
555 |
| - InlineAttr::Always |
556 |
| - } else if list_contains_name(items, sym::never) { |
557 |
| - InlineAttr::Never |
558 |
| - } else { |
559 |
| - struct_span_code_err!(tcx.dcx(), items[0].span(), E0535, "invalid argument") |
560 |
| - .with_help("valid inline arguments are `always` and `never`") |
561 |
| - .emit(); |
| 543 | + return InlineAttr::Hint; |
| 544 | + } |
| 545 | + let Some(ref items) = attr.meta_item_list() else { |
| 546 | + return ia; |
| 547 | + }; |
562 | 548 |
|
563 |
| - InlineAttr::None |
564 |
| - } |
| 549 | + inline_span = Some(attr.span); |
| 550 | + let [item] = &items[..] else { |
| 551 | + struct_span_code_err!(tcx.dcx(), attr.span, E0534, "expected one argument").emit(); |
| 552 | + return InlineAttr::None; |
| 553 | + }; |
| 554 | + if item.has_name(sym::always) { |
| 555 | + InlineAttr::Always |
| 556 | + } else if item.has_name(sym::never) { |
| 557 | + InlineAttr::Never |
565 | 558 | } else {
|
566 |
| - ia |
| 559 | + struct_span_code_err!(tcx.dcx(), item.span(), E0535, "invalid argument") |
| 560 | + .with_help("valid inline arguments are `always` and `never`") |
| 561 | + .emit(); |
| 562 | + |
| 563 | + InlineAttr::None |
567 | 564 | }
|
568 | 565 | });
|
569 | 566 | codegen_fn_attrs.inline = attrs.iter().fold(codegen_fn_attrs.inline, |ia, attr| {
|
@@ -595,23 +592,25 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
|
595 | 592 | let err = |sp, s| struct_span_code_err!(tcx.dcx(), sp, E0722, "{}", s).emit();
|
596 | 593 | if attr.is_word() {
|
597 | 594 | err(attr.span, "expected one argument");
|
598 |
| - ia |
599 |
| - } else if let Some(ref items) = attr.meta_item_list() { |
600 |
| - inline_span = Some(attr.span); |
601 |
| - if items.len() != 1 { |
602 |
| - err(attr.span, "expected one argument"); |
603 |
| - OptimizeAttr::Default |
604 |
| - } else if list_contains_name(items, sym::size) { |
605 |
| - OptimizeAttr::Size |
606 |
| - } else if list_contains_name(items, sym::speed) { |
607 |
| - OptimizeAttr::Speed |
608 |
| - } else if list_contains_name(items, sym::none) { |
609 |
| - OptimizeAttr::DoNotOptimize |
610 |
| - } else { |
611 |
| - err(items[0].span(), "invalid argument"); |
612 |
| - OptimizeAttr::Default |
613 |
| - } |
| 595 | + return ia; |
| 596 | + } |
| 597 | + let Some(ref items) = attr.meta_item_list() else { |
| 598 | + return OptimizeAttr::Default; |
| 599 | + }; |
| 600 | + |
| 601 | + inline_span = Some(attr.span); |
| 602 | + let [item] = &items[..] else { |
| 603 | + err(attr.span, "expected one argument"); |
| 604 | + return OptimizeAttr::Default; |
| 605 | + }; |
| 606 | + if item.has_name(sym::size) { |
| 607 | + OptimizeAttr::Size |
| 608 | + } else if item.has_name(sym::speed) { |
| 609 | + OptimizeAttr::Speed |
| 610 | + } else if item.has_name(sym::none) { |
| 611 | + OptimizeAttr::DoNotOptimize |
614 | 612 | } else {
|
| 613 | + err(item.span(), "invalid argument"); |
615 | 614 | OptimizeAttr::Default
|
616 | 615 | }
|
617 | 616 | });
|
@@ -763,18 +762,13 @@ fn should_inherit_track_caller(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
|
763 | 762 |
|
764 | 763 | fn check_link_ordinal(tcx: TyCtxt<'_>, attr: &hir::Attribute) -> Option<u16> {
|
765 | 764 | use rustc_ast::{LitIntType, LitKind, MetaItemLit};
|
766 |
| - let meta_item_list = attr.meta_item_list(); |
767 |
| - let meta_item_list = meta_item_list.as_deref(); |
768 |
| - let sole_meta_list = match meta_item_list { |
769 |
| - Some([item]) => item.lit(), |
770 |
| - Some(_) => { |
771 |
| - tcx.dcx().emit_err(errors::InvalidLinkOrdinalNargs { span: attr.span }); |
772 |
| - return None; |
773 |
| - } |
774 |
| - _ => None, |
| 765 | + let meta_item_list = attr.meta_item_list()?; |
| 766 | + let [sole_meta_list] = &meta_item_list[..] else { |
| 767 | + tcx.dcx().emit_err(errors::InvalidLinkOrdinalNargs { span: attr.span }); |
| 768 | + return None; |
775 | 769 | };
|
776 | 770 | if let Some(MetaItemLit { kind: LitKind::Int(ordinal, LitIntType::Unsuffixed), .. }) =
|
777 |
| - sole_meta_list |
| 771 | + sole_meta_list.lit() |
778 | 772 | {
|
779 | 773 | // According to the table at
|
780 | 774 | // https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#import-header, the
|
|
0 commit comments