From b334eef162ba9c10faa97c9d5c5d249f25afc7df Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Tue, 13 Oct 2020 21:42:59 -0700 Subject: Do not ICE with TraitPredicates containing [type error] Fix #77919. --- .../rustc_trait_selection/src/traits/select/mod.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'compiler') diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 4cc4bc0acda..d4124c82197 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -2031,12 +2031,19 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { &predicate.subst(tcx, substs), &mut obligations, ); - obligations.push(Obligation { - cause: cause.clone(), - recursion_depth, - param_env, - predicate, - }); + if predicate.references_error() { + self.tcx().sess.delay_span_bug( + cause.span, + &format!("impl_or_trait_obligation with errors: {:?}", predicate), + ); + } else { + obligations.push(Obligation { + cause: cause.clone(), + recursion_depth, + param_env, + predicate, + }); + } } // We are performing deduplication here to avoid exponential blowups -- cgit 1.4.1-3-g733a5 From f71e9ed7f1b88f303519dcd7c2cc69117ff95094 Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Fri, 23 Oct 2020 12:51:06 -0700 Subject: review comments --- compiler/rustc_trait_selection/src/traits/codegen.rs | 5 ++++- .../rustc_trait_selection/src/traits/select/mod.rs | 19 ++++++------------- 2 files changed, 10 insertions(+), 14 deletions(-) (limited to 'compiler') diff --git a/compiler/rustc_trait_selection/src/traits/codegen.rs b/compiler/rustc_trait_selection/src/traits/codegen.rs index 05e6c4804ff..3cb6ec86261 100644 --- a/compiler/rustc_trait_selection/src/traits/codegen.rs +++ b/compiler/rustc_trait_selection/src/traits/codegen.rs @@ -121,7 +121,10 @@ where // contains unbound type parameters. It could be a slight // optimization to stop iterating early. if let Err(errors) = fulfill_cx.select_all_or_error(infcx) { - bug!("Encountered errors `{:?}` resolving bounds after type-checking", errors); + infcx.tcx.sess.delay_span_bug( + rustc_span::DUMMY_SP, + &format!("Encountered errors `{:?}` resolving bounds after type-checking", errors), + ); } let result = infcx.resolve_vars_if_possible(result); diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index d4124c82197..4cc4bc0acda 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -2031,19 +2031,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { &predicate.subst(tcx, substs), &mut obligations, ); - if predicate.references_error() { - self.tcx().sess.delay_span_bug( - cause.span, - &format!("impl_or_trait_obligation with errors: {:?}", predicate), - ); - } else { - obligations.push(Obligation { - cause: cause.clone(), - recursion_depth, - param_env, - predicate, - }); - } + obligations.push(Obligation { + cause: cause.clone(), + recursion_depth, + param_env, + predicate, + }); } // We are performing deduplication here to avoid exponential blowups -- cgit 1.4.1-3-g733a5