Consider the following snippet, which compiles fine:
trait Tr {}
struct A(Option<Box<dyn Tr>>);
impl A {
Consider the following snippet, which compiles fine:
trait Tr {}
struct A(Option<Box<dyn Tr>>);
impl A {
Rules of liveness: about the "discard point"
with no drop glue, no "library" code gets executed, so a fortiori, no lifetimes/borrows/w/e are used/dereferenced, so it would be sound for lifetimes of the discardee to be dangling here.
⇒ No need for liveness to extend to this point
with drop glue:
Note that this is a Linux-specific feature.
Say we are a library libfoo.so.3.5
, and some dependent binary artifact is being linked against us.
./main
;use ::polonius_the_crab::prelude::*; | |
struct DummyStream { | |
buffer: Vec<u8>, | |
frame_count: u32, | |
} | |
impl DummyStream { | |
fn new(width: usize, height: usize) -> Self { | |
Self { |
# http://www.graphviz.org/content/cluster | |
digraph G { | |
graph [fontname = "courier"]; | |
node [fontname = "courier", shape=box]; | |
edge [fontname = "courier"]; | |
compound=true; | |
subgraph cluster_a { |
digraph __crate__ { | |
subgraph cluster_Mir_0_10 { | |
graph [fontname="Courier, monospace"]; | |
node [fontname="Courier, monospace"]; | |
edge [fontname="Courier, monospace"]; | |
// label=<fn main() -> ()<br align="left"/>let mut _1: std::string::String;<br align="left"/>let mut _2: DropGlue<&mut std::string::String>;<br align="left"/>let mut _3: &mut std::string::String;<br align="left"/>let mut _4: *mut std::string::String;<br align="left"/>let _5: ();<br align="left"/>debug _2 => _2;<br align="left"/>debug _1 => _1;<br align="left"/>>; | |
bb0__0_10 [shape="none", label=<<table border="0" cellborder="1" cellspacing="0"><tr><td bgcolor="gray" align="center" colspan="1">0</td></tr><tr><td align="left" balign="left">StorageLive(_1)<br/></td></tr><tr><td align="left">_1 = String::new()</td></tr></table>>]; | |
bb1__0_10 [shape="none", label=<<table border="0" cellborder="1" cellspacing="0"><tr><td bgcolor="gray" align="center" colspan="1">1</td></tr><tr><td align="left" balign="left">Sto |
[These posts have been extracted from this Discord conversation, so as not to require readers to use their Discord account to read it 😔]
HI!
Question and idea about narrowing lifetime of mutable references.
In rust code when developing finite state machines, behaviour trees and other algorithms we often need to pass around Context on which these algorithms will work.
Percentage:
<img src="https://user-images.githubusercontent.com/16319829/81180309-2b51f000-8fee-11ea-8a78-ddfe8c3412a7.png" width=50% height=50%>
Pixels:
<img src="https://user-images.githubusercontent.com/16319829/81180309-2b51f000-8fee-11ea-8a78-ddfe8c3412a7.png" width="150" height="280">