Skip to content

Commit 9196af0

Browse files
committed
qualify_consts: extract error_min_const_fn_violation.
1 parent 2f733aa commit 9196af0

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

src/librustc_mir/transform/qualify_consts.rs

+11-15
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use syntax::feature_gate::{emit_feature_err, GateIssue};
2525
use syntax::symbol::sym;
2626
use syntax_pos::{Span, DUMMY_SP};
2727

28+
use std::borrow::Cow;
2829
use std::cell::Cell;
2930
use std::fmt;
3031
use std::ops::{Deref, Index, IndexMut};
@@ -1607,26 +1608,14 @@ impl<'tcx> MirPass<'tcx> for QualifyAndPromoteConstants<'tcx> {
16071608
// which can't be mutated until its scope ends.
16081609
let (temps, candidates) = {
16091610
let mut checker = Checker::new(tcx, def_id, body, mode);
1610-
if mode == Mode::ConstFn {
1611+
if let Mode::ConstFn = mode {
16111612
if tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you {
16121613
checker.check_const();
16131614
} 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.
16151616
use super::qualify_min_const_fn::is_min_const_fn;
16161617
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);
16301619
} else {
16311620
// this should not produce any errors, but better safe than sorry
16321621
// FIXME(#53819)
@@ -1677,6 +1666,13 @@ fn determine_mode(tcx: TyCtxt<'_>, hir_id: HirId, def_id: DefId) -> Mode {
16771666
}
16781667
}
16791668

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+
16801676
fn check_short_circuiting_in_const_local(tcx: TyCtxt<'_>, body: &mut Body<'tcx>, mode: Mode) {
16811677
if body.control_flow_destroyed.is_empty() {
16821678
return;

0 commit comments

Comments
 (0)