Stream: t-compiler

Topic: cfg to detect stable / unstable


gnzlbg (Sep 16 2019 at 14:26, on Zulip):

is there a way for libcore/libstd macros to detect whether the toolchain is a stable or unstable toolchain ?

gnzlbg (Sep 16 2019 at 14:27, on Zulip):

we currently have a bug in which is_x86_feature_detected!("unstable-target-feature") works on stable

gnzlbg (Sep 16 2019 at 14:27, on Zulip):

that macro looks like:

macro_rules! is_x86_feature_detected {
  ("avx") => { ... }
  ("some-unstable-feature") => { ... }
  ($tt:tt) => { compile_error!("unknown target feature: {}", $tt) }
}
gnzlbg (Sep 16 2019 at 14:29, on Zulip):

but I can't place a stability attribute in the macro arms

gnzlbg (Sep 16 2019 at 14:30, on Zulip):

I suppose I could do something like:

("unstable-feature") => {
     #[unstable(...)] fn foo() { ... } foo()
}

instead

gnzlbg (Sep 16 2019 at 14:43, on Zulip):

but this errors with: error: stability attributes may not be used outside of the standard library

gnzlbg (Sep 16 2019 at 14:44, on Zulip):

apparently because the macro expands code to a user crate that uses the stability attribute

gnzlbg (Sep 16 2019 at 14:45, on Zulip):

(i'm using #[allow_internal_unstable(staged_api)] on the macro though)

RalfJ (Sep 16 2019 at 16:59, on Zulip):

staged_api AFAIK is a crate-level attribute and has no effect when used elsewhere

gnzlbg (Sep 16 2019 at 23:48, on Zulip):

So I didn't manage to expand the function items in the macro, but I'm expanding a new module inside libstd that contains the functions, and have the macro expand calls to those.

gnzlbg (Sep 16 2019 at 23:49, on Zulip):

However, user code is not failing to compile when using unstable APIs from this module via the macro

gnzlbg (Sep 16 2019 at 23:49, on Zulip):

:/

Last update: Nov 20 2019 at 02:40UTC