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

Permit trait object types where all (non-generic) associated constants are specified (via assoc item bindings) #130300

Open
fmease opened this issue Sep 13, 2024 · 0 comments
Assignees
Labels
A-trait-objects Area: trait objects, vtable layout C-feature-request Category: A feature request, i.e: not implemented / a PR. F-associated_const_equality `#![feature(associated_const_equality)]` requires-nightly This issue requires a nightly compiler in some way. S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@fmease
Copy link
Member

fmease commented Sep 13, 2024

Important context: Inherently, this would only become legal under the ongoing lang experiment associated_const_equality (#92827).

We permit trait object types where all 'active'1 non-generic associated types are specified (via assoc item bindings). We should extend this to cover 'active' non-generic2 associated constants, too.

Note that I haven't spent much time thinking about soundness yet. I still need to iron out the exact rules. Implementation-wise, I'm almost certain that any advances are blocked by #120905 (more precisely, its underlying issue) which I presume we would need to fix first for correctness.

Minimal & contrived example of something that would start compiling:

#![feature(associated_const_equality)]

trait Trait {
    const K: ();
}

fn main() {
    let _: dyn Trait<K = { () }>;
}

Presently, this gets rejected and we emit E0038 (cannot be made into an object).


Lastly, lest I forget, we should emit the lint unused_associated_type_bounds3 (#112319) for assoc const bindings where the corresp. assoc const is 'disabled' via where Self: Sized which is only possible to write under generic_const_items (#113521).


Footnotes

  1. I.e., not 'made inactive' / 'disabled' via where Self: Sized (Don't require associated types with Self: Sized bounds in dyn Trait objects #112319).

  2. This might or might not be a temporary restriction. For context, we don't (yet) permit GAT bindings in trait object types either on stable, due to soundness concerns. See generic_associated_types_extended (Tracking Issue for extended generic associated types #95451). Also note that generic assoc consts (GACs) are only available under generic_const_items (Tracking issue for generic const items #113521).

  3. Indeed, the name would no longer be accurate. Ideally, we would rename the lint when generalizing it.

@fmease fmease added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-feature-request Category: A feature request, i.e: not implemented / a PR. S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. requires-nightly This issue requires a nightly compiler in some way. T-types Relevant to the types team, which will review and decide on the PR/issue. F-associated_const_equality `#![feature(associated_const_equality)]` A-trait-objects Area: trait objects, vtable layout labels Sep 13, 2024
@fmease fmease self-assigned this Sep 13, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 13, 2024
@fmease fmease removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-trait-objects Area: trait objects, vtable layout C-feature-request Category: A feature request, i.e: not implemented / a PR. F-associated_const_equality `#![feature(associated_const_equality)]` requires-nightly This issue requires a nightly compiler in some way. S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants