Skip to content

Implement unstable trait impl #140399

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

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

Implement unstable trait impl #140399

wants to merge 36 commits into from

Conversation

tiif
Copy link
Member

@tiif tiif commented Apr 28, 2025

This PR allows marking impls of stable trait with stable type as unstable.

The design and mentoring are done by @BoxyUwU

@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-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Apr 28, 2025
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@BoxyUwU BoxyUwU self-assigned this May 27, 2025
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Jun 10, 2025

☔ The latest upstream changes (presumably #142299) made this pull request unmergeable. Please resolve the merge conflicts.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Jun 14, 2025

☔ The latest upstream changes (presumably #142483) made this pull request unmergeable. Please resolve the merge conflicts.

Copy link
Member

@BoxyUwU BoxyUwU left a comment

Choose a reason for hiding this comment

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

gg gamer

Comment on lines 840 to 842
fn enabled(self, symbol: <TyCtxt<'tcx> as Interner>::Symbol) -> bool {
self.enabled(symbol)
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fn enabled(self, symbol: <TyCtxt<'tcx> as Interner>::Symbol) -> bool {
self.enabled(symbol)
}
fn feature_bound_holds_in_crate(self, symbol: <TyCtxt<'tcx> as Interner>::Symbol) -> bool {
// We don't consider feature bounds to hold in the crate if we `staged_api` feature is
// even when the feature is enabled. This is to prevent accidentally leaking unstable APIs
// to stable.
!self.staged_api() && self.enabled(symbol)
}

Copy link
Member Author

@tiif tiif Jun 20, 2025

Choose a reason for hiding this comment

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

I tweaked the comment by a little bit

        // We don't consider feature bounds to hold in the crate when `staged_api` feature is
        // enabled, even if it is enabled through `#[feature]`. 
        // This is to prevent accidentally leaking unstable APIs to stable.

hope this captured what you intended to say :D

Copy link
Member

Choose a reason for hiding this comment

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

👍 I also meant to entirely remove the enabled function though, I don't think its an API we need to expose if we have feature_bound_holds_in_crate being used by the new solver

Copy link
Member Author

Choose a reason for hiding this comment

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

oh yea makes sense.

//
// Note: we don't consider a feature to be enabled
// if we are in std/core even if there is a corresponding `feature` attribute on the crate.
if (!self.selcx.tcx().features().staged_api()
Copy link
Member Author

@tiif tiif Jun 20, 2025

Choose a reason for hiding this comment

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

I tried to use feature_bound_holds_in_crate in the old solver, just like what is done in the new solver, but it requires rustc_type_ir::inherent::*, and has scary message

error: do not use `rustc_type_ir::inherent` unless you're inside of the trait solver
  --> compiler/rustc_trait_selection/src/traits/fulfill.rs:15:20
   |
15 | use rustc_type_ir::inherent::*;
   |                    ^^^^^^^^
   |
   = note: the method or struct you're looking for is likely defined somewhere else downstream in the compiler
   = note: `-D rustc::usage-of-type-ir-inherent` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(rustc::usage_of_type_ir_inherent)]`

so i decided to just write it out manually :)

Copy link
Member

Choose a reason for hiding this comment

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

Yeah only the new solver needs to use the fancy API, old solver can just do the logic manually

Comment on lines 8 to 9
#[unstable_feature_bound(feat_bar)]
//~^ ERROR: stability attributes may not be used outside of the standard library
Copy link
Member Author

Choose a reason for hiding this comment

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

Do we want to change the error message to unstable_feature_bound may not be used outside of the standard library or it is acceptable to call it stability attribute?

Copy link
Member

Choose a reason for hiding this comment

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

i think its okay as-is

@tiif tiif changed the title WIP: Unstable impls Implement unstable trait impl Jun 21, 2025
@tiif
Copy link
Member Author

tiif commented Jun 23, 2025

I am leaving the conflicts there because I don't want to rebase for now (the conflict also happens quite frequently), so it would be easier for boxy to review.

hi @jdonszelmann, it'd be nice to get a vibeck from you for the attribute change :)

@tiif tiif marked this pull request as ready for review June 23, 2025 13:50
@rustbot
Copy link
Collaborator

rustbot commented Jun 23, 2025

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann

changes to the core type system

cc @compiler-errors, @lcnr

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann

changes to inspect_obligations.rs

cc @compiler-errors, @lcnr

Some changes occurred in compiler/rustc_attr_data_structures

cc @jdonszelmann

@jdonszelmann
Copy link
Contributor

Hi tiff! Will review this week :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants