Skip to content

Commit 02d423c

Browse files
committed
codegen_attrs: force inlining takes precedence
1 parent f86169a commit 02d423c

1 file changed

Lines changed: 33 additions & 28 deletions

File tree

‎compiler/rustc_codegen_ssa/src/codegen_attrs.rs‎

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -523,41 +523,46 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
523523
mixed_export_name_no_mangle_lint_state.lint_if_mixed(tcx);
524524

525525
codegen_fn_attrs.inline = attrs.iter().fold(InlineAttr::None, |ia, attr| {
526-
if attr.has_name(sym::inline){
527-
if attr.is_word(){
528-
InlineAttr::Hint
529-
}elseifletSome(ref items) = attr.meta_item_list(){
530-
inline_span = Some(attr.span);
531-
if items.len() != 1{
532-
struct_span_code_err!(tcx.dcx(), attr.span,E0534,"expected one argument").emit();
533-
InlineAttr::None
534-
}elseiflist_contains_name(items, sym::always){
535-
InlineAttr::Always
536-
}elseiflist_contains_name(items, sym::never){
537-
InlineAttr::Never
538-
}else{
539-
struct_span_code_err!(tcx.dcx(), items[0].span(),E0535,"invalid argument")
540-
.with_help("valid inline arguments are `always` and `never`")
541-
.emit();
526+
if !attr.has_name(sym::inline){
527+
return ia;
528+
}
542529

543-
InlineAttr::None
544-
}
545-
}else{
546-
ia
547-
}
548-
}elseif attr.has_name(sym::rustc_force_inline) && tcx.features().rustc_attrs(){
549-
if attr.is_word(){
550-
InlineAttr::Force{attr_span: attr.span,reason:None}
551-
}elseifletSome(val) = attr.value_str(){
552-
InlineAttr::Force{attr_span: attr.span,reason:Some(val)}
530+
if attr.is_word(){
531+
InlineAttr::Hint
532+
}elseifletSome(ref items) = attr.meta_item_list(){
533+
inline_span = Some(attr.span);
534+
if items.len() != 1{
535+
struct_span_code_err!(tcx.dcx(), attr.span,E0534,"expected one argument").emit();
536+
InlineAttr::None
537+
}elseiflist_contains_name(items, sym::always){
538+
InlineAttr::Always
539+
}elseiflist_contains_name(items, sym::never){
540+
InlineAttr::Never
553541
}else{
554-
debug!("`rustc_force_inline` not checked by attribute validation");
555-
ia
542+
struct_span_code_err!(tcx.dcx(), items[0].span(),E0535,"invalid argument")
543+
.with_help("valid inline arguments are `always` and `never`")
544+
.emit();
545+
546+
InlineAttr::None
556547
}
557548
}else{
558549
ia
559550
}
560551
});
552+
codegen_fn_attrs.inline = attrs.iter().fold(codegen_fn_attrs.inline, |ia, attr| {
553+
if !attr.has_name(sym::rustc_force_inline) || !tcx.features().rustc_attrs(){
554+
return ia;
555+
}
556+
557+
if attr.is_word(){
558+
InlineAttr::Force{attr_span: attr.span,reason:None}
559+
}elseifletSome(val) = attr.value_str(){
560+
InlineAttr::Force{attr_span: attr.span,reason:Some(val)}
561+
}else{
562+
debug!("`rustc_force_inline` not checked by attribute validation");
563+
ia
564+
}
565+
});
561566

562567
// naked function MUST NOT be inlined! This attribute is required for the rust compiler itself,
563568
// but not for the code generation backend because at that point the naked function will just be

0 commit comments

Comments
 (0)