From 8492460fa461104d305625ee0a477db0dcd16b82 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 7 May 2022 10:24:45 +0200 Subject: [PATCH 1/3] Also check TraitRef with impossible predicates. --- compiler/rustc_trait_selection/src/traits/mod.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index 8240f5c542a61..8dcd0ff9fee99 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -461,6 +461,14 @@ fn subst_and_check_impossible_predicates<'tcx>( debug!("subst_and_check_impossible_predicates(key={:?})", key); let mut predicates = tcx.predicates_of(key.0).instantiate(tcx, key.1).predicates; + + // Specifically check trait fulfillment to avoid an error when trying to resolve + // associated items. + if let Some(trait_def_id) = tcx.trait_of_item(key.0) { + let trait_ref = ty::TraitRef::from_method(tcx, trait_def_id, key.1); + predicates.push(ty::Binder::dummy(trait_ref).to_poly_trait_predicate().to_predicate(tcx)); + } + predicates.retain(|predicate| !predicate.needs_subst()); let result = impossible_predicates(tcx, predicates); From 6b348257a19165c9c1025a46b24f0bc128842bd4 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 30 Apr 2022 20:03:27 +0200 Subject: [PATCH 2/3] Cleanup opaque type storage after checking impossible predicates. --- compiler/rustc_trait_selection/src/traits/mod.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index 8dcd0ff9fee99..8683de9fa7447 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -448,6 +448,9 @@ pub fn impossible_predicates<'tcx>( let errors = fulfill_cx.select_all_or_error(&infcx); + // Clean up after ourselves + let _ = infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types(); + !errors.is_empty() }); debug!("impossible_predicates = {:?}", result); From 69e5b2fde01e93a19a8102201ed1b1d2cab0661d Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 30 Apr 2022 22:02:11 +0200 Subject: [PATCH 3/3] Do not report overflow error. --- compiler/rustc_trait_selection/src/traits/mod.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index 8683de9fa7447..81819534e8b3b 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -432,6 +432,9 @@ pub fn impossible_predicates<'tcx>( debug!("impossible_predicates(predicates={:?})", predicates); let result = tcx.infer_ctxt().enter(|infcx| { + // HACK: Set tainted by errors to gracefully exit in case of overflow. + infcx.set_tainted_by_errors(); + let param_env = ty::ParamEnv::reveal_all(); let mut selcx = SelectionContext::new(&infcx); let mut fulfill_cx = FulfillmentContext::new();