diff options
| author | Tyler Mandry <tmandry@gmail.com> | 2019-11-01 11:20:17 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-11-01 11:20:17 -0700 |
| commit | 4160e5aababbdfbf9743ab37aa8e954b888e9425 (patch) | |
| tree | 17dad49fa9ce2ed35a5bd18a5d88787cb866c36a | |
| parent | b7416348c8155e9cc36dfdce349328ad8bdc402d (diff) | |
| parent | 627e3ef739dbead85aa04f32dc2d2a2ab7dd4637 (diff) | |
| download | rust-4160e5aababbdfbf9743ab37aa8e954b888e9425.tar.gz rust-4160e5aababbdfbf9743ab37aa8e954b888e9425.zip | |
Rollup merge of #65946 - ecstatic-morse:refactor-promotion2, r=eddyb
Make `promote_consts` emit the errors when required promotion fails A very minimal version of #65942. This will cause a generic "argument X is required to be a constant" message for `simd_shuffle` LLVM intrinsics instead of the [custom one](https://github.com/rust-lang/rust/blob/caa1f8d7b3b021c86a70ff62d23a07d97acff4c4/src/librustc_mir/transform/qualify_consts.rs#L1616). It may be possible to remove this special-casing altogether after rust-lang/stdarch#825. r? @eddyb
| -rw-r--r-- | src/librustc_mir/error_codes.rs | 2 | ||||
| -rw-r--r-- | src/librustc_mir/transform/promote_consts.rs | 29 | ||||
| -rw-r--r-- | src/librustc_mir/transform/qualify_consts.rs | 14 | ||||
| -rw-r--r-- | src/tools/tidy/src/error_codes_check.rs | 1 |
4 files changed, 27 insertions, 19 deletions
diff --git a/src/librustc_mir/error_codes.rs b/src/librustc_mir/error_codes.rs index 419c905cb51..c119ca536fb 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 8def717f158..83f3aafc55c 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<Vec<usize>> { 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 3702dd9ad49..f488b457334 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 159baff184d..bd58de81c77 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", |
