Skip to content

Const parameter defaults are not used as a fallback during type inference #96300

@SUPERCILEX

Description

@SUPERCILEX

I tried this code:

struct A<const N: usize = 64> {}

// impl A { // Works because it's specialized to 64
impl<const N: usize> A<N> { // Fails
    fn new() -> Self {
        todo!();
    }
}

pub fn blah() {
    A::new();
}

I expected to see this happen: the const generic would be inferred to 64.

Instead, this happened: fails to compile. An attempt to fix it by doing impl<const N: usize = 64> doesn't work because it's disallowed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-inferenceArea: Type inferenceC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions