someguynamedjosh / ouroboros

Easy self-referential struct generation for Rust.
Apache License 2.0
523 stars 35 forks source link

Unused attributes prefixed with _ don't work #39

Open dllu opened 2 years ago

dllu commented 2 years ago

For example:

#[self_referencing]
pub struct RentalStream {
    lifetime: (),
    #[borrows(lifetime)]
    #[covariant]
    context: uvc::Context<'this>,
    #[borrows(context)]
    #[covariant]
    device: uvc::Device<'this>,
    #[borrows(device)]
    #[covariant]
    device_handle: uvc::DeviceHandle<'this>,
    #[borrows(device_handle)]
    #[covariant]
    stream_handle: uvc::StreamHandle<'this>,
    #[borrows(mut stream_handle)]
    #[covariant]
    active_stream: uvc::ActiveStream<'this, ()>,
}
warning: field is never read: `active_stream`
  --> examples/demo-viz/uvc_camera.rs:41:9
   |
41 |     pub active_stream: uvc::ActiveStream<'this, ()>,
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(dead_code)]` on by default

but if I change it to _active_stream, I now get:

warning: method `with__active_stream` should have a snake case name
  --> examples/demo-viz/uvc_camera.rs:41:5
   |
41 |     _active_stream: uvc::ActiveStream<'this, ()>,
   |     ^^^^^^^^^^^^^^ help: convert the identifier to snake case: `with_active_stream`
   |
   = note: `#[warn(non_snake_case)]` on by default

warning: method `borrow__active_stream` should have a snake case name
  --> examples/demo-viz/uvc_camera.rs:41:5
   |
41 |     _active_stream: uvc::ActiveStream<'this, ()>,
   |     ^^^^^^^^^^^^^^ help: convert the identifier to snake case: `borrow_active_stream`

warning: method `with__active_stream_mut` should have a snake case name
  --> examples/demo-viz/uvc_camera.rs:41:5
   |
41 |     _active_stream: uvc::ActiveStream<'this, ()>,
   |     ^^^^^^^^^^^^^^ help: convert the identifier to snake case: `with_active_stream_mut`

So I had to end up putting a #[allow(dead_code)] on top of my struct RentalStream, a crude hack.

alxdb commented 1 year ago

I've just had this same issue, and it appears that #[allow(dead_code)] is no longer working.

fluxehub commented 8 months ago

This is still an issue for me, neither _ nor using #[allow(dead_code)] will disable warnings