Skip to content

Conversation

@nilotpal-n7
Copy link
Contributor

PR: Add support for removed library features

Overview

This PR extends the Rust stability system to handle removed library features. The new attribute #[unstable_removed] can be applied to APIs that have been permanently removed from the standard library. This ensures removed items always produce an error when referenced.

The approach follows the existing stability infrastructure (#[unstable], #[stable]), introducing a new Removed state with dedicated compiler diagnostics.


Implementation details

  • New attribute:

    #[unstable_removed(
        feature = "removed_example",
        since = "1.89.0",
        issue = "123456",
        reason = "testing removed feature"
    )]
  • Library integration:

    • Fake removed items are defined in library/core/src/removed_lib_features.rs.
    • These serve as test cases and examples of usage.
  • Compiler changes:

    • Extended stability handling to include StabilityLevel::Removed.

    • Updated checks in:

      • rustc_const_eval → reports errors on evaluation of removed consts.
      • rustc_hir_analysis → enforces removed status during analysis.
      • rustc_passes → detects duplicates and unused/invalid declarations.
      • rustc_resolve → reports errors for removed macros and intrinsic resolution.
  • Validation: Missing fields (since, issue) are rejected with compiler errors.


Flow

  1. A library item is annotated with #[unstable_removed].
  2. During HIR lowering and stability passes, it is recognized as Removed.
  3. Any reference to such an item triggers a hard error (E0658).
  4. Compiler ensures consistency across all passes and diagnostics.

Testing

  • Location: UI tests under tests/ui/stability-attribute/.

  • Coverage:

    • Direct use of removed items.
    • Removed trait functions and associated constants.
    • Intrinsic wrappers.
    • Invalid attributes (missing since, issue).
    • Duplicate stability declarations (removed vs stable/unstable).

What’s left / To Fix

  • Error codes: All new diagnostics currently reuse existing errors (e.g., E0658). Explicit, dedicated error codes should be added for clarity.
  • Lang/intrinsics distinction: Real intrinsics and lang items aren’t yet cleanly separated in the removed-feature handling. Right now, only simulated intrinsics are tested.
  • Polish: Some duplicated error emissions (e.g., trait fn + trait impl both firing) could be made cleaner.

Issue: #141617

@rustbot
Copy link
Collaborator

rustbot commented Sep 14, 2025

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

Some changes occurred to constck

cc @fee1-dead

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann

Some changes occurred in exhaustiveness checking

cc @Nadrieril

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) 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-libs Relevant to the library 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. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Sep 14, 2025
@rustbot
Copy link
Collaborator

rustbot commented Sep 14, 2025

r? @nnethercote

rustbot has assigned @nnethercote.
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

@RalfJung
Copy link
Member

RalfJung commented Sep 14, 2025

Note that this is not the design that was proposed at #141617 (comment). The proposal was to have a crate-level attribute (#![unstable_removed(feature = "...", reason = "...", issue = "...", since = "...")]) -- basically a bit of metadata attached to a crate that says "there also used to be the following features here".

What is the point of marking an existing item as being removed? The item clearly still exists, otherwise it couldn't carry the attribute.^^

I already noted on your previous PR that having a new StabilityLevel for this makes little sense.

@rust-log-analyzer
Copy link
Collaborator

The job tidy failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
fmt: checked 6372 files
tidy check
Checking tidy rustdoc_json...
No error code explanation was removed!
tidy error: /checkout/compiler/rustc_const_eval/messages.ftl: message `The intrinsic `` starts with an uppercase letter. Fix it or add it to `ALLOWED_CAPITALIZED_WORDS`
tidy: Skipping binary file check, read-only filesystem
removing old virtual environment
creating virtual environment at '/checkout/obj/build/venv' using 'python3.10' and 'venv'
creating virtual environment at '/checkout/obj/build/venv' using 'python3.10' and 'virtualenv'
Requirement already satisfied: pip in ./build/venv/lib/python3.10/site-packages (25.2)
---
info: ES-Check: there were no ES version matching errors!  🎉
typechecking javascript files
some tidy checks failed
Bootstrap failed while executing `test src/tools/tidy tidyselftest --extra-checks=py,cpp,js,spellcheck`
Command `/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools-bin/rust-tidy /checkout /checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo /checkout/obj/build 4 /node/bin/npm --extra-checks=py,cpp,js,spellcheck` failed with exit code 1
Created at: src/bootstrap/src/core/build_steps/tool.rs:1556:23
Executed at: src/bootstrap/src/core/build_steps/test.rs:1281:29

Command has failed. Rerun with -v to see more details.
Build completed unsuccessfully in 0:03:24
  local time: Sun Sep 14 20:26:23 UTC 2025
  network time: Sun, 14 Sep 2025 20:26:24 GMT
##[error]Process completed with exit code 1.
Post job cleanup.

@nilotpal-n7

This comment was marked as spam.

@RalfJung
Copy link
Member

Sorry, I don't have the time to give a lot of detailed guidance here. You can always ask on Zulip.

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 14, 2025
@nilotpal-n7 nilotpal-n7 deleted the remove-library-feature branch October 18, 2025 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library 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. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants