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