Skip to content

Commit 8216948

Browse files
committed
Allow comptime fns to call other comptime fns
1 parent a765cef commit 8216948

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

compiler/rustc_middle/src/hir/map.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,11 @@ impl<'tcx> TyCtxt<'tcx> {
319319

320320
BodyOwnerKind::Fn if self.is_constructor(def_id) => return None,
321321
BodyOwnerKind::Fn | BodyOwnerKind::Closure if self.is_const_fn(def_id) => {
322-
ConstContext::ConstFn
322+
if self.constness(def_id) == rustc_hir::Constness::Comptime {
323+
ConstContext::Const { inline: true }
324+
} else {
325+
ConstContext::ConstFn
326+
}
323327
}
324328
BodyOwnerKind::Fn if self.is_const_default_method(def_id) => ConstContext::ConstFn,
325329
BodyOwnerKind::Fn | BodyOwnerKind::Closure | BodyOwnerKind::GlobalAsm => return None,

tests/ui/comptime/not_callable.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ const fn bar() {
1919

2020
#[rustc_comptime]
2121
fn baz() {
22-
// Should be allowed
22+
// Ok
2323
foo();
24-
//~^ ERROR: comptime fns can only be called at compile time
2524
}

tests/ui/comptime/not_callable.stderr

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,5 @@ error: comptime fns can only be called at compile time
1010
LL | foo();
1111
| ^^^^^
1212

13-
error: comptime fns can only be called at compile time
14-
--> $DIR/not_callable.rs:23:5
15-
|
16-
LL | foo();
17-
| ^^^^^
18-
19-
error: aborting due to 3 previous errors
13+
error: aborting due to 2 previous errors
2014

0 commit comments

Comments
 (0)