Skip to content

Warn if a function is marked as both #[inline] and #[no_mangle] #72944

Closed

Description

Code:

// src/lib.rs
#[inline] #[no_mangle] pub extern "C" fn foo() { }
# Cargo.toml
[package]
name = "foo"
version = "0.0.1"
edition = "2018"

[lib]
name = "foo"
crate-type = ["cdylib"]
cargo build --release

If the function is marked as #[inline], it doesn't get compiled into the dll file:

strings target/release/libfoo.so | grep foo

The reason a function may be marked as both #[inline] and #[no_mangle] is so that it gets inlined when compiling the crate as a rust library, but not inlined when compiling the crate as a cdylib.

There should be a warning to use something like #[cfg_attr(not(crate_type="cdylib"), inline] instead.

This issue has been assigned to @doctorn via this comment.

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

Metadata

Assignees

Labels

A-FFIArea: Foreign function interface (FFI)A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-feature-requestCategory: A feature request, i.e: not implemented / a PR.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