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

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

Activity

  1. added
    C-bugCategory: This is a bug.
    regression-untriagedUntriaged performance or correctness regression.
    on Nov 8, 2022
  2. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    and removed
    regression-untriagedUntriaged performance or correctness regression.
    on Nov 8, 2022
  3. jruderman commented on Nov 8, 2022

    @jruderman
    Contributor

    This became an error due to #100982 (@fee1-dead, @oli-obk).

    Bisect info

    searched nightlies: from nightly-2022-09-18 to nightly-2022-11-07
    regressed nightly: nightly-2022-09-23
    searched commit range: 9062b78...e7119a0
    regressed commit: 7a8636c

    bisected with cargo-bisect-rustc v0.6.4

    Host triple: x86_64-apple-darwin

    I used cargo bisect-rustc --regress error on the following file

    const _: () = core::mem::forget(Box::<u32>::default); 
    fn main(){}
  4. self-assigned this
    on Nov 8, 2022
  5. added and removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Nov 9, 2022
  6. inquisitivecrystal commented on Nov 9, 2022

    @inquisitivecrystal
    Contributor

    Assigning priority as discussed by the Prioritization Working Group.

  7. added a commit that references this issue on Nov 9, 2022
    d22c433
  8. fee1-dead commented on Nov 9, 2022

    @fee1-dead
    Member

    awaiting beta backport

  9. yvt commented on Nov 23, 2022

    @yvt
    ContributorAuthor

    Can this be closed now that beta backport (#104447) is complete?

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

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