Skip to content

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

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
SUPERCILEX opened this issue Apr 21, 2022 · 3 comments
Closed
Labels
A-inference Area: Type inference C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@SUPERCILEX
Copy link
Contributor

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.

@SUPERCILEX SUPERCILEX added the C-bug Category: This is a bug. label Apr 21, 2022
@fmease
Copy link
Member

fmease commented Apr 22, 2022

This has nothing to do with “specialization” (#![feature(specialization)]) but with the known issue of type / const parameter defaults not being used as a fallback for failed inference. Duplicate of the closed issue #83687.

@SUPERCILEX
Copy link
Contributor Author

Whoops, is there more accurate terminology?

About that issue, why was it closed? This seems like something worth fixing.

@fmease fmease added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-inference Area: Type inference and removed needs-triage-legacy labels Sep 6, 2023
@fmease fmease changed the title Lack of impl specialization causes failed const generic inference Const parameter defaults are not used as a fallbacks during type inference Jan 23, 2024
@fmease fmease changed the title Const parameter defaults are not used as a fallbacks during type inference Const parameter defaults are not used as a fallback during type inference Jan 23, 2024
@fmease
Copy link
Member

fmease commented Jan 23, 2024

Closing in favor of #98931 which contains a bit more discussion.

@fmease fmease closed this as not planned Won't fix, can't repro, duplicate, stale Jan 23, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-inference Area: Type inference C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants