Skip to content

Conversation

@Oyami-Srk
Copy link
Contributor

@Oyami-Srk Oyami-Srk commented Jan 5, 2026

capnpc-rust starts generating code with unsafe block after #607. Therefore, add #[allow(unsafe_code)] to avoid warnings or errors as much as possible.

However, IMHO, introducing unsafe block to generated code might be an obstacle for projects using #![forbid(unsafe_code)] to guarantee the use of safe Rust only. Some of the projects will need to relax their guarantee to be able to use capnproto-rust, like https://github.com/o1-labs/mina-network-debugger/blob/main/mina-ipc/src/lib.rs.

Additionally, I'm not sure about whether adding these #![allow] to the top of the generated file is a better idea, so I chose to follow the existing one.

P.S., Actually, we already have a #![allow] in generated file:

mod_interior.push(line("#![allow(unused_variables)]"));

^ I'm more than happy to move #![allow] to generated file if this is suitable.

@codecov
Copy link

codecov bot commented Jan 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 50.83%. Comparing base (ab342b3) to head (0260350).
⚠️ Report is 251 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #610      +/-   ##
==========================================
- Coverage   51.64%   50.83%   -0.82%     
==========================================
  Files          69       70       +1     
  Lines       33735    32349    -1386     
==========================================
- Hits        17422    16443     -979     
+ Misses      16313    15906     -407     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dwrensha
Copy link
Member

dwrensha commented Jan 5, 2026

I opened #611 to discuss this and other possible fixes.

@dwrensha
Copy link
Member

dwrensha commented Jan 8, 2026

Additionally, I'm not sure about whether adding these #![allow] to the top of the generated file is a better idea, so I chose to follow the existing one.

Unfortunately, adding a global attribute to the top of a file pulled in by include!() does not work.

error: an inner attribute is not permitted in this context
 --> /home/dwrensha/src/capnproto-rust/target/debug/build/external-crate-a36be70fac4750a7/out/external_capnp.rs:5:1
  |
5 |   #![allow(unsafe_code)]
  |   ^^^^^^^^^^^^^^^^^^^^^^
6 | / pub mod annot {
7 | |   pub const ID: u64 = 0xfafa2ced66908af5;
8 | |   pub fn get_type() -> ::capnp::introspect::Type { <crate::external_capnp::opts::Owned as ::capnp::introspect::Introspect>::introspect() }
9 | | }
  | |_- the inner attribute doesn't annotate this module

What does work is locally annotating each unsafe instance: #615. I think I prefer that slightly vs this PR.

@dwrensha
Copy link
Member

dwrensha commented Jan 8, 2026

closing in favor of #615

@dwrensha dwrensha closed this Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants