rust/compiler/rustc_middle/src/mir
bors 21fab435da Auto merge of #104844 - cjgillot:mention-eval-place, r=jackh726,RalfJung
Evaluate place expression in `PlaceMention`

https://github.com/rust-lang/rust/pull/102256 introduces a `PlaceMention(place)` MIR statement which keep trace of `let _ = place` statements from surface rust, but without semantics.

This PR proposes to change the behaviour of `let _ =` patterns with respect to the borrow-checker to verify that the bound place is live.

Specifically, consider this code:
```rust
let _ = {
    let a = 5;
    &a
};
```

This passes borrowck without error on stable. Meanwhile, replacing `_` by `_: _` or `_p` errors with "error[E0597]: `a` does not live long enough", [see playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=c448d25a7c205dc95a0967fe96bccce8).

This PR *does not* change how `_` patterns behave with respect to initializedness: it remains ok to bind a moved-from place to `_`.

The relevant test is `tests/ui/borrowck/let_underscore_temporary.rs`. Crater check found no regression.

For consistency, this PR changes miri to evaluate the place found in `PlaceMention`, and report eventual dangling pointers found within it.

r? `@RalfJung`
2023-04-22 09:54:21 +00:00
..
interpret Remove WithOptconstParam. 2023-04-20 17:48:32 +00:00
basic_blocks.rs Use &IndexSlice instead of &IndexVec where possible 2023-04-02 17:35:37 -07:00
coverage.rs Replace enum ==s with matches where it makes sense 2023-01-30 12:26:26 +00:00
generic_graph.rs Replace Body::basic_blocks() with field access 2022-08-26 14:27:08 +02:00
generic_graphviz.rs Remove redundant graphviz escaping 2022-11-14 15:11:18 +01:00
graphviz.rs Remove WithOptconstParam. 2023-04-20 17:48:32 +00:00
mod.rs Auto merge of #106934 - DrMeepster:offset_of, r=WaffleLapkin 2023-04-22 00:10:44 +00:00
mono.rs Remove WithOptconstParam. 2023-04-20 17:48:32 +00:00
patch.rs Remove identity casts 2023-04-09 23:22:14 +02:00
pretty.rs Remove WithOptconstParam. 2023-04-20 17:48:32 +00:00
query.rs Remove WithOptconstParam. 2023-04-20 17:48:32 +00:00
spanview.rs Rename Abort terminator to Terminate 2023-04-06 09:34:16 +01:00
syntax.rs Auto merge of #104844 - cjgillot:mention-eval-place, r=jackh726,RalfJung 2023-04-22 09:54:21 +00:00
tcx.rs offset_of 2023-04-21 02:14:02 -07:00
terminator.rs Rename Abort terminator to Terminate 2023-04-06 09:34:16 +01:00
traversal.rs Convert manual loop into while let 2023-04-09 23:22:14 +02:00
type_foldable.rs intern offsetof fields 2023-04-21 02:14:03 -07:00
visit.rs Preserve argument indexes when inlining MIR 2023-04-11 11:07:48 +10:00