Skip to content

Wrong type mismatch with cfg_if! in function body #12940

Closed

Description

This code reports an incorrect "expected MemoryUsage, found ()" type mismatch error:

cfg_if! {
if #[cfg(all(feature = "jemalloc", not(target_env = "msvc")))] {
jemalloc_ctl::epoch::advance().unwrap();
MemoryUsage {
allocated: Bytes(jemalloc_ctl::stats::allocated::read().unwrap() as isize),
}
} else if #[cfg(all(target_os = "linux", target_env = "gnu"))] {
memusage_linux()
} else if #[cfg(windows)] {
// There doesn't seem to be an API for determining heap usage, so we try to
// approximate that by using the Commit Charge value.
use winapi::um::processthreadsapi::*;
use winapi::um::psapi::*;
use std::mem::{MaybeUninit, size_of};
let proc = unsafe { GetCurrentProcess() };
let mut mem_counters = MaybeUninit::uninit();
let cb = size_of::<PROCESS_MEMORY_COUNTERS>();
let ret = unsafe { GetProcessMemoryInfo(proc, mem_counters.as_mut_ptr(), cb as u32) };
assert!(ret != 0);
let usage = unsafe { mem_counters.assume_init().PagefileUsage };
MemoryUsage { allocated: Bytes(usage as isize) }
} else {
MemoryUsage { allocated: Bytes(0) }
}
}

Might be due to incorrect handling of macros in block tail position.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Labels

A-macromacro expansionA-tytype system / type inference / traits / method resolutionC-bugCategory: bugS-actionableSomeone could pick this issue up and work on it right now

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions