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

Support multiple stability attributes on items #131824

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

dianne
Copy link
Contributor

@dianne dianne commented Oct 17, 2024

Fixes #94770

Based on #94988

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).

  • Stability structs are specialized to how they're used for stability checking and rustdoc. 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).
  • This supports multiple #[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 reword E0544 this way).
  • This changes 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_bys, or rustc_allowed_through_unstable_moduless).
  • Under the assumption that most library items will still have at most one #[unstable] attribute, this uses SmallVec<[_; 1]> for storage. Is this assumption sound? I haven't done any performance testing.
  • To avoid reporting multiple errors for a single unstable same item use (while messing minimally with diagnostic machinery for unstable language features), I've separated out the diagnostics for library features. I'm not sure about the formatting, though; I think it might be too complicated. This also unifies handling for unstable, soft-unstable, const-unstable, and default-body-unstable diagnostics, so some of those have information now that they were lacking before.
  • feature_err_issue is no longer used for library features. I've left it for now since feature_warn_issue is in a similar state.
  • report_unstable and soft_unstable could now take a crate-level attribute injection span to let check_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 from ui-fulldeps/hash-stable-is-unstable.rs since it wouldn't get de-duplicated).
  • Since StabilityLevel no longer has Copy, 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.

This is a refactor for supporting 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`.
…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.
…e library feature `feature`"

This is consistent with all other diagnostics I could find containing features and enables the use
of `DiagSymbolList` for generalizing diagnostics for unstable library features to multiple features.
@rustbot
Copy link
Collaborator

rustbot commented Oct 17, 2024

r? @wesleywiser

rustbot has assigned @wesleywiser.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Oct 17, 2024
@rustbot
Copy link
Collaborator

rustbot commented Oct 17, 2024

Some changes occurred in src/librustdoc/clean/types.rs

cc @camelid

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

@rust-log-analyzer

This comment has been minimized.

- 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
At least one test relies on this behavior, so I think the description is still correct.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. 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.

Allow multiple #[unstable] attributes on one item
4 participants