Here gives a control flow graph:

``````// let mut foo: i32;
// let mut bar: i32;
// let mut p: &i32;

A
[ p = &foo     ]
[ if condition ] ----\ (true)
|             |
|     B       v
|     [ print(*p)     ]
|     [ ...           ]
|     [ p = &bar      ]
|     [ ...           ]
|     [ goto C        ]
|             |
+-------------/
|
C      v
[ print(*p)    ]
[ return       ]
``````

Here and Here all say that `'p` doesn't include `B/1` but include `B/3`.

So what's the difference between `...` and `...`???
Is the meaning of the first `...` different from meaing of the second `...`?

The meaning is the same (`...` is just a placeholder), but the liveness of `p` differs for the two lines.

``````#![allow(unused)]
fn main() {
let mut foo: T = ...;
let mut bar: T = ...;
let mut p: &'p T = &foo;
// `p` is live here: its value may be used on the next line.
if condition {
// `p` is live here: its value will be used on the next line.
print(*p);
// `p` is DEAD here: its value will not be used.
p = &bar;
// `p` is live here: its value will be used later.
}
// `p` is live here: its value may be used on the next line.
print(*p);
// `p` is DEAD here: its value will not be used.
}
``````

So the difference is, `p` is dead at `B/1` but live at `B/3`.

1 Like

a placeholder for what?
why isn't it like this?

``````A
[ p = &foo     ]
[ if condition ] ----\ (true)
|             |
|     B       v
|     [ ...           ]
|     [ print(*p)     ]
|     [ ...           ]
|     [ p = &bar      ]
|     [ ...           ]
|     [ goto C        ]
|             |
+-------------/
|
C      v
[ print(*p)    ]
[ return       ]
``````

what's the reason of inserting the placeholder?

So that one can unambiguously refer to the region of code between `p`'s use and reassignment, for example.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.