Skip to content

confilct with the conclusion: &mut T is invariant On T #183

Closed
@zylthinking

Description

@zylthinking

the code below can be compiled, but it should be rejected because of &mut T is invariant On T;
Is there anything I misunderstand?

impl Animal for Cat1 {
    fn snuggle(&self) {
    }

    fn eat(&mut self) {
        println!("cat {}", self.data);
    }
}

impl Cat for Cat1 {
    fn meow(&self) {}
}

fn love(pet: &mut Animal) {
}

fn change() {
    let mut z: Cat1 = Cat1 {
        data: 8
    };
    love(&mut z);
}

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