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

rustc_const_unstable should check constness #69630

Closed
DutchGhost opened this issue Mar 2, 2020 · 6 comments · Fixed by #86838
Closed

rustc_const_unstable should check constness #69630

DutchGhost opened this issue Mar 2, 2020 · 6 comments · Fixed by #86838
Assignees
Labels
A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. A-stability Area: `#[stable]`, `#[unstable]` etc. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@DutchGhost
Copy link
Contributor

The rustc_const_unstable attribute currently does not check whether the function it is applied upon is indeed a const fn. I feel like it should check that.

I recently made the mistake of forgetting to mark the function const: #69617 (comment)

ping @oli-obk

@jonas-schievink jonas-schievink added A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. A-stability Area: `#[stable]`, `#[unstable]` etc. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 2, 2020
@oli-obk
Copy link
Contributor

oli-obk commented Mar 2, 2020

Oh yea, that's a good idea. Note that this can't be done for intrinsics at this point, so you need to make sure to only check extern "Rust" functions

@DutchGhost
Copy link
Contributor Author

I'd be happy and try to implement this. However Im not verry familiar with the compiler structure.
As far as I understood, rust_const_unstable isn't realy a macro, but more an attribute used by the compiler. With some help on where to start, I'd like to give this a try!

@oli-obk
Copy link
Contributor

oli-obk commented Mar 6, 2020

I didn't find a good entry point. I guess you could pass i into

self.annotate(i.hir_id, &i.attrs, i.span, kind, |v| intravisit::walk_item(v, i));
instead of the various i fields and then check i.kind in for https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/enum.ItemKind.html#variant.Fn and check whether it's const (and doesn't have intrinsic Abi). Not sure how messy that gets, but if it's fairly contained, that seems ok to me.

@lambinoo
Copy link
Contributor

lambinoo commented Jul 3, 2021

I am interested in working on this! Could I get assigned to this? I already have a PR for this I think

@LeSeulArtichaut
Copy link
Contributor

@lambinoo You can use the @rustbot claim command

@lambinoo
Copy link
Contributor

lambinoo commented Jul 5, 2021

Oooh, thanks! :D

JohnTitor added a commit to JohnTitor/rust that referenced this issue Jul 7, 2021
…e_check_const, r=oli-obk

Checking that function is const if marked with rustc_const_unstable

Fixes rust-lang#69630

This one is still missing tests to check the behavior but I checked by hand and it seemed to work.
I would not mind some direction for writing those unit tests!
@bors bors closed this as completed in d85718a Jul 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. A-stability Area: `#[stable]`, `#[unstable]` etc. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants