Skip to content

Commit 564f2d3

Browse files
committed
Auto merge of #66537 - nnethercote:delay-is_local_ever_initialized, r=spastorino
Delay an `is_local_ever_initialized` call. This commit moves the call after a `return` that almost always runs. It speeds up the `unicode_normalization` benchmark by about 2%. r? @spastorino
2 parents bd816fd + 9651617 commit 564f2d3

File tree

1 file changed

+12
-12
lines changed
  • src/librustc_mir/borrow_check

1 file changed

+12
-12
lines changed

src/librustc_mir/borrow_check/mod.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -1883,16 +1883,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
18831883
let error_access;
18841884
let the_place_err;
18851885

1886-
// rust-lang/rust#21232, #54986: during period where we reject
1887-
// partial initialization, do not complain about mutability
1888-
// errors except for actual mutation (as opposed to an attempt
1889-
// to do a partial initialization).
1890-
let previously_initialized = if let PlaceBase::Local(local) = place.base {
1891-
self.is_local_ever_initialized(local, flow_state).is_some()
1892-
} else {
1893-
true
1894-
};
1895-
18961886
match kind {
18971887
Reservation(WriteKind::MutableBorrow(borrow_kind @ BorrowKind::Unique))
18981888
| Reservation(WriteKind::MutableBorrow(borrow_kind @ BorrowKind::Mut { .. }))
@@ -1966,8 +1956,18 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
19661956
}
19671957
}
19681958

1959+
// rust-lang/rust#21232, #54986: during period where we reject
1960+
// partial initialization, do not complain about mutability
1961+
// errors except for actual mutation (as opposed to an attempt
1962+
// to do a partial initialization).
1963+
let previously_initialized = if let PlaceBase::Local(local) = place.base {
1964+
self.is_local_ever_initialized(local, flow_state).is_some()
1965+
} else {
1966+
true
1967+
};
1968+
19691969
// at this point, we have set up the error reporting state.
1970-
return if previously_initialized {
1970+
if previously_initialized {
19711971
self.report_mutability_error(
19721972
place,
19731973
span,
@@ -1978,7 +1978,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
19781978
true
19791979
} else {
19801980
false
1981-
};
1981+
}
19821982
}
19831983

19841984
fn is_local_ever_initialized(

0 commit comments

Comments
 (0)