Skip to content

Add min_adt_const_params gate#153592

Merged
rust-bors[bot] merged 2 commits intorust-lang:mainfrom
zedddie:adt_const_params_restricted_privacy-gate
Apr 4, 2026
Merged

Add min_adt_const_params gate#153592
rust-bors[bot] merged 2 commits intorust-lang:mainfrom
zedddie:adt_const_params_restricted_privacy-gate

Conversation

@zedddie
Copy link
Copy Markdown
Contributor

@zedddie zedddie commented Mar 9, 2026

View all comments

Add min_adt_const_params feature gate to disallow ConstParamTy_ impl for types which fields visibility mismatches with struct itself

r? BoxyUwU

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 9, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 9, 2026

BoxyUwU is currently at their maximum review capacity.
They may take a while to respond.

/// Allows using the `unadjusted` ABI; perma-unstable.
(internal, abi_unadjusted, "1.16.0", None),
/// Restrict adt_const_params fields to share same privacy.
(internal, adt_const_params_restricted_privacy, "CURRENT_RUSTC_VERSION", None),
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I am really not sure on whether this should be internal or unstable (I guess should share issue number with adt_const_params, so it would be unstable then)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this can be unstable. the difference there is generally about whether we expect users to actually use this feature. internal is for when users arent supposed to use it, but unstable is for stuff we expect/hope/want to stabilize eventually.

Copy link
Copy Markdown
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.

thanks this looks good! can you change the feature to be min_adt_const_params and have it not depend on adt_const_params. i expect this will likely require updating any features().adt_const_params() feature checks across the compiler to also check for min_adt_const_params()

sorry for sending you down a different path initially

View changes since this review

@zedddie zedddie force-pushed the adt_const_params_restricted_privacy-gate branch from 04c868a to 2871ec1 Compare March 18, 2026 12:33
(unstable, marker_trait_attr, "1.30.0", Some(29864)),
/// Enable mgca `type const` syntax before expansion.
(incomplete, mgca_type_const_syntax, "1.95.0", Some(132980)),
/// Restrict adt_const_params fields to share same privacy.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

not sure about what should I write here as it will be a standalone feature

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would do similar wording to what's on the adt_const_params entry, so maybe:

Allows additional const parameter types, such as [u8; 10] or user defined types. User defined types must not have fields more private than the type itself.

/// Enable mgca `type const` syntax before expansion.
(incomplete, mgca_type_const_syntax, "1.95.0", Some(132980)),
/// Restrict adt_const_params fields to share same privacy.
(unstable, min_adt_const_params, "CURRENT_RUSTC_VERSION", Some(95174)),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
(unstable, min_adt_const_params, "CURRENT_RUSTC_VERSION", Some(95174)),
(unstable, min_adt_const_params, "CURRENT_RUSTC_VERSION", Some(154042)),

I've made a new tracking issue for this since we'll probably want a separate list of unresolved questions and whatnot 🤔

let struct_vis = tcx.visibility(adt.did());
for variant in adt.variants() {
for field in &variant.fields {
if field.vis != struct_vis {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add the following as a test:

#![feature(min_adt_const_params)]

use core::marker::ConstParamTy;

#[derive(ConstParamTy, Eq, PartialEq)]
struct Foo {
    pub field: u32,
}

I think this will fail under your PR due to using equality instead of checking fields are "at least as visible as the struct". I'm not really sure what the desired behaviour is but it'll need to figured out as part of the RFC and having a test which demonstrates the choice is useful.

Copy link
Copy Markdown
Contributor Author

@zedddie zedddie Mar 18, 2026

Choose a reason for hiding this comment

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

yes it will fail I think I tested this earlier, idk why I don't have this in test though. Will add to existing one

I see its better as the distinct test as it will show existing test doesn't require adt_const_params

@BoxyUwU
Copy link
Copy Markdown
Member

BoxyUwU commented Mar 18, 2026

implementation looks good to me, thanks for working on this :)

@zedddie zedddie changed the title Add adt_const_params_restricted_privacy gate Add min_adt_const_params gate Mar 18, 2026
return Ok(());
}

if tcx.features().min_adt_const_params() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I guess this should actually be if tcx.features().min_adt_const_params() && !tcx.features().adt_const_params() so that once we stabilize min_adt_const_params you can avoid the restriction by enabling full adt const params

Can you add a test that the following compiles:

#![feature(min_adt_const_params, adt_const_params)]

use core::marker::ConstParamTy;

#[derive(ConstParamTy, Eq, PartialEq)]
enum Foo {
    pub field: u32,
}

@zedddie zedddie force-pushed the adt_const_params_restricted_privacy-gate branch 2 times, most recently from fcb960a to 2c27a37 Compare March 18, 2026 16:12
@zedddie zedddie marked this pull request as ready for review March 22, 2026 19:16
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 22, 2026
return Ok(());
}

