From 2062f2ca8261b521caa9c34c195bf472dcb59e98 Mon Sep 17 00:00:00 2001 From: lcnr Date: Thu, 20 Jul 2023 10:40:59 +0200 Subject: [PATCH] review --- .../src/solve/assembly/mod.rs | 8 +++---- ...mble-normalizing-self-ty-impl-ambiguity.rs | 2 ++ ...-normalizing-self-ty-impl-ambiguity.stderr | 23 ------------------- .../dont-normalize-proj-with-error.rs | 22 ++++++++++++++++++ .../dont-normalize-proj-with-error.stderr | 9 ++++++++ 5 files changed, 37 insertions(+), 27 deletions(-) delete mode 100644 tests/ui/traits/new-solver/assembly/assemble-normalizing-self-ty-impl-ambiguity.stderr create mode 100644 tests/ui/traits/new-solver/dont-normalize-proj-with-error.rs create mode 100644 tests/ui/traits/new-solver/dont-normalize-proj-with-error.stderr diff --git a/compiler/rustc_trait_selection/src/solve/assembly/mod.rs b/compiler/rustc_trait_selection/src/solve/assembly/mod.rs index 68e931aac8c..b661ff481a0 100644 --- a/compiler/rustc_trait_selection/src/solve/assembly/mod.rs +++ b/compiler/rustc_trait_selection/src/solve/assembly/mod.rs @@ -311,7 +311,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { goal: Goal<'tcx, G>, ) -> Vec> { debug_assert_eq!(goal, self.resolve_vars_if_possible(goal)); - if let Some(ambig) = self.self_ty_infer_ambiguity_hack(goal) { + if let Some(ambig) = self.assemble_self_ty_infer_ambiguity_response(goal) { return ambig; } @@ -324,13 +324,13 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { candidates } - /// HACK: `_: Trait` is ambiguous, because it may be satisfied via a builtin rule, + /// `?0: Trait` is ambiguous, because it may be satisfied via a builtin rule, /// object bound, alias bound, etc. We are unable to determine this until we can at /// least structurally resolve the type one layer. /// /// It would also require us to consider all impls of the trait, which is both pretty /// bad for perf and would also constrain the self type if there is just a single impl. - fn self_ty_infer_ambiguity_hack>( + fn assemble_self_ty_infer_ambiguity_response>( &mut self, goal: Goal<'tcx, G>, ) -> Option>> { @@ -353,7 +353,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { goal: Goal<'tcx, G>, ) -> Vec> { debug_assert_eq!(goal, self.resolve_vars_if_possible(goal)); - if let Some(ambig) = self.self_ty_infer_ambiguity_hack(goal) { + if let Some(ambig) = self.assemble_self_ty_infer_ambiguity_response(goal) { return ambig; } diff --git a/tests/ui/traits/new-solver/assembly/assemble-normalizing-self-ty-impl-ambiguity.rs b/tests/ui/traits/new-solver/assembly/assemble-normalizing-self-ty-impl-ambiguity.rs index 727ce84ba35..826e8c1e0b1 100644 --- a/tests/ui/traits/new-solver/assembly/assemble-normalizing-self-ty-impl-ambiguity.rs +++ b/tests/ui/traits/new-solver/assembly/assemble-normalizing-self-ty-impl-ambiguity.rs @@ -1,7 +1,9 @@ // compile-flags: -Ztrait-solver=next +// check-pass // Checks that we do not get ambiguity by considering an impl // multiple times if we're able to normalize the self type. + trait Trait<'a> {} impl<'a, T: 'a> Trait<'a> for T {} diff --git a/tests/ui/traits/new-solver/assembly/assemble-normalizing-self-ty-impl-ambiguity.stderr b/tests/ui/traits/new-solver/assembly/assemble-normalizing-self-ty-impl-ambiguity.stderr deleted file mode 100644 index 91b635b35eb..00000000000 --- a/tests/ui/traits/new-solver/assembly/assemble-normalizing-self-ty-impl-ambiguity.stderr +++ /dev/null @@ -1,23 +0,0 @@ -error[E0283]: type annotations needed: cannot satisfy `::Assoc: Trait<'_>` - --> $DIR/assemble-normalizing-self-ty-impl-ambiguity.rs:19:5 - | -LL | impls_trait::<::Assoc>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: cannot satisfy `::Assoc: Trait<'_>` -note: required by a bound in `impls_trait` - --> $DIR/assemble-normalizing-self-ty-impl-ambiguity.rs:9:23 - | -LL | fn impls_trait<'a, T: Trait<'a>>() {} - | ^^^^^^^^^ required by this bound in `impls_trait` - -error[E0282]: type annotations needed - --> $DIR/assemble-normalizing-self-ty-impl-ambiguity.rs:24:5 - | -LL | impls_trait::<<<() as Id>::Assoc as Id>::Assoc>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `impls_trait` - -error: aborting due to 2 previous errors - -Some errors have detailed explanations: E0282, E0283. -For more information about an error, try `rustc --explain E0282`. diff --git a/tests/ui/traits/new-solver/dont-normalize-proj-with-error.rs b/tests/ui/traits/new-solver/dont-normalize-proj-with-error.rs new file mode 100644 index 00000000000..19a6fa990ff --- /dev/null +++ b/tests/ui/traits/new-solver/dont-normalize-proj-with-error.rs @@ -0,0 +1,22 @@ +// compile-flags: -Ztrait-solver=next + +// Test that we don't incorrectly leak unconstrained inference variables +// if the projection contained an error. This caused an ICE in writeback. + +trait Mirror { + type Assoc: ?Sized; +} + +struct Wrapper(T); +impl Mirror for Wrapper { + type Assoc = T; +} + +fn mirror(_: W) -> Box { todo!() } + +fn type_error() -> TypeError { todo!() } +//~^ ERROR cannot find type `TypeError` in this scope + +fn main() { + let x = mirror(type_error()); +} diff --git a/tests/ui/traits/new-solver/dont-normalize-proj-with-error.stderr b/tests/ui/traits/new-solver/dont-normalize-proj-with-error.stderr new file mode 100644 index 00000000000..5a7459ec1fd --- /dev/null +++ b/tests/ui/traits/new-solver/dont-normalize-proj-with-error.stderr @@ -0,0 +1,9 @@ +error[E0412]: cannot find type `TypeError` in this scope + --> $DIR/dont-normalize-proj-with-error.rs:17:20 + | +LL | fn type_error() -> TypeError { todo!() } + | ^^^^^^^^^ not found in this scope + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0412`.