Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

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

Closed as not planned

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.

Activity

  1. added
    C-bug
    on Apr 21, 2022
  2. fmease commented on Apr 22, 2022

    @fmease
    Member

    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.

  3. SUPERCILEX commented on Apr 22, 2022

    @SUPERCILEX
    ContributorAuthor

    Whoops, is there more accurate terminology?

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

  4. added
    T-compiler
    A-inference
    and removed on Sep 6, 2023
  5. changed the title [-]Lack of impl specialization causes failed const generic inference[/-] [+]Const parameter defaults are not used as a fallbacks during type inference[/+] on Jan 23, 2024
  6. 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[/+] on Jan 23, 2024
  7. fmease commented on Jan 23, 2024

    @fmease
    Member

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-inferenceC-bugT-compiler

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions