Skip to content

rustc: inference for numeric literals does not take default type parameters into account #15760

Closed
@aturon

Description

@aturon

The following code fails to compile:

#![feature(default_type_params)]

fn foo<T = u64>(t: T) {}
fn main() {
    foo(0);
}

with

error: cannot determine a type for this expression: cannot determine the type of this integer; add a suffix to specify the type explicitly

despite the fact that the actual type is determinant.

Fixing this problem could help mitigate problems with the int fallback: for functions like range, we could provide a default type parameter of, say, uint while retaining flexibility for other types. (Doing so loses some of the benefit of the fallback removal, but we can introduce defaults in a controlled way.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-inferenceArea: Type inferenceA-type-systemArea: Type systemC-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions