Skip to content

Passing a non-const trait function item value to a const fn is no longer allowed in a constant context #104155

Closed
@yvt

Description

@yvt

Code

I tried this code:

const _: () = core::mem::forget(Box::<u32>::default);       // ERROR
const _: () = core::mem::forget(|| Box::<u32>::default());  // ok

(Playground)

I expected to see this happen: Successful compilation

Instead, this happened:

error[E0277]: the trait bound `Box<u32>: Default` is not satisfied
 --> src/lib.rs:1:15
  |
1 | const _: () = core::mem::forget(Box::<u32>::default);
  |               ^^^^^^^^^^^^^^^^^ the trait `~const Default` is not implemented for `Box<u32>`
  |
note: the trait `Default` is implemented for `Box<u32>`, but that implementation is not `const`
 --> src/lib.rs:1:15
  |
1 | const _: () = core::mem::forget(Box::<u32>::default);
  |               ^^^^^^^^^^^^^^^^^

Version it worked on

It most recently worked on: 1.65.0

Version with regression

rustc --version --verbose:

rustc 1.66.0-beta.1 (e080cc5a6 2022-11-01)
binary: rustc
commit-hash: e080cc5a659fb760c0bc561b722a790dad35b5e1
commit-date: 2022-11-01
host: aarch64-apple-darwin
release: 1.66.0-beta.1
LLVM version: 15.0.2

@rustbot modify labels: +regression-from-stable-to-beta -regression-untriaged

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.P-criticalCritical priorityregression-from-stable-to-betaPerformance or correctness regression from stable to beta.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions