Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

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

Open
IBUzPE9 opened this issue May 23, 2018 · 1 comment
Labels
A-typesystem Area: The type system C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@IBUzPE9
Copy link

IBUzPE9 commented May 23, 2018

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

@XAMPPRocky XAMPPRocky added A-typesystem Area: The type system C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 2, 2018
@ChayimFriedman2
Copy link
Contributor

This is "fixed" on nightly thanks to explicit_generic_args_with_impl_trait stabilization.

use std::fmt::Debug;

fn xxx<A>(x: impl Debug) {
    println!("Done! {:?}", x)
}

fn main() {
    xxx::<()>(123u8);
}

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=e43997ce75350ad49e6fc177eb75a37b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-typesystem Area: The type system C-enhancement Category: An issue proposing an enhancement or a PR with one. 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