Skip to content

Tracking issue for future-incompatibility lint patterns_in_fns_without_body #35203

Open
@petrochenkov

Description

@petrochenkov

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-future-incompatibilityCategory: Future-incompatibility lintsC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    Status

    Idea

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions