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

It is currently not possible to tell if a function or method is a const fn by reading documentation, as rustdoc does not retain the const keyword in const fn declarations #76478

Closed
slightlyoutofphase opened this issue Sep 8, 2020 · 6 comments

Comments

@slightlyoutofphase
Copy link
Contributor

Basically, a function written for example like this:

pub const fn add(a: i32, b: i32) -> i32 {
    a + b
}

is currently documented like this:

pub fn add(a: i32, b: i32) -> i32

but it would be nice if was instead documented like this:

pub const fn add(a: i32, b: i32) -> i32

@tesuji
Copy link
Contributor

tesuji commented Sep 8, 2020

Currently, in nightly std:
image

Stable:
image

@jonas-schievink
Copy link
Contributor

This should work fine, yeah. The only case in which rustdoc will (deliberately) omit the const is for const-unstable functions.

@slightlyoutofphase
Copy link
Contributor Author

slightlyoutofphase commented Sep 8, 2020

Hmmm, it's possible this is only a problem with struct member methods, and possibly not in all scenarios? I should have taken a closer look at other documentation first I guess.

That said, for example, in my crate's documentation here, the very first method shown, (specifically, new) is a const fn but is not displayed as such (as are none of the other const fn methods that struct has either).

@jonas-schievink
Copy link
Contributor

Can you provide a minimal reproduction for this to show up?

@slightlyoutofphase
Copy link
Contributor Author

Sure, I'll put one together later today when I have access to my normal dev setup.

@slightlyoutofphase
Copy link
Contributor Author

Just opened a new issue, as I narrowed it down to a very specific cause that consistently reproduces the problem.

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

3 participants