@@ -25,6 +25,7 @@ use syntax::feature_gate::{emit_feature_err, GateIssue};
25
25
use syntax:: symbol:: sym;
26
26
use syntax_pos:: { Span , DUMMY_SP } ;
27
27
28
+ use std:: borrow:: Cow ;
28
29
use std:: cell:: Cell ;
29
30
use std:: fmt;
30
31
use std:: ops:: { Deref , Index , IndexMut } ;
@@ -1607,26 +1608,14 @@ impl<'tcx> MirPass<'tcx> for QualifyAndPromoteConstants<'tcx> {
1607
1608
// which can't be mutated until its scope ends.
1608
1609
let ( temps, candidates) = {
1609
1610
let mut checker = Checker :: new ( tcx, def_id, body, mode) ;
1610
- if mode == Mode :: ConstFn {
1611
+ if let Mode :: ConstFn = mode {
1611
1612
if tcx. sess . opts . debugging_opts . unleash_the_miri_inside_of_you {
1612
1613
checker. check_const ( ) ;
1613
1614
} else if tcx. is_min_const_fn ( def_id) {
1614
- // enforce `min_const_fn` for stable const fns
1615
+ // Enforce `min_const_fn` for stable ` const fn`s.
1615
1616
use super :: qualify_min_const_fn:: is_min_const_fn;
1616
1617
if let Err ( ( span, err) ) = is_min_const_fn ( tcx, def_id, body) {
1617
- let mut diag = struct_span_err ! (
1618
- tcx. sess,
1619
- span,
1620
- E0723 ,
1621
- "{}" ,
1622
- err,
1623
- ) ;
1624
- diag. note ( "for more information, see issue \
1625
- https://github.com/rust-lang/rust/issues/57563") ;
1626
- diag. help (
1627
- "add `#![feature(const_fn)]` to the crate attributes to enable" ,
1628
- ) ;
1629
- diag. emit ( ) ;
1618
+ error_min_const_fn_violation ( tcx, span, err) ;
1630
1619
} else {
1631
1620
// this should not produce any errors, but better safe than sorry
1632
1621
// FIXME(#53819)
@@ -1677,6 +1666,13 @@ fn determine_mode(tcx: TyCtxt<'_>, hir_id: HirId, def_id: DefId) -> Mode {
1677
1666
}
1678
1667
}
1679
1668
1669
+ fn error_min_const_fn_violation ( tcx : TyCtxt < ' _ > , span : Span , msg : Cow < ' _ , str > ) {
1670
+ struct_span_err ! ( tcx. sess, span, E0723 , "{}" , msg)
1671
+ . note ( "for more information, see issue https://github.com/rust-lang/rust/issues/57563" )
1672
+ . help ( "add `#![feature(const_fn)]` to the crate attributes to enable" )
1673
+ . emit ( ) ;
1674
+ }
1675
+
1680
1676
fn check_short_circuiting_in_const_local ( tcx : TyCtxt < ' _ > , body : & mut Body < ' tcx > , mode : Mode ) {
1681
1677
if body. control_flow_destroyed . is_empty ( ) {
1682
1678
return ;
0 commit comments