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

Show since when a function is const in stdlib #79548

Merged
merged 1 commit into from
Dec 1, 2020

Conversation

CraftSpider
Copy link
Contributor

Fixes #76998

This makes it so that functions with the #[rustc_const_stable()] attribute now show from what version they were stably declared const, alongside what version they were declared stable. Example from Result:
image

r? @jyn514

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 30, 2020
@jyn514
Copy link
Member

jyn514 commented Nov 30, 2020

That was quick!

@jyn514 jyn514 added A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Nov 30, 2020
let ver = ver.and_then(|inner| if !inner.is_empty() { Some(inner) } else { None });

let const_ver = const_ver.and_then(|inner| if !inner.is_empty() { Some(inner) } else { None });

if let Some(v) = ver {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No else because there shouldn't be such a thing as 'stably const but not stable'

Copy link
Member

@jyn514 jyn514 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"<span class=\"since\" title=\"Stable since Rust version {0}\">{0}</span>",
v
);
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you assert here that const_ver.is_none(), and add an error earlier (in from_def_id_and_parts, since that's the only place const_stability isn't None) if const_stability is set but not stability? If you're feeling really ambitious, you could make it part of the type system in Item and have stability: Option(Stability, Option<ConstStability>).

@jyn514
Copy link
Member

jyn514 commented Nov 30, 2020

@bors r+

After thinking about this more, I realized that 'rustc_const_stable must have stable' isn't currently enforced by the compiler, so it shouldn't be enforced by rustdoc either. Adding that restriction seems like it should be separate from displaying the attribute.

@bors
Copy link
Contributor

bors commented Nov 30, 2020

📌 Commit ccbb0f5 has been approved by jyn514

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 30, 2020
@CraftSpider
Copy link
Contributor Author

Opened #79551 to address the rustc side

m-ou-se added a commit to m-ou-se/rust that referenced this pull request Dec 1, 2020
Show since when a function is const in stdlib

Fixes rust-lang#76998

This makes it so that functions with the `#[rustc_const_stable()]` attribute now show from what version they were stably declared const, alongside what version they were declared stable. Example from `Result`:
![image](https://user-images.githubusercontent.com/13342132/100561194-1be60d00-3286-11eb-99ff-1e81201218a9.png)

r? `@jyn514`
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 1, 2020
Rollup of 11 pull requests

Successful merges:

 - rust-lang#79038 (Change ui test that are run-pass and that do not test the compiler to library tests)
 - rust-lang#79184 (Stop adding '*' at the end of slice and str typenames for MSVC case)
 - rust-lang#79227 (Remove const_fn_feature_flags test)
 - rust-lang#79444 (Move const ip in ui test to unit test)
 - rust-lang#79522 (Validate lint docs separately.)
 - rust-lang#79525 (Add -Z normalize-docs and enable it for compiler docs)
 - rust-lang#79527 (Move intra-doc link tests into a subdirectory)
 - rust-lang#79548 (Show since when a function is const in stdlib)
 - rust-lang#79568 (update Miri)
 - rust-lang#79573 (Update with status for various NetBSD ports.)
 - rust-lang#79583 (Update books)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 33d7b8c into rust-lang:master Dec 1, 2020
@rustbot rustbot added this to the 1.50.0 milestone Dec 1, 2020
@jyn514 jyn514 mentioned this pull request Dec 2, 2020
@CraftSpider CraftSpider deleted the 76998 branch January 14, 2021 18:23
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. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Standard library rustdoc: show since when a function is const
5 participants