@@ -1655,37 +1655,8 @@ impl<'tcx> MirPass<'tcx> for QualifyAndPromoteConstants<'tcx> {
1655
1655
_ => None ,
1656
1656
} ;
1657
1657
1658
- if !body. control_flow_destroyed . is_empty ( ) {
1659
- let mut locals = body. vars_iter ( ) ;
1660
- if let Some ( local) = locals. next ( ) {
1661
- let span = body. local_decls [ local] . source_info . span ;
1662
- let mut error = tcx. sess . struct_span_err (
1663
- span,
1664
- & format ! (
1665
- "new features like let bindings are not permitted in {}s \
1666
- which also use short circuiting operators",
1667
- mode,
1668
- ) ,
1669
- ) ;
1670
- for ( span, kind) in body. control_flow_destroyed . iter ( ) {
1671
- error. span_note (
1672
- * span,
1673
- & format ! ( "use of {} here does not actually short circuit due to \
1674
- the const evaluator presently not being able to do control flow. \
1675
- See https://github.com/rust-lang/rust/issues/49146 for more \
1676
- information.", kind) ,
1677
- ) ;
1678
- }
1679
- for local in locals {
1680
- let span = body. local_decls [ local] . source_info . span ;
1681
- error. span_note (
1682
- span,
1683
- "more locals defined here" ,
1684
- ) ;
1685
- }
1686
- error. emit ( ) ;
1687
- }
1688
- }
1658
+ check_short_circuiting_in_const_local ( tcx, body, mode) ;
1659
+
1689
1660
let promoted_temps = match mode {
1690
1661
// Already computed by `mir_const_qualif`.
1691
1662
Mode :: Const => const_promoted_temps. unwrap ( ) ,
@@ -1762,6 +1733,39 @@ fn determine_mode(tcx: TyCtxt<'_>, hir_id: HirId, def_id: DefId) -> Mode {
1762
1733
}
1763
1734
}
1764
1735
1736
+ fn check_short_circuiting_in_const_local ( tcx : TyCtxt < ' _ > , body : & mut Body < ' tcx > , mode : Mode ) {
1737
+ if body. control_flow_destroyed . is_empty ( ) {
1738
+ return ;
1739
+ }
1740
+
1741
+ let mut locals = body. vars_iter ( ) ;
1742
+ if let Some ( local) = locals. next ( ) {
1743
+ let span = body. local_decls [ local] . source_info . span ;
1744
+ let mut error = tcx. sess . struct_span_err (
1745
+ span,
1746
+ & format ! (
1747
+ "new features like let bindings are not permitted in {}s \
1748
+ which also use short circuiting operators",
1749
+ mode,
1750
+ ) ,
1751
+ ) ;
1752
+ for ( span, kind) in body. control_flow_destroyed . iter ( ) {
1753
+ error. span_note (
1754
+ * span,
1755
+ & format ! ( "use of {} here does not actually short circuit due to \
1756
+ the const evaluator presently not being able to do control flow. \
1757
+ See https://github.com/rust-lang/rust/issues/49146 for more \
1758
+ information.", kind) ,
1759
+ ) ;
1760
+ }
1761
+ for local in locals {
1762
+ let span = body. local_decls [ local] . source_info . span ;
1763
+ error. span_note ( span, "more locals defined here" ) ;
1764
+ }
1765
+ error. emit ( ) ;
1766
+ }
1767
+ }
1768
+
1765
1769
fn args_required_const ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> Option < FxHashSet < usize > > {
1766
1770
let attrs = tcx. get_attrs ( def_id) ;
1767
1771
let attr = attrs. iter ( ) . find ( |a| a. check_name ( sym:: rustc_args_required_const) ) ?;
0 commit comments