Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions compiler/rustc_attr_parsing/src/attributes/inline.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// FIXME(jdonszelmann): merge these two parsers and error when both attributes are present here.
// note: need to model better how duplicate attr errors work when not using
// SingleAttributeParser which is what we have two of here.

use rustc_feature::AttributeStability;
use rustc_hir::attrs::{AttributeKind, InlineAttr};
use rustc_hir::find_attr;
use rustc_session::lint::builtin::ILL_FORMED_ATTRIBUTE_INPUT;

use super::prelude::*;
use crate::session_diagnostics::InlineForceInlineConflict;

pub(crate) struct InlineParser;

Expand Down Expand Up @@ -94,4 +92,16 @@ impl SingleAttributeParser for RustcForceInlineParser {
cx.attr_span,
))
}

fn finalize_check(cx: &FinalizeCheckContext<'_, '_>, attr_span: Span) {
let Some(inline_span) = find_attr!(cx.parsed_attrs, Inline(attr, span) if !matches!(attr, InlineAttr::Force { .. }) => span)
else {
return;
};

cx.emit_err(InlineForceInlineConflict {
inline_span: *inline_span,
force_inline_span: attr_span,
});
}
}
9 changes: 9 additions & 0 deletions compiler/rustc_attr_parsing/src/session_diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ use rustc_target::spec::TargetTuple;
use crate::AttributeTemplate;
use crate::context::Suggestion;

#[derive(Diagnostic)]
#[diag("`#[rustc_force_inline]` and `#[inline]` cannot be used together")]
pub(crate) struct InlineForceInlineConflict {
#[primary_span]
pub force_inline_span: Span,
#[label("the inline attribute is specified here")]
pub inline_span: Span,
}

#[derive(Diagnostic)]
#[diag("`#[ffi_const]` function cannot be `#[ffi_pure]`", code = E0757)]
pub(crate) struct BothFfiConstAndPure {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#![feature(rustc_attrs)]

#[inline] //~ NOTE: the inline attribute is specified here
#[rustc_force_inline] //~ ERROR: cannot be used together
fn foo() {}

#[rustc_force_inline] //~ ERROR: cannot be used together
#[inline] //~ NOTE: the inline attribute is specified here
fn bar() {}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error: `#[rustc_force_inline]` and `#[inline]` cannot be used together
--> $DIR/rustc-force-inline-conflict-with-inline.rs:4:1
|
LL | #[inline]
| --------- the inline attribute is specified here
LL | #[rustc_force_inline]
| ^^^^^^^^^^^^^^^^^^^^^

error: `#[rustc_force_inline]` and `#[inline]` cannot be used together
--> $DIR/rustc-force-inline-conflict-with-inline.rs:7:1
|
LL | #[rustc_force_inline]
| ^^^^^^^^^^^^^^^^^^^^^
LL | #[inline]
| --------- the inline attribute is specified here

error: aborting due to 2 previous errors

Loading