qualify_consts: extract check_short_circuiting_in_const_local.
This commit is contained in:
parent
8f184b369d
commit
b6360fbc4c
1 changed files with 35 additions and 31 deletions
|
|
@ -1655,37 +1655,8 @@ impl<'tcx> MirPass<'tcx> for QualifyAndPromoteConstants<'tcx> {
|
|||
_ => None,
|
||||
};
|
||||
|
||||
if !body.control_flow_destroyed.is_empty() {
|
||||
let mut locals = body.vars_iter();
|
||||
if let Some(local) = locals.next() {
|
||||
let span = body.local_decls[local].source_info.span;
|
||||
let mut error = tcx.sess.struct_span_err(
|
||||
span,
|
||||
&format!(
|
||||
"new features like let bindings are not permitted in {}s \
|
||||
which also use short circuiting operators",
|
||||
mode,
|
||||
),
|
||||
);
|
||||
for (span, kind) in body.control_flow_destroyed.iter() {
|
||||
error.span_note(
|
||||
*span,
|
||||
&format!("use of {} here does not actually short circuit due to \
|
||||
the const evaluator presently not being able to do control flow. \
|
||||
See https://github.com/rust-lang/rust/issues/49146 for more \
|
||||
information.", kind),
|
||||
);
|
||||
}
|
||||
for local in locals {
|
||||
let span = body.local_decls[local].source_info.span;
|
||||
error.span_note(
|
||||
span,
|
||||
"more locals defined here",
|
||||
);
|
||||
}
|
||||
error.emit();
|
||||
}
|
||||
}
|
||||
check_short_circuiting_in_const_local(tcx, body, mode);
|
||||
|
||||
let promoted_temps = match mode {
|
||||
// Already computed by `mir_const_qualif`.
|
||||
Mode::Const => const_promoted_temps.unwrap(),
|
||||
|
|
@ -1762,6 +1733,39 @@ fn determine_mode(tcx: TyCtxt<'_>, hir_id: HirId, def_id: DefId) -> Mode {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_short_circuiting_in_const_local(tcx: TyCtxt<'_>, body: &mut Body<'tcx>, mode: Mode) {
|
||||
if body.control_flow_destroyed.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
let mut locals = body.vars_iter();
|
||||
if let Some(local) = locals.next() {
|
||||
let span = body.local_decls[local].source_info.span;
|
||||
let mut error = tcx.sess.struct_span_err(
|
||||
span,
|
||||
&format!(
|
||||
"new features like let bindings are not permitted in {}s \
|
||||
which also use short circuiting operators",
|
||||
mode,
|
||||
),
|
||||
);
|
||||
for (span, kind) in body.control_flow_destroyed.iter() {
|
||||
error.span_note(
|
||||
*span,
|
||||
&format!("use of {} here does not actually short circuit due to \
|
||||
the const evaluator presently not being able to do control flow. \
|
||||
See https://github.com/rust-lang/rust/issues/49146 for more \
|
||||
information.", kind),
|
||||
);
|
||||
}
|
||||
for local in locals {
|
||||
let span = body.local_decls[local].source_info.span;
|
||||
error.span_note(span, "more locals defined here");
|
||||
}
|
||||
error.emit();
|
||||
}
|
||||
}
|
||||
|
||||
fn args_required_const(tcx: TyCtxt<'_>, def_id: DefId) -> Option<FxHashSet<usize>> {
|
||||
let attrs = tcx.get_attrs(def_id);
|
||||
let attr = attrs.iter().find(|a| a.check_name(sym::rustc_args_required_const))?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue