Skip to content

Const closures inside const_unstable functions are claimed to be exposed to stable #155781

@Randl

Description

@Randl

Reproduction

#![feature(const_closures, const_destruct, const_trait_impl)]
#![feature(staged_api)]
#![stable(feature = "rust1", since = "1.0.0")]

use std::marker::Destruct;

#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_foo", issue = "none")]
const fn foo(f: impl [const] Fn() + [const] Destruct) {
    let closure = const || {
        f();
    };
    closure();
}

fn main() {}

I get

error: const function that might be (indirectly) exposed to stable cannot use `#[feature(const_trait_impl)]`
  --> /Users/evgeniizh/RustroverProjects/rust/tests/ui/traits/const-traits/const-closure-in-const-unstable-fn.rs:19:9
   |
LL |         f();
   |         ^^^
   |
help: if the function is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
   |
LL |     let closure = #[rustc_const_unstable(feature = "...", issue = "...")]
   |                   +++++++++++++++++++++++++++++++++++++++++++++++++++++++

but I'd expect this to compile. Also it is impossible to mark const closure as rustc_const_unstable

error: `#[rustc_const_unstable]` attribute cannot be used on closures
  --> /Users/evgeniizh/RustroverProjects/rust/tests/ui/traits/const-traits/const-closure-in-const-unstable-fn.rs:19:9
   |
LL |         #[rustc_const_unstable(feature = "const_foo", issue = "none")]
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: `#[rustc_const_unstable]` can be applied to associated consts, constants, crates, functions, impl blocks, methods, statics, traits, and use statements

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-closuresArea: Closures (`|…| { … }`)A-stabilityArea: `#[stable]`, `#[unstable]` etc.C-bugCategory: This is a bug.F-const_closures`#![feature(const_closures)]`F-const_trait_impl`#![feature(const_trait_impl)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions