Open
Description
Example available on https://rust.godbolt.org/z/bzjPv6TGT
You get a failure if you remove the edition flag, but it's completely different and that may or may not also be incorrect.
trait Tr {}
struct T {
obj: Box<dyn Tr>,
}
struct U;
impl Tr for U{}
impl T {
fn works<'a>(&'a mut self) -> Option<&'a mut dyn Tr> {
true.then(|| { self.obj.as_mut() })
}
fn fails<'a>(&'a mut self) -> Option<&'a mut dyn Tr> {
true.then(|| self.obj.as_mut())
}
}
fn main() {
let mut t = T{obj: Box::new(U{})};
let _u = t.works();
}