Builder.derive_partialord(true) maybe should not derive PartialOrd for function pointers
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
Builder::derive_partialord オプションと、関数ポインタを含む structs に対して derives を出力するコードパスから始めます。示されている C 宣言と生成された Rust 出力を再現し、その後、既存の derive 関連テストを調査するか、回帰テストのカバレッジを追加します。報告された rustc 警告なしで意図した動作が文書化され、検証されていれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Consider the following C declaration:
struct avc_memory_callback {
void *(*func_malloc)(size_t size);
/* other fields... */
};
Running bindgen on that, with a call to Builder.derive_partialord(true) (and other options) generates the following Rust declaration:
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialOrd, Ord, PartialEq, Eq)]
pub struct avc_memory_callback {
pub func_malloc:
::std::option::Option<unsafe extern "C" fn(size: usize) -> *mut ::std::os::raw::c_void>,
/* other fields... */
}
The interesting point here is the #[derive(PartialOrd)], which causes the following rustc warning:
warning: function pointer comparisons do not produce meaningful results since their addresses are not guaranteed to be unique
--> <...>/selinux-sys/target/debug/build/selinux-sys-2e09f76ca98757af/out/selinux-sys.rs:1004:5
|
1002 | #[derive(Debug, Copy, Clone, PartialOrd, Ord, PartialEq, Eq)]
| ---------- in this derive macro expansion
1003 | pub struct avc_memory_callback {
1004 | / pub func_malloc:
1005 | | ::std::option::Option<unsafe extern "C" fn(size: usize) -> *mut ::std::os::raw::c_void>,
| |_______________________________________________________________________________________________^
|
= note: the address of the same function can vary between different codegen units
= note: furthermore, different functions could have the same address after being merged together
= note: for more information visit <https://doc.rust-lang.org/nightly/core/ptr/fn.fn_addr_eq.html>
= note: `#[warn(unpredictable_function_pointer_comparisons)]` on by default
The documentation of Builder::derive_partialord says:
Set whether the PartialOrd trait should be derived when possible.
And while this is technically possible, I think rustc here is requesting, politely, to avoid it. I agree with the assessment that rustc is showing. And my question is: should Builder.derive_partialord(true) still do it?
In the meantime, my fix for this issue is to call builder.no_partialeq("^avc_([_a-zA-Z0-9]+)_callback$") to manually exclude the types that contain function pointers. But, is this the reasonable fix for this situation, or should the behavior of Builder.derive_partialord(true) change to exclude function pointers?
- 主要言語
- Rust
- スター
- 5.3k
- フォーク
- 846
- 平均マージ
- 2日 6時間
- マージ済み PR(30日)
- 11
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
rust-lang/rust-bindgen のほかの issue
-
--enable-cxx-namespaces panics on namespace [[deprecated]] { ("[" is not a valid Ident)対応中かも @lwz23 が 49 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
rust-lang/rust-bindgen#3485 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
rust-lang/rust-bindgen#3483 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
rust-lang/rust-bindgen#3370 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
rust-lang/rust-bindgen#3363 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
rust-lang/rust-bindgen#3540 ·
メンテナーはふだん 1 日以内に返信
rust-lang/rust-bindgen の issue をすべて見る
似ている issue
-
agent-self
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
yologdev/yoyo-evolve#1176 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
Richard-Zhang1019/Crossbow#431 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 86/100
saschanaz/jxl-winthumb#69 ·
-
ready
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
TusanHomichi/PSIV#504 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信