Code using patterns in parameters of foreign functions, function pointers or trait methods without body is not accepted by the compiler.
extern {
fn f((a, b): (u8, u16)); // ERROR
}
type T = fn((a, b): (u8, u16)); // ERROR
trait Tr {
fn f((a, b): (u8, u16)); // ERROR
}
Previously some simple patterns like &ident, &&ident or mut ident were allowed in these positions, now they aren't. Such patterns weren't properly type checked, e.g. type A = fn(&arg: u8); compiled despite u8 not being a reference.
What are these errors for?
Full patterns don't make sense in functions without bodies, but simple identifiers may be useful for documenting argument purposes even if they aren't actually used - type Callback = fn(useful_name: u8).
By restricting patterns in body-less function signatures to ident: TYPE we can make argument names optional and accept simply a TYPE in argument position (type T = fn(u8)) without introducing parsing ambiguities.
How to fix this warning/error
Remove & or mut from the pattern and make the function parameter a single identifier or _.
Current status
Code using patterns in parameters of foreign functions, function pointers or trait methods without body is not accepted by the compiler.
Previously some simple patterns like
&ident,&&identormut identwere allowed in these positions, now they aren't. Such patterns weren't properly type checked, e.g.type A = fn(&arg: u8);compiled despiteu8not being a reference.What are these errors for?
Full patterns don't make sense in functions without bodies, but simple identifiers may be useful for documenting argument purposes even if they aren't actually used -
type Callback = fn(useful_name: u8).By restricting patterns in body-less function signatures to
ident: TYPEwe can make argument names optional and accept simply aTYPEin argument position (type T = fn(u8)) without introducing parsing ambiguities.How to fix this warning/error
Remove
&ormutfrom the pattern and make the function parameter a single identifier or_.Current status
mut IDENT