-
Notifications
You must be signed in to change notification settings - Fork 13.5k
mir_transform: implement #[rustc_force_inline]
#134082
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+2,402
−661
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f86169a
mir_transform: implement forced inlining
davidtwco 02d423c
codegen_attrs: force inlining takes precedence
davidtwco 4507939
inline: force inlining shims
davidtwco e4bae91
inline: re-introduce some callee body checks
davidtwco 90066c0
inline: remove unnecessary promoted check
davidtwco 5f316f5
validator: move force inline check
davidtwco dbec6be
inline: move should inline check
davidtwco 3169a44
don't collect `#[rustc_force_inline]` in eager mode
davidtwco ce602ac
clarify `target_feature` + forced inlining
davidtwco cc9a9ec
mir_build: check annotated functions w/out callers
davidtwco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
use rustc_attr_parsing::InlineAttr; | ||
use rustc_hir::def_id::DefId; | ||
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; | ||
use rustc_middle::mir::{Body, TerminatorKind}; | ||
use rustc_middle::ty; | ||
use rustc_middle::ty::TyCtxt; | ||
use rustc_span::sym; | ||
|
||
/// Check that a body annotated with `#[rustc_force_inline]` will not fail to inline based on its | ||
/// definition alone (irrespective of any specific caller). | ||
pub(crate) fn check_force_inline<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>) { | ||
let def_id = body.source.def_id(); | ||
if !tcx.hir().body_owner_kind(def_id).is_fn_or_closure() || !def_id.is_local() { | ||
return; | ||
} | ||
let InlineAttr::Force { attr_span, .. } = tcx.codegen_fn_attrs(def_id).inline else { | ||
return; | ||
}; | ||
|
||
if let Err(reason) = | ||
is_inline_valid_on_fn(tcx, def_id).and_then(|_| is_inline_valid_on_body(tcx, body)) | ||
{ | ||
tcx.dcx().emit_err(crate::errors::InvalidForceInline { | ||
attr_span, | ||
callee_span: tcx.def_span(def_id), | ||
callee: tcx.def_path_str(def_id), | ||
reason, | ||
}); | ||
} | ||
} | ||
|
||
pub fn is_inline_valid_on_fn<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Result<(), &'static str> { | ||
let codegen_attrs = tcx.codegen_fn_attrs(def_id); | ||
if tcx.has_attr(def_id, sym::rustc_no_mir_inline) { | ||
return Err("#[rustc_no_mir_inline]"); | ||
} | ||
|
||
// FIXME(#127234): Coverage instrumentation currently doesn't handle inlined | ||
// MIR correctly when Modified Condition/Decision Coverage is enabled. | ||
if tcx.sess.instrument_coverage_mcdc() { | ||
return Err("incompatible with MC/DC coverage"); | ||
} | ||
|
||
let ty = tcx.type_of(def_id); | ||
if match ty.instantiate_identity().kind() { | ||
ty::FnDef(..) => tcx.fn_sig(def_id).instantiate_identity().c_variadic(), | ||
ty::Closure(_, args) => args.as_closure().sig().c_variadic(), | ||
_ => false, | ||
} { | ||
return Err("C variadic"); | ||
} | ||
|
||
if codegen_attrs.flags.contains(CodegenFnAttrFlags::COLD) { | ||
return Err("cold"); | ||
} | ||
|
||
// Intrinsic fallback bodies are automatically made cross-crate inlineable, | ||
// but at this stage we don't know whether codegen knows the intrinsic, | ||
// so just conservatively don't inline it. This also ensures that we do not | ||
// accidentally inline the body of an intrinsic that *must* be overridden. | ||
if tcx.has_attr(def_id, sym::rustc_intrinsic) { | ||
return Err("callee is an intrinsic"); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn is_inline_valid_on_body<'tcx>( | ||
_: TyCtxt<'tcx>, | ||
body: &Body<'tcx>, | ||
) -> Result<(), &'static str> { | ||
if body | ||
.basic_blocks | ||
.iter() | ||
.any(|bb| matches!(bb.terminator().kind, TerminatorKind::TailCall { .. })) | ||
{ | ||
return Err("can't inline functions with tail calls"); | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
tests/mir-opt/inline/forced.caller.ForceInline.panic-abort.diff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
- // MIR for `caller` before ForceInline | ||
+ // MIR for `caller` after ForceInline | ||
|
||
fn caller() -> () { | ||
let mut _0: (); | ||
let _1: (); | ||
+ scope 1 (inlined callee_forced) { | ||
+ } | ||
|
||
bb0: { | ||
StorageLive(_1); | ||
- _1 = callee_forced() -> [return: bb1, unwind unreachable]; | ||
- } | ||
- | ||
- bb1: { | ||
StorageDead(_1); | ||
_0 = const (); | ||
return; | ||
} | ||
} | ||
|
21 changes: 21 additions & 0 deletions
21
tests/mir-opt/inline/forced.caller.ForceInline.panic-unwind.diff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
- // MIR for `caller` before ForceInline | ||
+ // MIR for `caller` after ForceInline | ||
|
||
fn caller() -> () { | ||
let mut _0: (); | ||
let _1: (); | ||
+ scope 1 (inlined callee_forced) { | ||
+ } | ||
|
||
bb0: { | ||
StorageLive(_1); | ||
- _1 = callee_forced() -> [return: bb1, unwind continue]; | ||
- } | ||
- | ||
- bb1: { | ||
StorageDead(_1); | ||
_0 = const (); | ||
return; | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY | ||
//@ compile-flags: -Copt-level=0 --crate-type=lib | ||
#![feature(rustc_attrs)] | ||
|
||
#[rustc_force_inline] | ||
pub fn callee_forced() {} | ||
|
||
// EMIT_MIR forced.caller.ForceInline.diff | ||
pub fn caller() { | ||
callee_forced(); | ||
// CHECK-LABEL: fn caller( | ||
// CHECK: (inlined callee_forced) | ||
} |
12 changes: 12 additions & 0 deletions
12
tests/mir-opt/inline/forced_async.caller.ForceInline.panic-abort.diff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
- // MIR for `caller` before ForceInline | ||
+ // MIR for `caller` after ForceInline | ||
|
||
fn caller() -> {async fn body of caller()} { | ||
let mut _0: {async fn body of caller()}; | ||
|
||
bb0: { | ||
_0 = {coroutine@$DIR/forced_async.rs:10:19: 14:2 (#0)}; | ||
return; | ||
} | ||
} | ||
|
12 changes: 12 additions & 0 deletions
12
tests/mir-opt/inline/forced_async.caller.ForceInline.panic-unwind.diff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
- // MIR for `caller` before ForceInline | ||
+ // MIR for `caller` after ForceInline | ||
|
||
fn caller() -> {async fn body of caller()} { | ||
let mut _0: {async fn body of caller()}; | ||
|
||
bb0: { | ||
_0 = {coroutine@$DIR/forced_async.rs:10:19: 14:2 (#0)}; | ||
return; | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY | ||
//@ compile-flags: -Copt-level=0 --crate-type=lib | ||
//@ edition: 2021 | ||
#![feature(rustc_attrs)] | ||
|
||
#[rustc_force_inline] | ||
pub fn callee_forced() {} | ||
|
||
// EMIT_MIR forced_async.caller.ForceInline.diff | ||
async fn caller() { | ||
callee_forced(); | ||
// CHECK-LABEL: fn caller( | ||
// CHECK: (inlined callee_forced) | ||
} |
21 changes: 21 additions & 0 deletions
21
tests/mir-opt/inline/forced_closure.caller-{closure#0}.ForceInline.panic-abort.diff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
- // MIR for `caller::{closure#0}` before ForceInline | ||
+ // MIR for `caller::{closure#0}` after ForceInline | ||
|
||
fn caller::{closure#0}(_1: &{closure@$DIR/forced_closure.rs:10:6: 10:8}) -> () { | ||
let mut _0: (); | ||
let _2: (); | ||
+ scope 1 (inlined callee_forced) { | ||
+ } | ||
|
||
bb0: { | ||
StorageLive(_2); | ||
- _2 = callee_forced() -> [return: bb1, unwind unreachable]; | ||
- } | ||
- | ||
- bb1: { | ||
StorageDead(_2); | ||
_0 = const (); | ||
return; | ||
} | ||
} | ||
|
21 changes: 21 additions & 0 deletions
21
tests/mir-opt/inline/forced_closure.caller-{closure#0}.ForceInline.panic-unwind.diff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
- // MIR for `caller::{closure#0}` before ForceInline | ||
+ // MIR for `caller::{closure#0}` after ForceInline | ||
|
||
fn caller::{closure#0}(_1: &{closure@$DIR/forced_closure.rs:10:6: 10:8}) -> () { | ||
let mut _0: (); | ||
let _2: (); | ||
+ scope 1 (inlined callee_forced) { | ||
+ } | ||
|
||
bb0: { | ||
StorageLive(_2); | ||
- _2 = callee_forced() -> [return: bb1, unwind continue]; | ||
- } | ||
- | ||
- bb1: { | ||
StorageDead(_2); | ||
_0 = const (); | ||
return; | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY | ||
//@ compile-flags: -Copt-level=0 --crate-type=lib | ||
#![feature(rustc_attrs)] | ||
|
||
#[rustc_force_inline] | ||
pub fn callee_forced() {} | ||
|
||
// EMIT_MIR forced_closure.caller-{closure#0}.ForceInline.diff | ||
pub fn caller() { | ||
(|| { | ||
callee_forced(); | ||
// CHECK-LABEL: fn caller::{closure#0}( | ||
// CHECK: (inlined callee_forced) | ||
})(); | ||
} |
21 changes: 21 additions & 0 deletions
21
tests/mir-opt/inline/forced_dead_code.caller.ForceInline.panic-abort.diff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
- // MIR for `caller` before ForceInline | ||
+ // MIR for `caller` after ForceInline | ||
|
||
fn caller() -> () { | ||
let mut _0: (); | ||
let _1: (); | ||
+ scope 1 (inlined callee_forced) { | ||
+ } | ||
|
||
bb0: { | ||
StorageLive(_1); | ||
- _1 = callee_forced() -> [return: bb1, unwind unreachable]; | ||
- } | ||
- | ||
- bb1: { | ||
StorageDead(_1); | ||
_0 = const (); | ||
return; | ||
} | ||
} | ||
|
21 changes: 21 additions & 0 deletions
21
tests/mir-opt/inline/forced_dead_code.caller.ForceInline.panic-unwind.diff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
- // MIR for `caller` before ForceInline | ||
+ // MIR for `caller` after ForceInline | ||
|
||
fn caller() -> () { | ||
let mut _0: (); | ||
let _1: (); | ||
+ scope 1 (inlined callee_forced) { | ||
+ } | ||
|
||
bb0: { | ||
StorageLive(_1); | ||
- _1 = callee_forced() -> [return: bb1, unwind continue]; | ||
- } | ||
- | ||
- bb1: { | ||
StorageDead(_1); | ||
_0 = const (); | ||
return; | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY | ||
//@ compile-flags: -Copt-level=0 -Clink-dead-code | ||
#![feature(rustc_attrs)] | ||
|
||
#[rustc_force_inline] | ||
pub fn callee_forced() {} | ||
|
||
// EMIT_MIR forced_dead_code.caller.ForceInline.diff | ||
pub fn caller() { | ||
callee_forced(); | ||
// CHECK-LABEL: fn caller( | ||
// CHECK: (inlined callee_forced) | ||
} | ||
|
||
fn main() { | ||
caller(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
//@ build-fail | ||
//@ compile-flags: --crate-type=lib --target thumbv4t-none-eabi | ||
//@ needs-llvm-components: arm | ||
|
||
// Checks that forced inlining won't mix asm with incompatible instruction sets. | ||
|
||
#![crate_type = "lib"] | ||
#![feature(rustc_attrs)] | ||
#![feature(no_core, lang_items)] | ||
#![no_core] | ||
|
||
#[lang = "sized"] | ||
pub trait Sized {} | ||
#[lang = "copy"] | ||
pub trait Copy {} | ||
#[lang = "freeze"] | ||
pub unsafe trait Freeze {} | ||
|
||
#[lang = "start"] | ||
fn start<T>(_main: fn() -> T, _argc: isize, _argv: *const *const u8, _sigpipe: u8) -> isize { | ||
0 | ||
} | ||
|
||
#[rustc_builtin_macro] | ||
#[macro_export] | ||
macro_rules! asm { | ||
("assembly template", | ||
$(operands,)* | ||
$(options($(option),*))? | ||
) => { | ||
/* compiler built-in */ | ||
}; | ||
} | ||
|
||
#[instruction_set(arm::a32)] | ||
#[rustc_force_inline] | ||
fn instruction_set_a32() {} | ||
|
||
#[instruction_set(arm::t32)] | ||
#[rustc_force_inline] | ||
fn instruction_set_t32() {} | ||
|
||
#[rustc_force_inline] | ||
fn instruction_set_default() {} | ||
|
||
#[rustc_force_inline] | ||
fn inline_always_and_using_inline_asm() { | ||
unsafe { asm!("/* do nothing */") }; | ||
} | ||
|
||
#[instruction_set(arm::t32)] | ||
pub fn t32() { | ||
instruction_set_a32(); | ||
//~^ ERROR `instruction_set_a32` could not be inlined into `t32` but is required to be inlined | ||
instruction_set_t32(); | ||
instruction_set_default(); | ||
inline_always_and_using_inline_asm(); | ||
//~^ ERROR `inline_always_and_using_inline_asm` could not be inlined into `t32` but is required to be inlined | ||
} | ||
|
||
pub fn default() { | ||
instruction_set_a32(); | ||
//~^ ERROR `instruction_set_a32` could not be inlined into `default` but is required to be inlined | ||
instruction_set_t32(); | ||
//~^ ERROR `instruction_set_t32` could not be inlined into `default` but is required to be inlined | ||
instruction_set_default(); | ||
inline_always_and_using_inline_asm(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
error: `instruction_set_a32` could not be inlined into `t32` but is required to be inlined | ||
--> $DIR/asm.rs:53:5 | ||
| | ||
LL | instruction_set_a32(); | ||
| ^^^^^^^^^^^^^^^^^^^^^ ...`instruction_set_a32` called here | ||
| | ||
= note: could not be inlined due to: incompatible instruction set | ||
|
||
error: `inline_always_and_using_inline_asm` could not be inlined into `t32` but is required to be inlined | ||
--> $DIR/asm.rs:57:5 | ||
| | ||
LL | inline_always_and_using_inline_asm(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...`inline_always_and_using_inline_asm` called here | ||
| | ||
= note: could not be inlined due to: cannot move inline-asm across instruction sets | ||
|
||
error: `instruction_set_a32` could not be inlined into `default` but is required to be inlined | ||
--> $DIR/asm.rs:62:5 | ||
| | ||
LL | instruction_set_a32(); | ||
| ^^^^^^^^^^^^^^^^^^^^^ ...`instruction_set_a32` called here | ||
| | ||
= note: could not be inlined due to: incompatible instruction set | ||
|
||
error: `instruction_set_t32` could not be inlined into `default` but is required to be inlined | ||
--> $DIR/asm.rs:64:5 | ||
| | ||
LL | instruction_set_t32(); | ||
| ^^^^^^^^^^^^^^^^^^^^^ ...`instruction_set_t32` called here | ||
| | ||
= note: could not be inlined due to: incompatible instruction set | ||
|
||
error: aborting due to 4 previous errors | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
//@ compile-flags: --crate-type=lib | ||
#![feature(rustc_attrs)] | ||
|
||
#[rustc_force_inline = "the test requires it"] | ||
pub fn forced_with_reason() { | ||
} | ||
|
||
#[rustc_force_inline] | ||
pub fn forced() { | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//@ check-fail | ||
//@ compile-flags: --crate-type=lib | ||
#![allow(internal_features)] | ||
#![feature(rustc_attrs)] | ||
|
||
#[rustc_force_inline] | ||
pub fn callee(x: isize) -> usize { unimplemented!() } | ||
|
||
fn a() { | ||
let _: fn(isize) -> usize = callee; | ||
//~^ ERROR cannot coerce functions which must be inlined to function pointers | ||
} | ||
|
||
fn b() { | ||
let _ = callee as fn(isize) -> usize; | ||
//~^ ERROR non-primitive cast | ||
} | ||
|
||
fn c() { | ||
let _: [fn(isize) -> usize; 2] = [ | ||
callee, | ||
//~^ ERROR cannot coerce functions which must be inlined to function pointers | ||
callee, | ||
]; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
error[E0308]: cannot coerce functions which must be inlined to function pointers | ||
--> $DIR/cast.rs:10:33 | ||
| | ||
LL | let _: fn(isize) -> usize = callee; | ||
| ------------------ ^^^^^^ cannot coerce functions which must be inlined to function pointers | ||
| | | ||
| expected due to this | ||
| | ||
= note: expected fn pointer `fn(_) -> _` | ||
found fn item `fn(_) -> _ {callee}` | ||
= note: fn items are distinct from fn pointers | ||
help: consider casting to a fn pointer | ||
| | ||
LL | let _: fn(isize) -> usize = callee as fn(isize) -> usize; | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
error[E0605]: non-primitive cast: `fn(isize) -> usize {callee}` as `fn(isize) -> usize` | ||
--> $DIR/cast.rs:15:13 | ||
| | ||
LL | let _ = callee as fn(isize) -> usize; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid cast | ||
|
||
error[E0308]: cannot coerce functions which must be inlined to function pointers | ||
--> $DIR/cast.rs:21:9 | ||
| | ||
LL | callee, | ||
| ^^^^^^ cannot coerce functions which must be inlined to function pointers | ||
| | ||
= note: expected fn pointer `fn(_) -> _` | ||
found fn item `fn(_) -> _ {callee}` | ||
= note: fn items are distinct from fn pointers | ||
help: consider casting to a fn pointer | ||
| | ||
LL | callee as fn(isize) -> usize, | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
Some errors have detailed explanations: E0308, E0605. | ||
For more information about an error, try `rustc --explain E0308`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//@ aux-build:callees.rs | ||
//@ build-pass | ||
//@ compile-flags: --crate-type=lib | ||
|
||
extern crate callees; | ||
|
||
// Test that forced inlining across crates works as expected. | ||
|
||
pub fn caller() { | ||
callees::forced(); | ||
|
||
callees::forced_with_reason(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//@ check-fail | ||
//@ compile-flags: --crate-type=lib | ||
//@ edition: 2021 | ||
#![allow(internal_features)] | ||
#![feature(rustc_attrs)] | ||
|
||
// Test that forced inlining into async functions w/ errors works as expected. | ||
|
||
#[rustc_no_mir_inline] | ||
#[rustc_force_inline] | ||
//~^ ERROR `callee` is incompatible with `#[rustc_force_inline]` | ||
pub fn callee() { | ||
} | ||
|
||
#[rustc_no_mir_inline] | ||
#[rustc_force_inline = "the test requires it"] | ||
//~^ ERROR `callee_justified` is incompatible with `#[rustc_force_inline]` | ||
pub fn callee_justified() { | ||
} | ||
|
||
async fn async_caller() { | ||
callee(); | ||
callee_justified(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
error: `callee` is incompatible with `#[rustc_force_inline]` | ||
--> $DIR/deny-async.rs:10:1 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | pub fn callee() { | ||
| --------------- `callee` defined here | ||
| | ||
= note: incompatible due to: #[rustc_no_mir_inline] | ||
|
||
error: `callee_justified` is incompatible with `#[rustc_force_inline]` | ||
--> $DIR/deny-async.rs:16:1 | ||
| | ||
LL | #[rustc_force_inline = "the test requires it"] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | pub fn callee_justified() { | ||
| ------------------------- `callee_justified` defined here | ||
| | ||
= note: incompatible due to: #[rustc_no_mir_inline] | ||
|
||
error: aborting due to 2 previous errors | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//@ check-fail | ||
//@ compile-flags: --crate-type=lib | ||
#![allow(internal_features)] | ||
#![feature(rustc_attrs)] | ||
|
||
// Test that forced inlining into closures w/ errors works as expected. | ||
|
||
#[rustc_no_mir_inline] | ||
#[rustc_force_inline] | ||
//~^ ERROR `callee` is incompatible with `#[rustc_force_inline]` | ||
pub fn callee() { | ||
} | ||
|
||
#[rustc_no_mir_inline] | ||
#[rustc_force_inline = "the test requires it"] | ||
//~^ ERROR `callee_justified` is incompatible with `#[rustc_force_inline]` | ||
pub fn callee_justified() { | ||
} | ||
|
||
pub fn caller() { | ||
(|| { | ||
callee(); | ||
callee_justified(); | ||
})(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
error: `callee` is incompatible with `#[rustc_force_inline]` | ||
--> $DIR/deny-closure.rs:9:1 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | pub fn callee() { | ||
| --------------- `callee` defined here | ||
| | ||
= note: incompatible due to: #[rustc_no_mir_inline] | ||
|
||
error: `callee_justified` is incompatible with `#[rustc_force_inline]` | ||
--> $DIR/deny-closure.rs:15:1 | ||
| | ||
LL | #[rustc_force_inline = "the test requires it"] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | pub fn callee_justified() { | ||
| ------------------------- `callee_justified` defined here | ||
| | ||
= note: incompatible due to: #[rustc_no_mir_inline] | ||
|
||
error: aborting due to 2 previous errors | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//@ check-fail | ||
davidtwco marked this conversation as resolved.
Show resolved
Hide resolved
|
||
//@ compile-flags: --crate-type=lib | ||
#![allow(internal_features)] | ||
#![feature(rustc_attrs)] | ||
|
||
// Test that forced inlining w/ errors works as expected. | ||
|
||
#[rustc_no_mir_inline] | ||
#[rustc_force_inline] | ||
//~^ ERROR `callee` is incompatible with `#[rustc_force_inline]` | ||
pub fn callee() { | ||
} | ||
|
||
#[rustc_no_mir_inline] | ||
#[rustc_force_inline = "the test requires it"] | ||
//~^ ERROR `callee_justified` is incompatible with `#[rustc_force_inline]` | ||
pub fn callee_justified() { | ||
} | ||
|
||
pub fn caller() { | ||
callee(); | ||
callee_justified(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
error: `callee` is incompatible with `#[rustc_force_inline]` | ||
--> $DIR/deny.rs:9:1 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | pub fn callee() { | ||
| --------------- `callee` defined here | ||
| | ||
= note: incompatible due to: #[rustc_no_mir_inline] | ||
|
||
error: `callee_justified` is incompatible with `#[rustc_force_inline]` | ||
--> $DIR/deny.rs:15:1 | ||
| | ||
LL | #[rustc_force_inline = "the test requires it"] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | pub fn callee_justified() { | ||
| ------------------------- `callee_justified` defined here | ||
| | ||
= note: incompatible due to: #[rustc_no_mir_inline] | ||
|
||
error: aborting due to 2 previous errors | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//@ check-fail | ||
//@ compile-flags: --crate-type=lib | ||
#![feature(c_variadic)] | ||
#![feature(rustc_attrs)] | ||
|
||
#[rustc_no_mir_inline] | ||
#[rustc_force_inline] | ||
//~^ ERROR `rustc_attr` is incompatible with `#[rustc_force_inline]` | ||
pub fn rustc_attr() { | ||
} | ||
|
||
#[cold] | ||
#[rustc_force_inline] | ||
//~^ ERROR `cold` is incompatible with `#[rustc_force_inline]` | ||
pub fn cold() { | ||
} | ||
|
||
#[rustc_force_inline] | ||
//~^ ERROR `variadic` is incompatible with `#[rustc_force_inline]` | ||
pub unsafe extern "C" fn variadic(args: ...) { | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
error: `rustc_attr` is incompatible with `#[rustc_force_inline]` | ||
--> $DIR/early-deny.rs:7:1 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | pub fn rustc_attr() { | ||
| ------------------- `rustc_attr` defined here | ||
| | ||
= note: incompatible due to: #[rustc_no_mir_inline] | ||
|
||
error: `cold` is incompatible with `#[rustc_force_inline]` | ||
--> $DIR/early-deny.rs:13:1 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | pub fn cold() { | ||
| ------------- `cold` defined here | ||
| | ||
= note: incompatible due to: cold | ||
|
||
error: `variadic` is incompatible with `#[rustc_force_inline]` | ||
--> $DIR/early-deny.rs:18:1 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | pub unsafe extern "C" fn variadic(args: ...) { | ||
| -------------------------------------------- `variadic` defined here | ||
| | ||
= note: incompatible due to: C variadic | ||
|
||
error: aborting due to 3 previous errors | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
//@ compile-flags: --crate-type=lib | ||
#![allow(internal_features)] | ||
|
||
#[rustc_force_inline] | ||
//~^ ERROR #![rustc_force_inline] forces a free function to be inlined | ||
pub fn bare() { | ||
} | ||
|
||
#[rustc_force_inline = "the test requires it"] | ||
//~^ ERROR #![rustc_force_inline] forces a free function to be inlined | ||
pub fn justified() { | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
error[E0658]: #![rustc_force_inline] forces a free function to be inlined | ||
--> $DIR/gate.rs:4:1 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: add `#![feature(rustc_attrs)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
||
error[E0658]: #![rustc_force_inline] forces a free function to be inlined | ||
--> $DIR/gate.rs:9:1 | ||
| | ||
LL | #[rustc_force_inline = "the test requires it"] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: add `#![feature(rustc_attrs)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
//@ edition: 2024 | ||
#![allow(internal_features, unused_imports, unused_macros)] | ||
#![feature(extern_types)] | ||
#![feature(gen_blocks)] | ||
#![feature(rustc_attrs)] | ||
#![feature(stmt_expr_attributes)] | ||
#![feature(trait_alias)] | ||
|
||
// Test that invalid force inlining attributes error as expected. | ||
|
||
#[rustc_force_inline("foo")] | ||
//~^ ERROR malformed `rustc_force_inline` attribute input | ||
pub fn forced1() { | ||
} | ||
|
||
#[rustc_force_inline(bar, baz)] | ||
//~^ ERROR malformed `rustc_force_inline` attribute input | ||
pub fn forced2() { | ||
} | ||
|
||
#[rustc_force_inline(2)] | ||
//~^ ERROR malformed `rustc_force_inline` attribute input | ||
pub fn forced3() { | ||
} | ||
|
||
#[rustc_force_inline = 2] | ||
//~^ ERROR malformed `rustc_force_inline` attribute input | ||
pub fn forced4() { | ||
} | ||
|
||
#[rustc_force_inline] | ||
//~^ ERROR attribute should be applied to a function | ||
extern crate std as other_std; | ||
|
||
#[rustc_force_inline] | ||
//~^ ERROR attribute should be applied to a function | ||
use std::collections::HashMap; | ||
|
||
#[rustc_force_inline] | ||
//~^ ERROR attribute should be applied to a function | ||
static _FOO: &'static str = "FOO"; | ||
|
||
#[rustc_force_inline] | ||
//~^ ERROR attribute should be applied to a function | ||
const _BAR: u32 = 3; | ||
|
||
#[rustc_force_inline] | ||
//~^ ERROR attribute should be applied to a function | ||
mod foo { } | ||
|
||
#[rustc_force_inline] | ||
//~^ ERROR attribute should be applied to a function | ||
unsafe extern "C" { | ||
#[rustc_force_inline] | ||
//~^ ERROR attribute should be applied to a function | ||
static X: &'static u32; | ||
|
||
#[rustc_force_inline] | ||
//~^ ERROR attribute should be applied to a function | ||
type Y; | ||
|
||
#[rustc_force_inline] | ||
//~^ ERROR attribute should be applied to a function | ||
fn foo(); | ||
} | ||
|
||
#[rustc_force_inline] | ||
//~^ ERROR attribute should be applied to a function | ||
type Foo = u32; | ||
|
||
#[rustc_force_inline] | ||
//~^ ERROR attribute should be applied to a function | ||
enum Bar<#[rustc_force_inline] T> { | ||
//~^ ERROR attribute should be applied to a function | ||
#[rustc_force_inline] | ||
//~^ ERROR attribute should be applied to a function | ||
Baz(std::marker::PhantomData<T>), | ||
} | ||
|
||
#[rustc_force_inline] | ||
//~^ ERROR attribute should be applied to a function | ||
struct Qux { | ||
#[rustc_force_inline] | ||
//~^ ERROR attribute should be applied to a function | ||
field: u32, | ||
} | ||
|
||
#[rustc_force_inline] | ||
//~^ ERROR attribute should be applied to a function | ||
union FooBar { | ||
x: u32, | ||
y: u32, | ||
} | ||
|
||
#[rustc_force_inline] | ||
//~^ ERROR attribute should be applied to a function | ||
trait FooBaz { | ||
#[rustc_force_inline] | ||
//~^ ERROR attribute should be applied to a function | ||
type Foo; | ||
#[rustc_force_inline] | ||
//~^ ERROR attribute should be applied to a function | ||
const Bar: i32; | ||
|
||
#[rustc_force_inline] | ||
//~^ ERROR attribute should be applied to a function | ||
fn foo() {} | ||
} | ||
|
||
#[rustc_force_inline] | ||
//~^ ERROR attribute should be applied to a function | ||
trait FooQux = FooBaz; | ||
|
||
#[rustc_force_inline] | ||
//~^ ERROR attribute should be applied to a function | ||
impl<T> Bar<T> { | ||
#[rustc_force_inline] | ||
//~^ ERROR attribute should be applied to a function | ||
fn foo() {} | ||
} | ||
|
||
#[rustc_force_inline] | ||
//~^ ERROR attribute should be applied to a function | ||
impl<T> FooBaz for Bar<T> { | ||
type Foo = u32; | ||
const Bar: i32 = 3; | ||
} | ||
|
||
#[rustc_force_inline] | ||
//~^ ERROR attribute should be applied to a function | ||
macro_rules! barqux { ($foo:tt) => { $foo }; } | ||
|
||
fn barqux(#[rustc_force_inline] _x: u32) {} | ||
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters | ||
//~^^ ERROR attribute should be applied to a function | ||
|
||
#[rustc_force_inline] | ||
//~^ ERROR attribute cannot be applied to a `async`, `gen` or `async gen` function | ||
async fn async_foo() {} | ||
|
||
#[rustc_force_inline] | ||
//~^ ERROR attribute cannot be applied to a `async`, `gen` or `async gen` function | ||
gen fn gen_foo() {} | ||
|
||
#[rustc_force_inline] | ||
//~^ ERROR attribute cannot be applied to a `async`, `gen` or `async gen` function | ||
async gen fn async_gen_foo() {} | ||
|
||
fn main() { | ||
let _x = #[rustc_force_inline] || { }; | ||
//~^ ERROR attribute should be applied to a function | ||
let _y = #[rustc_force_inline] 3 + 4; | ||
//~^ ERROR attribute should be applied to a function | ||
#[rustc_force_inline] | ||
//~^ ERROR attribute should be applied to a function | ||
let _z = 3; | ||
|
||
match _z { | ||
#[rustc_force_inline] | ||
//~^ ERROR attribute should be applied to a function | ||
1 => (), | ||
_ => (), | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,377 @@ | ||
error: malformed `rustc_force_inline` attribute input | ||
--> $DIR/invalid.rs:11:1 | ||
| | ||
LL | #[rustc_force_inline("foo")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: the following are the possible correct uses | ||
| | ||
LL | #[rustc_force_inline = "reason"] | ||
| | ||
LL | #[rustc_force_inline] | ||
| | ||
|
||
error: malformed `rustc_force_inline` attribute input | ||
--> $DIR/invalid.rs:16:1 | ||
| | ||
LL | #[rustc_force_inline(bar, baz)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: the following are the possible correct uses | ||
| | ||
LL | #[rustc_force_inline = "reason"] | ||
| | ||
LL | #[rustc_force_inline] | ||
| | ||
|
||
error: malformed `rustc_force_inline` attribute input | ||
--> $DIR/invalid.rs:21:1 | ||
| | ||
LL | #[rustc_force_inline(2)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: the following are the possible correct uses | ||
| | ||
LL | #[rustc_force_inline = "reason"] | ||
| | ||
LL | #[rustc_force_inline] | ||
| | ||
|
||
error: malformed `rustc_force_inline` attribute input | ||
--> $DIR/invalid.rs:26:1 | ||
| | ||
LL | #[rustc_force_inline = 2] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: the following are the possible correct uses | ||
| | ||
LL | #[rustc_force_inline = "reason"] | ||
| | ||
LL | #[rustc_force_inline] | ||
| | ||
|
||
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters | ||
--> $DIR/invalid.rs:133:11 | ||
| | ||
LL | fn barqux(#[rustc_force_inline] _x: u32) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid.rs:31:1 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | extern crate std as other_std; | ||
| ------------------------------ not a function definition | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid.rs:35:1 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | use std::collections::HashMap; | ||
| ------------------------------ not a function definition | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid.rs:39:1 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | static _FOO: &'static str = "FOO"; | ||
| ---------------------------------- not a function definition | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid.rs:43:1 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | const _BAR: u32 = 3; | ||
| -------------------- not a function definition | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid.rs:47:1 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | mod foo { } | ||
| ----------- not a function definition | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid.rs:51:1 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | / unsafe extern "C" { | ||
LL | | #[rustc_force_inline] | ||
LL | | | ||
LL | | static X: &'static u32; | ||
... | | ||
LL | | fn foo(); | ||
LL | | } | ||
| |_- not a function definition | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid.rs:67:1 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | type Foo = u32; | ||
| --------------- not a function definition | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid.rs:71:1 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | / enum Bar<#[rustc_force_inline] T> { | ||
LL | | | ||
LL | | #[rustc_force_inline] | ||
... | | ||
LL | | } | ||
| |_- not a function definition | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid.rs:73:10 | ||
| | ||
LL | enum Bar<#[rustc_force_inline] T> { | ||
| ^^^^^^^^^^^^^^^^^^^^^ - not a function definition | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid.rs:75:5 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | Baz(std::marker::PhantomData<T>), | ||
| -------------------------------- not a function definition | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid.rs:80:1 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | / struct Qux { | ||
LL | | #[rustc_force_inline] | ||
LL | | | ||
LL | | field: u32, | ||
LL | | } | ||
| |_- not a function definition | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid.rs:83:5 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | field: u32, | ||
| ---------- not a function definition | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid.rs:88:1 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | / union FooBar { | ||
LL | | x: u32, | ||
LL | | y: u32, | ||
LL | | } | ||
| |_- not a function definition | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid.rs:95:1 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | / trait FooBaz { | ||
LL | | #[rustc_force_inline] | ||
LL | | | ||
LL | | type Foo; | ||
... | | ||
LL | | fn foo() {} | ||
LL | | } | ||
| |_- not a function definition | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid.rs:110:1 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | trait FooQux = FooBaz; | ||
| ---------------------- not a function definition | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid.rs:114:1 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | / impl<T> Bar<T> { | ||
LL | | #[rustc_force_inline] | ||
LL | | | ||
LL | | fn foo() {} | ||
LL | | } | ||
| |_- not a function definition | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid.rs:122:1 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | / impl<T> FooBaz for Bar<T> { | ||
LL | | type Foo = u32; | ||
LL | | const Bar: i32 = 3; | ||
LL | | } | ||
| |_- not a function definition | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid.rs:129:1 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | macro_rules! barqux { ($foo:tt) => { $foo }; } | ||
| ---------------------------------------------- not a function definition | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid.rs:133:11 | ||
| | ||
LL | fn barqux(#[rustc_force_inline] _x: u32) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^-------- | ||
| | | ||
| not a function definition | ||
|
||
error: attribute cannot be applied to a `async`, `gen` or `async gen` function | ||
--> $DIR/invalid.rs:137:1 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | async fn async_foo() {} | ||
| -------------------- `async`, `gen` or `async gen` function | ||
|
||
error: attribute cannot be applied to a `async`, `gen` or `async gen` function | ||
--> $DIR/invalid.rs:141:1 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | gen fn gen_foo() {} | ||
| ---------------- `async`, `gen` or `async gen` function | ||
|
||
error: attribute cannot be applied to a `async`, `gen` or `async gen` function | ||
--> $DIR/invalid.rs:145:1 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | async gen fn async_gen_foo() {} | ||
| ---------------------------- `async`, `gen` or `async gen` function | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid.rs:150:14 | ||
| | ||
LL | let _x = #[rustc_force_inline] || { }; | ||
| ^^^^^^^^^^^^^^^^^^^^^ ------ not a function definition | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid.rs:152:14 | ||
| | ||
LL | let _y = #[rustc_force_inline] 3 + 4; | ||
| ^^^^^^^^^^^^^^^^^^^^^ - not a function definition | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid.rs:154:5 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | let _z = 3; | ||
| ----------- not a function definition | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid.rs:159:9 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | 1 => (), | ||
| ------- not a function definition | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid.rs:98:5 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | type Foo; | ||
| --------- not a function definition | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid.rs:101:5 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | const Bar: i32; | ||
| --------------- not a function definition | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid.rs:105:5 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | fn foo() {} | ||
| ----------- not a function definition | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid.rs:117:5 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | fn foo() {} | ||
| ----------- not a function definition | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid.rs:54:5 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | static X: &'static u32; | ||
| ----------------------- not a function definition | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid.rs:58:5 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | type Y; | ||
| ------- not a function definition | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid.rs:62:5 | ||
| | ||
LL | #[rustc_force_inline] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | fn foo(); | ||
| --------- not a function definition | ||
|
||
error: aborting due to 38 previous errors | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
//@ build-pass | ||
#![allow(internal_features)] | ||
#![feature(rustc_attrs)] | ||
|
||
#[rustc_force_inline] | ||
fn f() {} | ||
fn g<T: FnOnce()>(t: T) { t(); } | ||
|
||
fn main() { g(f); } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.