if tcx.features().min_adt_const_params() && !tcx.features().adt_const_params() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lol yeah I guess I didn't think deeply enough about the fact that this means you can implement ConstParamTy for arbitrary stuff if you don't enable any feature gate x)

Suggested change
if tcx.features().min_adt_const_params() && !tcx.features().adt_const_params() {
if !tcx.features().adt_const_params() {

I'll r+ once this is done

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Make sense, although even if they would implement ConstParamTy_ for their arbitrary struct, they couldn't use it anyway without min_adt_const_params or adt_const_params :> I am playing with tests a bit to include we ensurew this also without any gate

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

in theory you could have an unstable crate without min_adt_const_params and then a downstream crate which does enable it and can observe the broken impl and use it 🤔

Copy link
Copy Markdown
Contributor Author

@zedddie zedddie Mar 25, 2026

Choose a reason for hiding this comment

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

but if they would implement it with adt_const_params, they still can use this unrestricted impl with min_adt_const_params on another crate 🧐

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

aux:

#![allow(incomplete_features)]
#![feature(adt_const_params, const_param_ty_trait)]

use std::marker::ConstParamTy_;

#[derive(PartialEq, Eq)]
pub struct Fumo {
    cirno: i32,
    pub(crate) reimu: i32
}

impl ConstParamTy_ for Fumo {}

test:

//@aux-build:cross-crate-const_param_ty-impl-leak.rs
#![allow(incomplete_features)]
#![feature(min_adt_const_params)]

extern crate cross_crate_const_param_ty_impl_leak;

use cross_crate_const_param_ty_impl_leak::Fumo;

fn fumo_fn<const N: Fumo>() {}

fn main() {}

this passes for example

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

hmm yeah thats kinda weird lol. though it doesn't feel as bad to me because atleast someone enabled the feature gate for supporting private fields in const generics

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

eh I would add this test but it seems aux isn't supposed to fail -_-

@zedddie zedddie force-pushed the adt_const_params_restricted_privacy-gate branch from 2c27a37 to 4222812 Compare March 25, 2026 20:23
@rustbot

This comment was marked as outdated.

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-CI Area: Our Github Actions CI A-compiletest Area: The compiletest test runner A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) A-run-make Area: port run-make Makefiles to rmake.rs A-rustc-dev-guide Area: rustc-dev-guide A-testsuite Area: The testsuite used to check the correctness of rustc A-tidy Area: The tidy tool labels Mar 25, 2026
@rustbot rustbot removed A-CI Area: Our Github Actions CI T-clippy Relevant to the Clippy team. A-compiletest Area: The compiletest test runner A-attributes Area: Attributes (`#[…]`, `#![…]`) A-run-make Area: port run-make Makefiles to rmake.rs PG-exploit-mitigations Project group: Exploit mitigations T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) A-tidy Area: The tidy tool labels Mar 25, 2026
@Nadrieril
Copy link
Copy Markdown
Member

It happens 😁

Copy link
Copy Markdown
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.

this looks good to me. can you move the tests to be tests/ui/const-generics/min_adt_const_params rather than tests/ui/const-generics/adt_const_params/min_adt_const_params then I'll r+ :3

View changes since this review

@zedddie zedddie force-pushed the adt_const_params_restricted_privacy-gate branch from 11d5d14 to 72fbd1c Compare April 2, 2026 15:41
@BoxyUwU
Copy link
Copy Markdown
Member

BoxyUwU commented Apr 3, 2026

@bors r+

thx

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Apr 3, 2026

