Skip to content

Apply coercion rules on return expressions #12755

Closed
@arjantop

Description

@arjantop

Asked on reddit

I have a program where I want to select from two fields (int in this example, io::Writer in practice). It is not possible to return a in a way the program compiles.

Reborrowing was suggested (&mut *self.a) but you can't do that with io::Writer references.

pub struct Foo<'a> {
    priv a: &'a mut int,
    priv b: int,
    priv take_a: bool
}

impl<'a> Foo<'a> {
    fn take(&'a mut self) -> &'a mut int {
        if self.take_a {
            self.a
        } else {
            &mut self.b
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions