-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Support multiple stability attributes on items #131824
base: master
Are you sure you want to change the base?
Conversation
r? @wesleywiser rustbot has assigned @wesleywiser. Use |
Some changes occurred in src/librustdoc/clean/types.rs cc @camelid These commits modify the If this was unintentional then you should revert the changes before this PR is merged. |
This comment has been minimized.
This comment has been minimized.
ebf7852
to
14b8556
Compare
☔ The latest upstream changes (presumably #132020) made this pull request unmergeable. Please resolve the merge conflicts. |
14b8556
to
6561424
Compare
☔ The latest upstream changes (presumably #132027) made this pull request unmergeable. Please resolve the merge conflicts. |
6561424
to
0a730d9
Compare
☔ The latest upstream changes (presumably #131985) made this pull request unmergeable. Please resolve the merge conflicts. |
0a730d9
to
86fac38
Compare
☔ The latest upstream changes (presumably #131349) made this pull request unmergeable. Please resolve the merge conflicts. |
86fac38
to
88e33bf
Compare
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
cc @RalfJung @compiler-errors This rebase was pretty substantial and required some minor refactors. Would either of you mind giving the const-stability parts a look to make sure they make sense and don't go against planned future changes? cc @rust-lang/libs-api I realize I should probably ping here as well. Does the design supporting a mix of unstable/stable attributes sound good? I'll try documenting it in the dev guide and std dev guide once that's finalized. |
☔ The latest upstream changes (presumably #131284) made this pull request unmergeable. Please resolve the merge conflicts. |
The PR should explain what the semantics are of having multiple
That sounds really strange. What is the semantics of this? And what is the point? |
compiler/rustc_attr/src/builtin.rs
Outdated
Unstable { unstables: SmallVec<[Unstability; 1]> }, | ||
/// For functions with no explicit const-stability attribute that require checking recursive | ||
/// const stability. This is either an unmarked const fn or a `const_stable_indirect` intrinsic. | ||
Implicit, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rename this to ImplicitUnstable
, because we never want anything to be "implicitly stable".
Also FWIW this variant will disappear when I have the time to continue working on the const stability checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Do you think this should be blocked on that being merged?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think this should be blocked on that being merged?
Not sure which timeline you are on. I don't know when I will get around to writing my planned PRs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My PR is now up: #132541
I've updated the PR description to address this. To your second point, I'm working off of this specification. Treating it as a matter of preference, I decided to implement it both with and without support for multiple |
88e33bf
to
bc6c3b0
Compare
The updated PR description is great, thanks. :) Personally I don't think multiple stable attributes, or both stable and unstable, are worth it. But let's see what t-libs-api thinks. |
☔ The latest upstream changes (presumably #132145) made this pull request unmergeable. Please resolve the merge conflicts. |
bc6c3b0
to
5a1fd55
Compare
☔ The latest upstream changes (presumably #132435) made this pull request unmergeable. Please resolve the merge conflicts. |
That will also make reviewing this PR a lot easier by reducing the noise in the diff. :) |
…ckticks, r=compiler-errors Use backticks instead of single quotes for library feature names in diagnostics This PR changes the text of library feature errors for using unstable or body-unstable items. Displaying library feature names in backticks is consistent with other diagnostics (e.g. those from `rustc_passes`) and with the `reason`s on unstable attributes in the library. Additionally, this simplifies diagnostics when supporting multiple unstable attributes on items (see rust-lang#131824) since `DiagSymbolList` also displays symbols using backticks.
…ckticks, r=compiler-errors Use backticks instead of single quotes for library feature names in diagnostics This PR changes the text of library feature errors for using unstable or body-unstable items. Displaying library feature names in backticks is consistent with other diagnostics (e.g. those from `rustc_passes`) and with the `reason`s on unstable attributes in the library. Additionally, this simplifies diagnostics when supporting multiple unstable attributes on items (see rust-lang#131824) since `DiagSymbolList` also displays symbols using backticks.
Rollup merge of rust-lang#132544 - dianne:unstable-library-feature-backticks, r=compiler-errors Use backticks instead of single quotes for library feature names in diagnostics This PR changes the text of library feature errors for using unstable or body-unstable items. Displaying library feature names in backticks is consistent with other diagnostics (e.g. those from `rustc_passes`) and with the `reason`s on unstable attributes in the library. Additionally, this simplifies diagnostics when supporting multiple unstable attributes on items (see rust-lang#131824) since `DiagSymbolList` also displays symbols using backticks.
☔ The latest upstream changes (presumably #132603) made this pull request unmergeable. Please resolve the merge conflicts. |
765cdd3
to
e393929
Compare
☔ The latest upstream changes (presumably #132626) made this pull request unmergeable. Please resolve the merge conflicts. |
I just learned about this PR, and I just wanted to note that this will be a giant conflict with #131229. That should in no way stop us from going forward with this, but it is something that's good to know. Whoever happens to merge their changes first will force the other to retrofit their changes onto it haha, but with some luck for you, that'll be me who has to do the retrofitting :3 |
We discussed this in the libs-api meeting today and we're happy with this as proposed. Support for multiple |
I've been wondering about this. My one hope if I do the rebase is that the attribute rework will make this cleaner in the end. 😅
Nice! I'll get to work on documenting it soon. |
It probably will, the reason it's annoying is that in my local version, builtins.rs is simply gone. It's split up into files for all the different attributes that are processed there. So we'll just have to find the parts that have to move, should be doable. |
This moves stability structs' `feature` fields into `StabilityLevel::Unstable` and `ConstStabilityLevel::Unstable`, in preparation to support multiple unstable attributes on items. Seemingly, the `feature` field isn't used with the `StabilityLevel::Stable` variant, so I haven't included it. `rustc_passes::lib_features` uses the 'feature' meta-item for 'stable' attributes, but it extracts them itself, rather than relying on `rustc_attr`. In order to support the new const stability check rules, this additionally introduces `ConstStabilityLevel` and moves the case of `feature` being `None` to the `Implicit` variant for clarity; having it correspond to an empty `unstables` vec seems like it would be a footgun.
…ions the logic for adding unstable attrs gets a bit messier when supporting multiple instances thereof. this keeps that from being duplicated in 3 places.
…els" errors this makes things a little cleaner. since multiple stability levels are allowed, I think it makes sense too.
An item is unstable if it has any unstable attributes, to make it easier to track which features library items depended on as they stabilize. This changes the text for E0544. Unfortunately, the example doesn't make much sense anymore. The way this merges stability levels together is made to work for stability-checking and rustdoc; as far as I can tell, only `rustc_passes::lib_features` needs them separate, and it extracts them itself.
- only emits one error/lint (instead of one per missing feature) per usage of unstable and body-unstable items - only emits one future-name-collision lint (instead of one per missing feature) for unstable trait items - makes diagnostics for unstable, soft-unstable, const-unstable, and body-unstable library features translatable, using common subdiagnostic structs. - adds notes with features, reasons, and issue links to const-unstability errors - adds notes with issue links to soft_unstable lints - on nightly, adds `#![feature]` crate attr help to soft_unstable lints - on nightly, adds compiler-upgrade-suggestion notes to const-unstable and soft_unstable diagnostics
Reasons provided on `#[unstable]` attributes are now per-item rather than per-feature. This is how they mostly are used anyway, and it simplifies both the implementation and the diagnostics themselves.
It doesn't make sense for something to be partially soft, and allowing inconsistent softness markers would risk an item accidentally becoming properly unstable as its features stabilize.
On nightly, there's a suggestion/help containing the `#![feature(..)]` attribute required to enable any required unstable features, so the note listing the features is unnecessary. This only applies to const-unstable and default-body-unstable errors. Normal "use of unstable library feature" errors list the features in the error message, so it doesn't feel redundant.
e393929
to
b9af36e
Compare
Some changes occurred to the CTFE machinery cc @rust-lang/wg-const-eval |
Is that a new notification? Unless I made a mistake, I think all I did was resolve the merge conflict straightforwardly, so see the above discussion for how this touches the CTFE machinery. |
We changed the notification settings recently and apparently that triggers a new notification.
|
Motivation
Many unstable library items require the stabilization of multiple features before they can be stabilized. By allowing them to be annotated with multiple
#[unstable]
attributes, this prevents their accidental stabilization when some of those features are stabilized, and helps mitigate upgrade pains for unstable toolchain users.New stability attribute semantics
In the most recent commit, the way it works is:
#[unstable]
attribute is present on an item, it is unstable. Likewise, any#[rustc_const_unstable]
marks an item as const-unstable, and any#[rustc_default_body_unstable]
marks it as default body-unstable.#[unstable]
attributes must be enabled. Conceptually, this is because it depends on multiple unstable features. Practically, this also means nightly toolchain users are less likely to need to replace one unstable feature gate with another in their crate-level attributes.#[stable]
attributes may be present to document the stabilized features an item depended on. The stabilization version of an item is the most recent stabilization version in present#[stable]
attributes. Likewise,#[stable]
attributes may be present on an unstable item to document stabilized features it formerly depended on. From what I understand, this is non-essential, but I figured I'd implement it anyway so the libs-api team can decide whether it's helpful or confusing. This is done in a separate commit, so I can revert it if desired.New syntactic constraints
#[unstable]
attribute on an item may have areason
provided (and likewise for#[rustc_const_unstable]
and#[rustc_default_body_unstable]
). At a glance, thereason
meta-item was used to describe the reason for an item being unstable, rather than an individual feature it depends on. Enforcing this makes the diagnostic formatting much cleaner.#[unstable]
attribute on an item has asoft
marker, it must be present on all#[unstable]
attributes on that item. Items can't be partially soft-unstable, and this helps prevent accidentally making a soft-unstable item unusable on stable when stabilizing one of the features it requires.Fixes #94770
Based on #94988
PR for a diagnostic formatting change this uses: #132544
I have some notes I'd like input on, in case they're messy or contentious. I tried to isolate some of these into their own commits, so see those for more info (sorry some of the commits are still giant! stability attributes seem to be used in a lot of places).
rustc_passes::lib_features
also reads stability attributes, but it parses them itself. I considered it out of the scope of this PR refactor that too, but if attribute handling is reworked to be more unified in the future, this may need further adjustment (but hopefully not too much).#[stable]
attributes, and a mix of#[stable]
and#[unstable]
, in case that's helpful for tracking which features library items depended on as they stabilize (and because it's less difficult to rewordE0544
this way).E0544
(multiple stability levels). Should the error code be different now, or is reusing the same one okay?rustc_passes::lib_features
catches instances of the same feature being given different stability levels or stabilization versions, so the only error it uniquely catches is when the same stability level is given multiple times (potentially with different reasons, issue numbers,implied_by
s, orrustc_allowed_through_unstable_modules
s).#[unstable]
attribute, this usesSmallVec<[_; 1]>
for storage. Is this assumption sound? I haven't done any performance testing.feature_err_issue
is no longer used for library features. I've left it for now sincefeature_warn_issue
is in a similar state.report_unstable
andsoft_unstable
could now take a crate-level attribute injection span to letcheck_optional_stability
provide that when possible for suggestions on nightly. At the moment it doesn't, since it'd be even more test stderr updates (including a new error emitted fromui-fulldeps/hash-stable-is-unstable.rs
since it wouldn't get de-duplicated).StabilityLevel
no longer hasCopy
, stability structs are now arena-allocated. I'm not sure what the performance implications are. I'm sure you could get away with putting less in the arena by doing something more complicated, if it's an issue.This doesn't update any libraries to add additional unstable attributes to items that should have them.