Skip to content

rustc_const_unstable on private items is confusing #144802

@clarfonthey

Description

@clarfonthey

Problem

Right now, private items that use const-unstable things need one of the following:

  1. rustc_const_unstable, to mark them as part of an unstable feature
  2. rustc_const_stable_indirect, to mark these uses of const-unstable features as okay to be used indirectly in const-stable functions

This can be particularly confusing when trying to assign features to these functions, since in particular, either of these attributes is okay to add to any private item, regardless of whether they actually need it.

The main issue is that we want to track what const features are indirectly exposed to stable, but that we don't want to recursively inspect function bodies to do this.

Proposal

So, I propose a new solution: rustc_forward_const_fn_unstable.

This is similar to rustc_allow_const_fn_unstable, but specifically for private items, and it has slightly different semantics:

  1. The features mentioned in the attribute must exist, be unstable, and be used in the body of the function.
  2. After being processed, the function is treated as unstable with all the different features listed. (and the correct issues)

This effectively punts a rustc_allow_const_fn_unstable attribute down the line to a caller function if needed, helps avoid the issue where people just add the same const unstable feature to all methods they need it on, and avoids unnecessarily adding unstable features to const methods that don't require them.

Effectively, it bypasses the issue discussed in this review thread.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)T-libsRelevant to the library team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions