gccrs icon indicating copy to clipboard operation
gccrs copied to clipboard

Error out when explicitly specifiying the desugared type of `Fn` traits

Open CohenArthur opened this issue 3 years ago • 2 comments

fn invalid_ref(a: i32, b: i32 ,f: &dyn Fn<(i32, i32), Output = i32>) -> i32 {
    f(a + b)
}

fn invalid(a: i32, b: i32 ,f: impl Fn<(i32, i32), Output = i32>) -> i32 {
    f(a + b)
}

Both cases should error out since that format is unstable and should not be used. Ideally, they should hint about the proper format (Fn(i32, i32) -> i32)

Associated features enabling this:

  • https://doc.rust-lang.org/beta/unstable-book/language-features/unboxed-closures.html
  • https://doc.rust-lang.org/beta/unstable-book/library-features/fn-traits.html

CohenArthur avatar Aug 18 '22 13:08 CohenArthur

It shouldn't error out when the feature gate for it is enabled as libcore and liballoc need it.

bjorn3 avatar Aug 18 '22 13:08 bjorn3

Ah, very good point. I'll add the feature to the original comment

CohenArthur avatar Aug 18 '22 13:08 CohenArthur