Skip to content

Commit

Permalink
Rollup merge of #90925 - krasimirgg:rustc_mir_build_fix, r=petrochenkov
Browse files Browse the repository at this point in the history
rustc_mir_build: reorder bindings

No functional changes intended.

I'm playing around with building compiler components using nightly rust
(2021-11-02) in a non-standard way. I encountered the following error while
trying to build rustc_mir_build:

```
error[E0597]: `wildcard` does not live long enough
    --> rust/src/nightly/compiler/rustc_mir_build/src/build/matches/mod.rs:1767:82
     |
1767 |         let mut otherwise_candidate = Candidate::new(expr_place_builder.clone(), &wildcard, false);
     |                                                                                  ^^^^^^^^^ borrowed value does not live long enough
...
1799 |     }
     |     -
     |     |
     |     `wildcard` dropped here while still borrowed
     |     borrow might be used here, when `guard_candidate` is dropped and runs the destructor for type `Candidate<'_, '_>`
     |
     = note: values in a scope are dropped in the opposite order they are defined
```

I believe this flags an issue that may become an error in the future.
Swapping the order of `wildcard` and `guard_candidate` resolves it.
  • Loading branch information
JohnTitor authored Nov 16, 2021
2 parents 6d9c3a1 + c1c2013 commit cdc12ba
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/build/matches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1762,8 +1762,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
) -> BlockAnd<()> {
let expr_span = expr.span;
let expr_place_builder = unpack!(block = self.lower_scrutinee(block, expr, expr_span));
let mut guard_candidate = Candidate::new(expr_place_builder.clone(), &pat, false);
let wildcard = Pat::wildcard_from_ty(pat.ty);
let mut guard_candidate = Candidate::new(expr_place_builder.clone(), &pat, false);
let mut otherwise_candidate = Candidate::new(expr_place_builder.clone(), &wildcard, false);
let fake_borrow_temps = self.lower_match_tree(
block,
Expand Down

0 comments on commit cdc12ba

Please sign in to comment.