📌 Commit 72fbd1c has been approved by BoxyUwU

It is now in the queue for this repository.

@rust-bors rust-bors bot 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 Apr 3, 2026
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 3, 2026
…d_privacy-gate, r=BoxyUwU

Add  `min_adt_const_params` gate

Add `min_adt_const_params` feature gate to disallow `ConstParamTy_` impl for types which fields visibility mismatches with struct itself

r? BoxyUwU
rust-bors bot pushed a commit that referenced this pull request Apr 3, 2026
Rollup of 5 pull requests

Successful merges:

 - #153286 (various fixes for scalable vectors)
 - #153592 (Add  `min_adt_const_params` gate)
 - #154051 (use libm for acosh and asinh for f16, f32, and f64)
 - #154743 (Remove an unused `StableHash` impl.)
 - #154752 (Add comment to borrow-checker)
rust-bors bot pushed a commit that referenced this pull request Apr 3, 2026
Rollup of 7 pull requests

Successful merges:

 - #153286 (various fixes for scalable vectors)
 - #153592 (Add  `min_adt_const_params` gate)
 - #154675 (Improve shadowed private field diagnostics)
 - #154653 (Remove rustc_on_unimplemented's append_const_msg)
 - #154743 (Remove an unused `StableHash` impl.)
 - #154752 (Add comment to borrow-checker)
 - #154764 (Add tests for three ICEs that have already been fixed)
rust-bors bot pushed a commit that referenced this pull request Apr 3, 2026
Rollup of 7 pull requests

Successful merges:

 - #153286 (various fixes for scalable vectors)
 - #153592 (Add  `min_adt_const_params` gate)
 - #154675 (Improve shadowed private field diagnostics)
 - #154653 (Remove rustc_on_unimplemented's append_const_msg)
 - #154743 (Remove an unused `StableHash` impl.)
 - #154752 (Add comment to borrow-checker)
 - #154764 (Add tests for three ICEs that have already been fixed)
jhpratt added a commit to jhpratt/rust that referenced this pull request Apr 4, 2026
…d_privacy-gate, r=BoxyUwU

Add  `min_adt_const_params` gate

Add `min_adt_const_params` feature gate to disallow `ConstParamTy_` impl for types which fields visibility mismatches with struct itself

r? BoxyUwU
rust-bors bot pushed a commit that referenced this pull request Apr 4, 2026
Rollup of 10 pull requests

Successful merges:

 - #154376 (Remove more BuiltinLintDiag variants - part 4)
 - #127534 (feat(core): impl Step for NonZero<u*>)
 - #153286 (various fixes for scalable vectors)
 - #153592 (Add  `min_adt_const_params` gate)
 - #154675 (Improve shadowed private field diagnostics)
 - #154703 (Fix trailing comma in lifetime suggestion for empty angle brackets)
 - #154653 (Remove rustc_on_unimplemented's append_const_msg)
 - #154743 (Remove an unused `StableHash` impl.)
 - #154752 (Add comment to borrow-checker)
 - #154764 (Add tests for three ICEs that have already been fixed)
rust-bors bot pushed a commit that referenced this pull request Apr 4, 2026
Rollup of 7 pull requests

Successful merges:

 - #153286 (various fixes for scalable vectors)
 - #153592 (Add  `min_adt_const_params` gate)
 - #154675 (Improve shadowed private field diagnostics)
 - #154653 (Remove rustc_on_unimplemented's append_const_msg)
 - #154743 (Remove an unused `StableHash` impl.)
 - #154752 (Add comment to borrow-checker)
 - #154764 (Add tests for three ICEs that have already been fixed)
@rust-bors rust-bors bot merged commit a4d278d into rust-lang:main Apr 4, 2026
11 checks passed
@rustbot rustbot added this to the 1.96.0 milestone Apr 4, 2026
rust-timer added a commit that referenced this pull request Apr 4, 2026
Rollup merge of #153592 - zedddie:adt_const_params_restricted_privacy-gate, r=BoxyUwU

Add  `min_adt_const_params` gate

Add `min_adt_const_params` feature gate to disallow `ConstParamTy_` impl for types which fields visibility mismatches with struct itself

r? BoxyUwU
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants