-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lint/ctypes: ext. abi fn-ptr in internal abi fn #108611
lint/ctypes: ext. abi fn-ptr in internal abi fn #108611
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
This seems to be the wording that is already used, but I really don't like the |
I agree, but I'll leave this for a follow-up. |
eb578e5
to
5da1782
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused now.
Surely this should fail compilation:
#![deny(improper_ctypes_definitions, improper_ctypes)]
struct __(extern "C" fn([u8]));
And yet, it currently passes it ([play]). And, if I understood correctly, under this PR it would pass too...
Maybe instead of trying to deeply check types in extern
items, we should actually just check all types, find extern ... fn(...)
types and check their arguments?
5da1782
to
3e7ca3e
Compare
I've extended support to all types that could contain the extern fn-ptr types (which I think is the only thing that we need to check in otherwise okay types, i.e. |
I don't think that's necessarily enough. For example this doesn't get linted, still: #![deny(improper_ctypes_definitions, improper_ctypes)]
fn main() {
let _: extern "C" fn([u8]) = todo!();
} I would prefer using something like |
That's exactly why I haven't used
|
idk, I don't feel confident reviewing this PR, so I'll reroll |
I assume Wesley has not enough bandwidth right now, so I'll reroll r? compiler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one thought, but r=me if you don't want to try to change things.
compiler/rustc_lint/src/types.rs
Outdated
let sig = self.cx.tcx.fn_sig(def_id).subst_identity(); | ||
let sig = self.cx.tcx.erase_late_bound_regions(sig); | ||
|
||
let is_internal_abi = self.is_internal_abi(abi); | ||
let check_ty = |this: &mut ImproperCTypesVisitor<'a, 'tcx>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, this all seems like it should just be a part of a visitor with a flag for foreign abi or not.
@bors r=jackh726 I think that suggestion is best left for a follow-up. |
⌛ Testing commit 3e7ca3e with merge f13b0551bf4f1aa76569c80852751b51c811f5fc... |
This comment was marked as resolved.
This comment was marked as resolved.
📌 Commit f14e5778ca8dccef35f243cb8b7869fe239afb69 has been approved by It is now in the queue for this repository. |
⌛ Testing commit f14e5778ca8dccef35f243cb8b7869fe239afb69 with merge be32e03c64ad0401ea676f7831ad574bc7740354... |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Instead of skipping functions with internal ABIs, check that the signature doesn't contain any fn-ptr types with external ABIs that aren't FFI-safe. Signed-off-by: David Wood <david.wood@huawei.com>
Remove an `unwrap` that assumed FFI-safe types in foreign fn-ptr types. Signed-off-by: David Wood <david.wood@huawei.com>
Extend previous commit's support for checking for external fn-ptrs in internal fn types to report errors for multiple found fn-ptrs. Signed-off-by: David Wood <david.wood@huawei.com>
Extend previous checks for external ABI fn-ptrs to use in internal statics, constants, type aliases and algebraic data types. Signed-off-by: David Wood <david.wood@huawei.com>
This was causing compilation failures in the performance benchmarking as diesel hit recursion limits. Signed-off-by: David Wood <david@davidtw.co>
Signed-off-by: David Wood <david@davidtw.co>
f14e577
to
2227422
Compare
@bors r=jackh726 |
☀️ Test successful - checks-actions |
Finished benchmarking commit (0ab38e9): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 670.457s -> 669.062s (-0.21%) |
Fixes #94223.
unwrap
that assumed FFI-safe types in foreign fn-ptr types.