Skip to content

Parameter names in foreign functions, function pointer types and trait methods are not resolved / validated #33995

Open
@petrochenkov

Description

@petrochenkov

Arguments in foreign functions, function types and traits are pattern bindings like all other function arguments and supposedly they should be resolved in the same way, however they are not resolved at all.
It doesn't make much difference because these bindings can't be used in function bodies, however it makes some difference, for example foreign functions can reuse constant names for their arguments, while other functions can't (whether it's good or bad is a separate question).

Accidentally, some function arguments being unresolved also affect lints like non_snake_case, such lints don't report warnings for them. This may be reasonable for foreign functions though, because such functions may follow foreign naming conventions. If this lint is "fixed" it may affects crates like winapi (cc @retep998). This is not so reasonable for trait methods however.

Examples:

#![allow(dead_code, unused_variables)]

const SOD: u8 = 0;
const SOB: u8 = 0;
const MOD: u8 = 0;
const MDC: u8 = 0;
const DRI: u8 = 0;

// warning: variable `SOD` should have a snake case name
// error: let variables cannot be named the same as const variables
fn f(SOD: u8) {}

trait Tr {
    // warning: variable `SOB` should have a snake case name
    // error: let variables cannot be named the same as const variables
    fn g(SOB: u8) {}

    // No warnings, no errors
    fn h(MOD: u8);
}

// No warnings, no errors
type A = fn(MDC: u8);

extern "C" {
    // No warnings, no errors
    fn k(DRI: u8);
}

fn main() {
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-bugCategory: This is a bug.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