Convert Drop statement into terminator
The structure of the old translator as well as MIR assumed that drop glue cannot possibly panic and translated the drops accordingly. However, in presence of `Drop::drop` this assumption can be trivially shown to be untrue. As such, the Rust code like the following would never print number 2: ```rust struct Droppable(u32); impl Drop for Droppable { fn drop(&mut self) { if self.0 == 1 { panic!("Droppable(1)") } else { println!("{}", self.0) } } } fn main() { let x = Droppable(2); let y = Droppable(1); } ``` While the behaviour is allowed according to the language rules (we allow drops to not run), that’s a very counter-intuitive behaviour. We fix this in MIR by allowing `Drop` to have a target to take on divergence and connect the drops in such a way so the leftover drops are executed when some drop unwinds. Note, that this commit still does not implement the translator part of changes necessary for the grand scheme of things to fully work, so the actual observed behaviour does not change yet. Coming soon™. See #14875.
Showing
想要评论请 注册 或 登录