Stream: t-compiler/help

Topic: cx.tcx.is_promotable_const_fn is false for const fn


lzutao (Jun 04 2020 at 03:15, on Zulip):

For example this snippet:

pub fn skip_const_fn() {
    const fn foo(v: i32) -> Option<i32> {
        Some(v)
    }
    let _ = None.or(foo(42));
    let opt = Some(1);
    let _ = opt.or(Some(2));
}

cx.tcx.is_promotable_const_fn is false for foo.
The documentation

lzutao (Jun 04 2020 at 03:59, on Zulip):

Now I am using rustc_mir::const_eval::is_const_fn

oli (Jun 04 2020 at 07:20, on Zulip):

is_promotable_const_fn is an internal hack used for a specific purpose. It's related to the #[rustc_promotable] attribute and both should not be used lightly

Last update: Sep 28 2020 at 15:15UTC