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
6 changes: 5 additions & 1 deletion compiler/rustc_attr_parsing/src/attributes/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ impl<S: Stage> SingleAttributeParser<S> for RustcForceInlineParser {
const PATH: &'static [Symbol] = &[sym::rustc_force_inline];
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Fn)]);
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
Allow(Target::Fn),
Allow(Target::Method(MethodKind::Inherent)),
]);

const TEMPLATE: AttributeTemplate = template!(Word, List: &["reason"], NameValueStr: "reason");

fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
Expand Down
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_inherent.rs:14:6: 14:8}) -> () {
let mut _0: ();
let _2: ();
+ scope 1 (inlined Foo::callee_forced) {
+ }

bb0: {
StorageLive(_2);
- _2 = Foo::callee_forced() -> [return: bb1, unwind unreachable];
- }
-
- bb1: {
StorageDead(_2);
_0 = const ();
return;
}
}

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_inherent.rs:14:6: 14:8}) -> () {
let mut _0: ();
let _2: ();
+ scope 1 (inlined Foo::callee_forced) {
+ }

bb0: {
StorageLive(_2);
- _2 = Foo::callee_forced() -> [return: bb1, unwind continue];
- }
-
- bb1: {
StorageDead(_2);
_0 = const ();
return;
}
}

19 changes: 19 additions & 0 deletions tests/mir-opt/inline/forced_closure_inherent.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
//@ compile-flags: -Copt-level=0 --crate-type=lib
#![feature(rustc_attrs)]

struct Foo {}

impl Foo {
#[rustc_force_inline]
pub fn callee_forced() {}
}

// EMIT_MIR forced_closure_inherent.caller-{closure#0}.ForceInline.diff
pub fn caller() {
(|| {
Foo::callee_forced();
// CHECK-LABEL: fn caller::{closure#0}(
// CHECK: (inlined Foo::callee_forced)
})();
}
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 Foo::bar) {
+ }

bb0: {
StorageLive(_1);
- _1 = Foo::bar() -> [return: bb1, unwind unreachable];
- }
-
- bb1: {
StorageDead(_1);
_0 = const ();
return;
}
}

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 Foo::bar) {
+ }

bb0: {
StorageLive(_1);
- _1 = Foo::bar() -> [return: bb1, unwind continue];
- }
-
- bb1: {
StorageDead(_1);
_0 = const ();
return;
}
}

17 changes: 17 additions & 0 deletions tests/mir-opt/inline/forced_inherent.rs
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 --crate-type=lib
#![feature(rustc_attrs)]

struct Foo;

impl Foo {
#[rustc_force_inline]
fn bar() {}
}

// EMIT_MIR forced_inherent.caller.ForceInline.diff
fn caller() {
Foo::bar();
// CHECK-LABEL: fn caller(
// CHECK: (inlined Foo::bar)
}
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 Foo::bar) {
+ }

bb0: {
StorageLive(_1);
- _1 = Foo::bar() -> [return: bb1, unwind unreachable];
- }
-
- bb1: {
StorageDead(_1);
_0 = const ();
return;
}
}

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 Foo::bar) {
+ }

bb0: {
StorageLive(_1);
- _1 = Foo::bar() -> [return: bb1, unwind continue];
- }
-
- bb1: {
StorageDead(_1);
_0 = const ();
return;
}
}

25 changes: 25 additions & 0 deletions tests/mir-opt/inline/forced_inherent_ambiguous.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
//@ compile-flags: -Copt-level=0 --crate-type=lib
#![feature(rustc_attrs)]

struct Foo;

impl Foo {
#[rustc_force_inline]
fn bar() {}
}

trait Tr {
fn bar();
}

impl Tr for Foo {
fn bar() {}
}

// EMIT_MIR forced_inherent_ambiguous.caller.ForceInline.diff
fn caller() {
Foo::bar();
// CHECK-LABEL: fn caller(
// CHECK: (inlined Foo::bar)
}
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_inherent_async.rs:14:19: 18:2 (#0)};
return;
}
}

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_inherent_async.rs:14:19: 18:2 (#0)};
return;
}
}

18 changes: 18 additions & 0 deletions tests/mir-opt/inline/forced_inherent_async.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
//@ compile-flags: -Copt-level=0 --crate-type=lib
//@ edition: 2021
#![feature(rustc_attrs)]

struct Foo {}

impl Foo {
#[rustc_force_inline]
pub fn callee_forced() {}
}

// EMIT_MIR forced_inherent_async.caller.ForceInline.diff
async fn caller() {
Foo::callee_forced();
// CHECK-LABEL: fn caller(
// CHECK: (inlined Foo::callee_forced)
}
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 Foo::callee_forced) {
+ }

bb0: {
StorageLive(_1);
- _1 = Foo::callee_forced() -> [return: bb1, unwind unreachable];
- }
-
- bb1: {
StorageDead(_1);
_0 = const ();
return;
}
}

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 Foo::callee_forced) {
+ }

bb0: {
StorageLive(_1);
- _1 = Foo::callee_forced() -> [return: bb1, unwind continue];
- }
-
- bb1: {
StorageDead(_1);
_0 = const ();
return;
}
}

21 changes: 21 additions & 0 deletions tests/mir-opt/inline/forced_inherent_dead_code.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
//@ compile-flags: -Copt-level=0 -Clink-dead-code
#![feature(rustc_attrs)]

struct Foo {}

impl Foo {
#[rustc_force_inline]
pub fn callee_forced() {}
}

// EMIT_MIR forced_inherent_dead_code.caller.ForceInline.diff
pub fn caller() {
Foo::callee_forced();
// CHECK-LABEL: fn caller(
// CHECK: (inlined Foo::callee_forced)
}

fn main() {
caller();
}
21 changes: 21 additions & 0 deletions tests/ui/force-inlining/inherent.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//@ check-fail
#![feature(rustc_attrs)]

struct Foo;

impl Foo {
#[rustc_force_inline]
//~^ ERROR: `Foo::bar` is incompatible with `#[rustc_force_inline]`
#[rustc_no_mir_inline]
fn bar() {}
}

fn bar_caller() {
unsafe {
Foo::bar();
}
}

fn main() {
bar_caller();
}
13 changes: 13 additions & 0 deletions tests/ui/force-inlining/inherent.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error: `Foo::bar` is incompatible with `#[rustc_force_inline]`
--> $DIR/inherent.rs:7:5
|
LL | #[rustc_force_inline]
| ^^^^^^^^^^^^^^^^^^^^^
...
LL | fn bar() {}
| -------- `Foo::bar` defined here
|
= note: incompatible due to: #[rustc_no_mir_inline]

error: aborting due to 1 previous error

1 change: 0 additions & 1 deletion tests/ui/force-inlining/invalid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ trait FooQux = FooBaz;
//~^ ERROR attribute cannot be used on
impl<T> Bar<T> {
#[rustc_force_inline]
//~^ ERROR attribute cannot be used on
fn foo() {}
}

Expand Down
Loading
Loading