Skip to content

stability break in rust 1.54: generic Self types are currently not permitted in anonymous constants #88888

Closed
@eduardosm

Description

@eduardosm

I tried this code:

use std::arch::x86_64::*;

struct Test<const X: u8>;

impl<const X: u8> Test<X> {
    const Y: i32 = (X | (X << 2) | (X << 4) | (X << 6)) as i32;

    unsafe fn f(v: __m128i) -> __m128i {
        _mm_shufflelo_epi16(v, Self::Y)
    }
}

I expected to see this happen:

This code was accepted in Rust 1.53, so newer versions should also accept it.

Instead, this happened:

error: generic `Self` types are currently not permitted in anonymous constants
 --> <source>:9:32
  |
9 |         _mm_shufflelo_epi16(v, Self::Y)
  |                                ^^^^
  |
note: not a concrete type
 --> <source>:5:19
  |
5 | impl<const X: u8> Test<X> {
  |                   ^^^^^^^

error: aborting due to previous error

Meta

Tested using rustc 1.53 and 1.54 (and newer) from Compiler Explorer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-SIMDArea: SIMD (Single Instruction Multiple Data)A-const-genericsArea: const generics (parameters and arguments)C-bugCategory: This is a bug.P-highHigh priorityPG-const-genericsProject group: Const genericsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions