Skip to content

facet-core: Debug impl of Def is misleading, should use PointerDefs Debug impl instead #2149

@Erik1000

Description

@Erik1000

https://docs.rs/facet-core/0.44.3/src/facet_core/types/def/mod.rs.html#217-219

A &Foos ::SHAPE.def debug impl prints SmartPointer<Foo> which is wrong since &T is not a smart pointer.
That is due to:
https://docs.rs/facet-core/0.44.3/src/facet_core/types/def/mod.rs.html#217-219
which is Some due to the way Facet is implemented for &T
https://docs.rs/facet-core/0.44.3/src/facet_core/impls/core/reference.rs.html#252

Discovered with the following code:

#[cfg(test)]
mod tests {
    use facet::{Def, Facet, KnownPointer};
    use facet_reflect::Peek;

    #[derive(Debug, Facet)]
    struct Foo {
        value: String,
    }

    #[facet_testhelpers::test]
    fn shared_reference() {
        let a = Foo {
            value: "aaaa".to_string(),
        };
        println!("{:#?}", <&Foo as Facet<'_>>::SHAPE.def);
        assert!(
            matches!(<&Foo as Facet<'_>>::SHAPE.def, Def::Pointer(p) if p.known == Some(KnownPointer::SharedReference))
        );
        let ref_a: &Foo = &a;
        let ref_ref_a: &&Foo = &ref_a;
        let peek = Peek::new(ref_ref_a);
        println!("{:#?}", peek.shape().def); // `Undefined`
        assert!(
            matches!(peek.shape().def, Def::Pointer(p) if p.known == Some(KnownPointer::SharedReference))
        );
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions