Skip to content

Commit 2d132f2

Browse files
committed
Allow comptime fns to call other comptime fns
1 parent ee23829 commit 2d132f2

3 files changed

Lines changed: 10 additions & 10 deletions

File tree

compiler/rustc_middle/src/hir/map.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,13 @@ impl<'tcx> TyCtxt<'tcx> {
321321
BodyOwnerKind::Closure if self.is_const_fn(def_id) => {
322322
return self.hir_body_const_context(self.local_parent(local_def_id));
323323
}
324-
BodyOwnerKind::Fn if self.is_const_fn(def_id) => ConstContext::ConstFn,
324+
BodyOwnerKind::Fn if self.is_const_fn(def_id) => {
325+
if matches!(self.constness(def_id), rustc_hir::Constness::Const { always: true }) {
326+
ConstContext::Const { inline: true }
327+
} else {
328+
ConstContext::ConstFn
329+
}
330+
}
325331
BodyOwnerKind::Fn | BodyOwnerKind::Closure | BodyOwnerKind::GlobalAsm => return None,
326332
};
327333

tests/ui/comptime/not_callable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ const fn bar() {
1717

1818
#[rustc_comptime]
1919
fn baz() {
20-
// TODO: Should be allowed
21-
foo(); //~ ERROR: comptime fns can only be called at compile time
20+
// Ok
21+
foo();
2222
}

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:21: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)