Skip to content

Tracking Issue for future-incompatibility lint invalid_c_variadic_arguments #162483

Description

@theemathas

This is the tracking issue for the invalid_c_variadic_arguments future-compatibility warning. The goal of this page is to describe why this change was made and how you can fix code that is affected by it. It also provides a place to ask questions or register a complaint if you feel the change should not be made. For more information on the policy around future-compatibility warnings, see our breaking change policy guidelines.

What is the warning for? Why was this change made?

The invalid_c_variadic_arguments lint detects when a value of an unsupported type is passed as a C-variadic argument (varargs).

Only certain types are supported in C-variadic arguments (varargs). In particular, only types that implement the core::ffi::VaArgSafe trait are supported.

Using unsupported types causes undefined behavior. However, the compiler previously didn't consistently check to prevent this from happening in all cases.

Currently, this lint does not warn on references to Sized types, despite the fact that they (unlike raw pointers) don't implement VaArgSafe. This is because we might decide to officially support them in the future, by making them implement VaArgSafe, and there is too much existing code that passes references as varargs.

Example

unsafe extern "C" fn variadic(_: ...) {}

pub fn foo<T>(x: T) {
    unsafe {
        variadic(x);  // warning: type `T` does not implement `VaArgSafe`
    }
}

Recommendations

If you encounter this lint in a generic context which will be instantiated only with supported types, consider adding a trait bound such as T: VaArgSafe.

Steps

  • Implement the lint
  • Raise lint level to deny
  • Change the lint to report in dependencies
  • Switch to a hard error

Implementation history

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-FFIArea: Foreign function interface (FFI)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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions