Skip to content

Specialization does not work correctly during constant evaluation. #66901

Closed
@Lymia

Description

@Lymia

A crate using specialization I've been working on seems to have broken sometime between nightly-2019-11-19 and nightly-2019-11-20. After a bit of debugging, it seems the issue is that specialization doesn't always work correctly in const contexts.

This code, for example, returns the following:

const_bool::<TypeA>: in default impl
const_bool::<TypeB>: in default impl
const_str::<TypeA>: in specialized impl
const_str::<TypeB>: in default impl
run_method::<TypeA>: in specialized impl
run_method::<TypeB>: in default impl

On earlier versions, this would have returned the following:

const_bool::<TypeA>: in specialized impl
const_bool::<TypeB>: in default impl
const_str::<TypeA>: in specialized impl
const_str::<TypeB>: in default impl
run_method::<TypeA>: in specialized impl
run_method::<TypeB>: in default impl

This bug does not happen when the -Z mir-opt-level=0 flag is set, and it behaves the same as prior versions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-specializationArea: Trait impl specializationC-bugCategory: This is a bug.F-specialization`#![feature(specialization)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions