Skip to content

Commit e02ea83

Browse files
Don't stop const-checking after erroneous trait bound
1 parent 879d379 commit e02ea83

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

compiler/rustc_mir/src/transform/check_consts/ops.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,9 +598,16 @@ pub mod ty {
598598
}
599599

600600
#[derive(Debug)]
601-
pub struct TraitBound;
601+
pub struct TraitBound(pub mir::LocalKind);
602602
impl NonConstOp for TraitBound {
603-
const STOPS_CONST_CHECKING: bool = true;
603+
fn importance(&self) -> DiagnosticImportance {
604+
match self.0 {
605+
mir::LocalKind::Var | mir::LocalKind::Temp => DiagnosticImportance::Secondary,
606+
mir::LocalKind::ReturnPointer | mir::LocalKind::Arg => {
607+
DiagnosticImportance::Primary
608+
}
609+
}
610+
}
604611

605612
fn status_in_item(&self, ccx: &ConstCx<'_, '_>) -> Status {
606613
mcf_status_in_item(ccx)

compiler/rustc_mir/src/transform/check_consts/validation.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,11 @@ impl Validator<'mir, 'tcx> {
364364
match pred.skip_binder() {
365365
ty::ExistentialPredicate::AutoTrait(_)
366366
| ty::ExistentialPredicate::Projection(_) => {
367-
self.check_op(ops::ty::TraitBound)
367+
self.check_op(ops::ty::TraitBound(kind))
368368
}
369369
ty::ExistentialPredicate::Trait(trait_ref) => {
370370
if Some(trait_ref.def_id) != self.tcx.lang_items().sized_trait() {
371-
self.check_op(ops::ty::TraitBound)
371+
self.check_op(ops::ty::TraitBound(kind))
372372
}
373373
}
374374
}
@@ -413,15 +413,19 @@ impl Validator<'mir, 'tcx> {
413413
let def = generics.type_param(p, tcx);
414414
let span = tcx.def_span(def.def_id);
415415

416+
// These are part of the function signature, so treat them like
417+
// arguments when determining importance.
418+
let kind = LocalKind::Arg;
419+
416420
if constness == hir::Constness::Const {
417-
self.check_op_spanned(ops::ty::TraitBound, span);
421+
self.check_op_spanned(ops::ty::TraitBound(kind), span);
418422
} else if !tcx.features().const_fn
419423
|| self.ccx.is_const_stable_const_fn()
420424
{
421425
// HACK: We shouldn't need the conditional above, but trait
422426
// bounds on containing impl blocks are wrongly being marked as
423427
// "not-const".
424-
self.check_op_spanned(ops::ty::TraitBound, span);
428+
self.check_op_spanned(ops::ty::TraitBound(kind), span);
425429
}
426430
}
427431
// other kinds of bounds are either tautologies

0 commit comments

Comments
 (0)