Skip to content

Commit eb18ddd

Browse files
committed
Don't auto-inline const fn
1 parent ef99b57 commit eb18ddd

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

src/librustc/ty/instance.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,7 @@ impl<'tcx> InstanceDef<'tcx> {
173173
// available to normal end-users.
174174
return true
175175
}
176-
let codegen_fn_attrs = tcx.codegen_fn_attrs(self.def_id());
177-
// need to use `is_const_fn_raw` since we don't really care if the user can use it as a
178-
// const fn, just whether the function should be inlined
179-
codegen_fn_attrs.requests_inline() || tcx.is_const_fn_raw(self.def_id())
176+
tcx.codegen_fn_attrs(self.def_id()).requests_inline()
180177
}
181178
}
182179

src/test/codegen-units/item-collection/unreferenced-const-fn.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
// ignore-tidy-linelength
1212
// compile-flags:-Zprint-mono-items=lazy
1313

14-
// NB: We do not expect *any* monomorphization to be generated here.
15-
1614
#![deny(dead_code)]
1715
#![crate_type = "rlib"]
1816

17+
//~ MONO_ITEM fn unreferenced_const_fn::foo[0] @@ unreferenced_const_fn-cgu.0[External]
1918
pub const fn foo(x: u32) -> u32 {
2019
x + 0xf00
2120
}

src/test/ui/consts/auxiliary/const_fn_lib.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,24 @@
1010

1111
// Crate that exports a const fn. Used for testing cross-crate.
1212

13+
#![feature(const_fn)]
1314
#![crate_type="rlib"]
1415

15-
pub const fn foo() -> usize { 22 } //~ ERROR const fn is unstable
16+
pub const fn foo() -> usize { 22 }
17+
18+
pub const fn bar() -> fn() {
19+
fn x() {}
20+
x
21+
}
22+
23+
#[inline]
24+
pub const fn bar_inlined() -> fn() {
25+
fn x() {}
26+
x
27+
}
28+
29+
#[inline(always)]
30+
pub const fn bar_inlined_always() -> fn() {
31+
fn x() {}
32+
x
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// compile-pass
2+
// aux-build:const_fn_lib.rs
3+
4+
extern crate const_fn_lib;
5+
6+
fn main() {
7+
const_fn_lib::bar()();
8+
const_fn_lib::bar_inlined()();
9+
const_fn_lib::bar_inlined_always()();
10+
}

0 commit comments

Comments
 (0)