Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I probe for const generics support? #31

Closed
cole-miller opened this issue Jan 16, 2021 · 3 comments
Closed

Can I probe for const generics support? #31

cole-miller opened this issue Jan 16, 2021 · 3 comments

Comments

@cole-miller
Copy link

I'd like to probe support for (minimal) const generics by checking this code:

type A<const N: usize> = [(); N];

But this can't be done with probe_type and I'm not sure how else to do it (other than maybe probe_rustc_version which seems kind of awkward). Any workarounds?

@cole-miller
Copy link
Author

cole-miller commented Jan 16, 2021

This seems to work:

fn main() {
    let ac = autocfg::new();
    ac.emit_expression_cfg(
        r#"{ struct A<const N: usize>([(); N]); A([]) }"#,
        "have_const_generics",
    );
}

But if there's a nicer way I'd love to know about it! (Otherwise feel free to close this.)

@cuviper
Copy link
Owner

cuviper commented Jan 19, 2021

There's no direct support for item definitions, which is what you'd need to test this, but I think a block expression is reasonable. You could also do that with emit_constant_cfg, but the constraints there are really about constant evaluation.

Did you add A([]) to avoid unused warning spew? I might change it to start hiding output by default for #30.

@cole-miller
Copy link
Author

Did you add A([]) to avoid unused warning spew?

No, it was just a reflex :P (I wasn't thinking about implicit () return). The unused warning doesn't bother me especially since it only shows up with -vv and this is the only thing in my build.rs currently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants