Skip to content

Commit c7d16df

Browse files
committed
add function calls
1 parent d1294e0 commit c7d16df

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,24 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
242242
match terminator.kind {
243243
TerminatorKind::Goto { target } => Some(Some(target)),
244244
TerminatorKind::Return => Some(None),
245+
TerminatorKind::Call {
246+
ref func,
247+
ref args,
248+
destination: Some((ref place, target)),
249+
cleanup: _,
250+
from_hir_call: true,
251+
fn_span: _,
252+
} => {
253+
let local = place.as_local()?;
254+
let func = self.operand_to_node(func)?;
255+
let args = self.tcx.arena.alloc_from_iter(
256+
args.iter()
257+
.map(|arg| self.operand_to_node(arg))
258+
.collect::<Option<Vec<NodeId>>>()?,
259+
);
260+
self.locals[local] = self.nodes.push(Node::FunctionCall(func, args));
261+
Some(Some(target))
262+
}
245263
TerminatorKind::Assert { ref cond, expected: false, target, .. } => {
246264
let p = match cond {
247265
mir::Operand::Copy(p) | mir::Operand::Move(p) => p,
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// run-pass
2+
#![feature(const_generics, const_evaluatable_checked)]
3+
#![allow(incomplete_features)]
4+
5+
const fn test_me<T>(a: usize, b: usize) -> usize {
6+
if a < b {
7+
std::mem::size_of::<T>()
8+
} else {
9+
std::usize::MAX
10+
}
11+
}
12+
13+
fn test_simple<T>() -> [u8; std::mem::size_of::<T>()]
14+
where
15+
[u8; std::mem::size_of::<T>()]: Sized,
16+
{
17+
[0; std::mem::size_of::<T>()]
18+
}
19+
20+
fn test_with_args<T, const N: usize>() -> [u8; test_me::<T>(N, N + 1) + N]
21+
where
22+
[u8; test_me::<T>(N, N + 1) + N]: Sized,
23+
{
24+
[0; test_me::<T>(N, N + 1) + N]
25+
}
26+
27+
fn main() {
28+
assert_eq!([0; 8], test_simple::<u64>());
29+
assert_eq!([0; 12], test_with_args::<u64, 4>());
30+
}

0 commit comments

Comments
 (0)