Skip to content

Potential false positive for invalid_runtime_symbol_definitions lint #159446

Description

@hkalbasi

I tried this code:

unsafe extern "C" {
    fn exit(s: i32);
}

fn main() {
    unsafe { exit(5); }
}

I expected to see this happen: Compilation succeed and program returned 5

Instead, this happened:

error: invalid definition of the runtime `exit` symbol used by the standard library
 --> <source>:4:5
  |
4 |     fn exit(s: i32);
  |     ^^^^^^^^^^^^^^^^
  |
  = note: expected `unsafe extern "C" fn(i32) -> !`
          found    `unsafe extern "C" fn(i32)`
  = help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "exit")]`, or `#[link_name = "exit"]`
  = note: `#[deny(invalid_runtime_symbol_definitions)]` on by default

error: aborting due to 1 previous error; 2 warnings emitted

Compiler returned: 1

It might be suspicious, but it is not invalid definitely.

Meta

I hit this bug in CO2 which is basically a C frontend for rustc. I would like to enable this very useful lint at least warn by default, but I don't want to annoy C people by forcing them to add __atribute__((no_return)) to their void exit(int); declarations. I expect c2rust to have a similar problem.

cc @Urgau #155521

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.C-discussionCategory: Discussion or questions that doesn't represent real issues.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions