From e02ea835a75b75af740a45cf4b29c76610476569 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Tue, 29 Sep 2020 18:52:00 -0700 Subject: [PATCH] Don't stop const-checking after erroneous trait bound --- compiler/rustc_mir/src/transform/check_consts/ops.rs | 11 +++++++++-- .../src/transform/check_consts/validation.rs | 12 ++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_mir/src/transform/check_consts/ops.rs b/compiler/rustc_mir/src/transform/check_consts/ops.rs index 49c465f3d38..6d1125e352e 100644 --- a/compiler/rustc_mir/src/transform/check_consts/ops.rs +++ b/compiler/rustc_mir/src/transform/check_consts/ops.rs @@ -598,9 +598,16 @@ pub mod ty { } #[derive(Debug)] - pub struct TraitBound; + pub struct TraitBound(pub mir::LocalKind); impl NonConstOp for TraitBound { - const STOPS_CONST_CHECKING: bool = true; + fn importance(&self) -> DiagnosticImportance { + match self.0 { + mir::LocalKind::Var | mir::LocalKind::Temp => DiagnosticImportance::Secondary, + mir::LocalKind::ReturnPointer | mir::LocalKind::Arg => { + DiagnosticImportance::Primary + } + } + } fn status_in_item(&self, ccx: &ConstCx<'_, '_>) -> Status { mcf_status_in_item(ccx) diff --git a/compiler/rustc_mir/src/transform/check_consts/validation.rs b/compiler/rustc_mir/src/transform/check_consts/validation.rs index 0781a76a166..a2dff46982b 100644 --- a/compiler/rustc_mir/src/transform/check_consts/validation.rs +++ b/compiler/rustc_mir/src/transform/check_consts/validation.rs @@ -364,11 +364,11 @@ impl Validator<'mir, 'tcx> { match pred.skip_binder() { ty::ExistentialPredicate::AutoTrait(_) | ty::ExistentialPredicate::Projection(_) => { - self.check_op(ops::ty::TraitBound) + self.check_op(ops::ty::TraitBound(kind)) } ty::ExistentialPredicate::Trait(trait_ref) => { if Some(trait_ref.def_id) != self.tcx.lang_items().sized_trait() { - self.check_op(ops::ty::TraitBound) + self.check_op(ops::ty::TraitBound(kind)) } } } @@ -413,15 +413,19 @@ impl Validator<'mir, 'tcx> { let def = generics.type_param(p, tcx); let span = tcx.def_span(def.def_id); + // These are part of the function signature, so treat them like + // arguments when determining importance. + let kind = LocalKind::Arg; + if constness == hir::Constness::Const { - self.check_op_spanned(ops::ty::TraitBound, span); + self.check_op_spanned(ops::ty::TraitBound(kind), span); } else if !tcx.features().const_fn || self.ccx.is_const_stable_const_fn() { // HACK: We shouldn't need the conditional above, but trait // bounds on containing impl blocks are wrongly being marked as // "not-const". - self.check_op_spanned(ops::ty::TraitBound, span); + self.check_op_spanned(ops::ty::TraitBound(kind), span); } } // other kinds of bounds are either tautologies