diff --git a/src/librustc_mir/error_codes.rs b/src/librustc_mir/error_codes.rs index 419c905cb5127..c119ca536fb52 100644 --- a/src/librustc_mir/error_codes.rs +++ b/src/librustc_mir/error_codes.rs @@ -2545,7 +2545,7 @@ There are some known bugs that trigger this message. // E0471, // constant evaluation error (in pattern) // E0385, // {} in an aliasable location E0521, // borrowed data escapes outside of closure - E0526, // shuffle indices are not constant +// E0526, // shuffle indices are not constant E0594, // cannot assign to {} // E0598, // lifetime of {} is too short to guarantee its contents can be... E0625, // thread-local statics cannot be accessed at compile-time diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index 8def717f1580a..83f3aafc55cb1 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -80,6 +80,17 @@ pub enum Candidate { Argument { bb: BasicBlock, index: usize }, } +impl Candidate { + /// Returns `true` if we should use the "explicit" rules for promotability for this `Candidate`. + fn forces_explicit_promotion(&self) -> bool { + match self { + Candidate::Ref(_) | + Candidate::Repeat(_) => false, + Candidate::Argument { .. } => true, + } + } +} + fn args_required_const(tcx: TyCtxt<'_>, def_id: DefId) -> Option> { let attrs = tcx.get_attrs(def_id); let attr = attrs.iter().find(|a| a.check_name(sym::rustc_args_required_const))?; @@ -727,16 +738,22 @@ pub fn validate_candidates( }; candidates.iter().copied().filter(|&candidate| { - validator.explicit = match candidate { - Candidate::Ref(_) | - Candidate::Repeat(_) => false, - Candidate::Argument { .. } => true, - }; + validator.explicit = candidate.forces_explicit_promotion(); // FIXME(eddyb) also emit the errors for shuffle indices // and `#[rustc_args_required_const]` arguments here. - validator.validate_candidate(candidate).is_ok() + let is_promotable = validator.validate_candidate(candidate).is_ok(); + match candidate { + Candidate::Argument { bb, index } if !is_promotable => { + let span = body[bb].terminator().source_info.span; + let msg = format!("argument {} is required to be a constant", index + 1); + tcx.sess.span_err(span, &msg); + } + _ => () + } + + is_promotable }).collect() } diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 3702dd9ad493f..f488b457334e5 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -1606,20 +1606,12 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> { // This is not a problem, because the argument explicitly // requests constness, in contrast to regular promotion // which happens even without the user requesting it. - // We can error out with a hard error if the argument is not - // constant here. + // + // `promote_consts` is responsible for emitting the error if + // the argument is not promotable. if !IsNotPromotable::in_operand(self, arg) { debug!("visit_terminator_kind: candidate={:?}", candidate); self.promotion_candidates.push(candidate); - } else { - if is_shuffle { - span_err!(self.tcx.sess, self.span, E0526, - "shuffle indices are not constant"); - } else { - self.tcx.sess.span_err(self.span, - &format!("argument {} is required to be a constant", - i + 1)); - } } } } diff --git a/src/tools/tidy/src/error_codes_check.rs b/src/tools/tidy/src/error_codes_check.rs index 159baff184d1b..bd58de81c778a 100644 --- a/src/tools/tidy/src/error_codes_check.rs +++ b/src/tools/tidy/src/error_codes_check.rs @@ -40,7 +40,6 @@ const WHITELIST: &[&str] = &[ "E0514", "E0519", "E0523", - "E0526", "E0554", "E0570", "E0629",