diff --git a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs index d83320f5fe800..3a98abf06a342 100644 --- a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs @@ -870,7 +870,7 @@ where ( RerunCondition::OpaqueInStorageOrAnyOpaqueHasInferAsHidden(_), TypingMode::PostAnalysis | TypingMode::Codegen, - ) => RerunDecision::No, + ) => RerunDecision::Yes, ( RerunCondition::OpaqueInStorageOrAnyOpaqueHasInferAsHidden(defids), TypingMode::Typeck { defining_opaque_types_and_generators: opaques }, diff --git a/tests/ui/traits/next-solver/rerun-if-any-opaque-or-has-infer-as-hidden-in-codegen.rs b/tests/ui/traits/next-solver/rerun-if-any-opaque-or-has-infer-as-hidden-in-codegen.rs new file mode 100644 index 0000000000000..8f691ad8f4c45 --- /dev/null +++ b/tests/ui/traits/next-solver/rerun-if-any-opaque-or-has-infer-as-hidden-in-codegen.rs @@ -0,0 +1,34 @@ +//@ compile-flags: -Znext-solver +//@ check-pass + +fn mk_vec() -> Vec> { + loop {} +} + +fn parse_feature(feature: &str) -> impl Iterator { + std::iter::once(feature) +} + +fn main() { + // In `codegen_select_candidate`, we try to find an impl for `FlatMap::into_iter` + // We try to prove `FlatMap<...>: IntoIterator`. + // The blanket impl requires `FlatMap<...>: Iterator`. + // The `Iterator` impl of `FlatMap` has nested goals: + // `Projection(Fn::Output, iter::Once`. + // We normalize this goal and set rerun condition to `AnyOpaqueHasInferAsHidden` + // with reason `SelfTyInfer` because we instantiated impls with infers when + // assembling candidates for intermediate goals. + // Then we evaluate the normalized goal: + // `Projection(Fn::Output, iter::Once`. + // The alias term is normalized to rigid alias `impl Iterator` as + // we're in `TypingMode::ErasedNotCoherence`. + // But the expected term is revealed `iter::Once` thus relating failed. + // The goal fails with rerun condition `OpaqueInStorage(parse_feature::opaque)`. + // This goal should be rerun in `TypingMode::Codegen` mode, but + // `AnyOpaqueHasInferAsHidden + OpaqueInStorage = OpaqueInStorageOrAnyOpaqueHasInferAsHidden` + // which didn't trigger rerun in `TypingMode::Codegen` mode previously. + mk_vec() + .into_iter() + .flatten() + .flat_map(parse_feature).into_iter(); +}