Skip to content

"Mismatched types" error when comparing the same struct for equality when referenced from two libraries #87534

Closed
@andyyu2004

Description

@andyyu2004

I tried this code:

// in a/src/lib.rs which has a dependency on crate b
pub fn mk_struct() -> b::SomeStruct {
    b::SomeStruct
}

#[test]
fn wer() {
    // compiles
    assert_eq!(self::mk_struct(), b::SomeStruct);
}

// in b/src/lib.rs which has dev-dependency on crate a
#[derive(PartialEq, Eq, Debug)]
pub struct SomeStruct;

#[cfg(test)]
mod tests {
    #[test]
    fn it_works() {
        // doesn't compile with following error
        // expected struct `b::SomeStruct`, found struct `SomeStruct`
        a::mk_struct() == super::SomeStruct;
    }
}

I would expect this code to compile but instead it emits the error "expected struct b::NonGeneric, found struct NonGeneric" which is odd as I would think they are the same type.

Meta

Reproducible on 1.56.0-nightly.
Repository: https://github.com/andyyu2004/rust-bug-repro

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-discussionCategory: Discussion or questions that doesn't represent real issues.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions