Skip to content

An unused type parameter and an impl in the argument position allows you to define a function that cannot be called #50990

Closed
@IBUzPE9

Description

@IBUzPE9
use std::fmt::Debug;

// Function that can not be called
fn xxx<A>(x:impl Debug){ println!("Done! {:?}", x) }

// Should an unused type parameter generate an error or warning?
fn yyy<A, B:Debug>(x:B){ println!("Done! {:?}", x) }

fn main(){
    // xxx(123u8); //type annotations needed
    // xxx::<()>(123u8); //too few type parameters provided: expected 2 type parameters, found 1 type parameter
    // xxx::<(), _>(123u8); //cannot provide explicit type parameters when `impl Trait` is used in argument position.
    // xxx::<(), u8>(123u8); //cannot provide explicit type parameters when `impl Trait` is used in argument position.
    yyy::<(), u8>(123u8);
    yyy::<(), _>(123u8);
}

playground

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-type-systemArea: Type systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.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