missing_debug_implementations lint is ignored for extern_types

a80e1ca
Opened by crumblingstatue at 2024-12-21 04:50:13
#![feature(extern_types)]

#![warn(missing_debug_implementations)]

pub enum Foo {}
extern "C" {
    pub type Bar;
}

Foo gets a warning, but Bar doesn't:

warning: type does not implement `fmt::Debug`; consider adding #[derive(Debug)] or a manual implementation
 --> foo.rs:5:1
  |
5 | pub enum Foo {}
  | ^^^^^^^^^^^^^^^
  |
note: lint level defined here
 --> foo.rs:3:9
  |
3 | #![warn(missing_debug_implementations)]
  |  
  1. I call out to @kennytm: Sorry if I'm bothering you, but you were great at fixing the previous 2 issues with extern_types, maybe this is something you can easily tackle.

    crumblingstatue at 2017-12-11 17:34:09

  2. Triage: no changes.

    That said, I'm not 100% sure that this is incorrect; given that an extern type is "some type we don't know the size or layout of", how would we possibly get a Debug implementation for it?

    Steve Klabnik at 2019-09-16 13:02:33

  3. Extern types are commonly used with FFI, so an implementation could look something like:

    extern "C" {
        pub type Bar;
    
        pub fn BAR_is_healthy(bar: *const Bar) -> bool;
    }
    
    impl Debug for Bar {
        fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
            fmt.debug_struct("Bar")
                .field("is_healthy", unsafe { &BAR_is_healthy(self) })
                .finish()
        }
    }
    

    Steven Fackler at 2019-09-16 14:21:50