From 15ee80ade3e857a5549f0202d124239d3b8a74ce Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 14 Oct 2024 13:49:31 -0400 Subject: [PATCH] Register a dummy candidate for failed structural normalization during candiate assembly --- .../src/solve/assembly/mod.rs | 20 +++++++++ .../impl-trait/method-resolution4.next.stderr | 25 ++--------- tests/ui/impl-trait/method-resolution4.rs | 2 - .../recursive-coroutine-boxed.next.stderr | 27 ++---------- .../impl-trait/recursive-coroutine-boxed.rs | 3 -- .../opaque-type-unsatisfied-bound.rs | 3 -- .../opaque-type-unsatisfied-bound.stderr | 41 ++++--------------- .../opaque-type-unsatisfied-fn-bound.rs | 1 - .../opaque-type-unsatisfied-fn-bound.stderr | 11 +---- .../traits/next-solver/dyn-incompatibility.rs | 1 - .../next-solver/dyn-incompatibility.stderr | 15 +------ 11 files changed, 36 insertions(+), 113 deletions(-) diff --git a/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs b/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs index cebeef76bfc03..0741f75fb380f 100644 --- a/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs @@ -6,6 +6,7 @@ use derive_where::derive_where; use rustc_type_ir::fold::TypeFoldable; use rustc_type_ir::inherent::*; use rustc_type_ir::lang_items::TraitSolverLangItem; +use rustc_type_ir::solve::inspect; use rustc_type_ir::visit::TypeVisitableExt as _; use rustc_type_ir::{self as ty, Interner, Upcast as _, elaborate}; use tracing::{debug, instrument}; @@ -288,6 +289,25 @@ where let Ok(normalized_self_ty) = self.structurally_normalize_ty(goal.param_env, goal.predicate.self_ty()) else { + // HACK: Register a fake candidate when normalization fails so that + // we can point at the reason for *why*. I'm tempted to say that this + // is the wrong way to do this, though. + let result = + self.probe(|&result| inspect::ProbeKind::RigidAlias { result }).enter(|this| { + let normalized_ty = this.next_ty_infer(); + let alias_relate_goal = Goal::new( + this.cx(), + goal.param_env, + ty::PredicateKind::AliasRelate( + goal.predicate.self_ty().into(), + normalized_ty.into(), + ty::AliasRelationDirection::Equate, + ), + ); + this.add_goal(GoalSource::AliasWellFormed, alias_relate_goal); + this.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS) + }); + assert_eq!(result, Err(NoSolution)); return vec![]; }; diff --git a/tests/ui/impl-trait/method-resolution4.next.stderr b/tests/ui/impl-trait/method-resolution4.next.stderr index 8eacfd3e44d40..0524f49f98e58 100644 --- a/tests/ui/impl-trait/method-resolution4.next.stderr +++ b/tests/ui/impl-trait/method-resolution4.next.stderr @@ -1,28 +1,9 @@ error[E0282]: type annotations needed - --> $DIR/method-resolution4.rs:14:9 + --> $DIR/method-resolution4.rs:13:9 | LL | foo(false).next().unwrap(); | ^^^^^^^^^^ cannot infer type -error[E0277]: the size for values of type `impl Iterator` cannot be known at compilation time - --> $DIR/method-resolution4.rs:11:20 - | -LL | fn foo(b: bool) -> impl Iterator { - | ^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `impl Iterator` - = note: the return type of a function must have a statically known size - -error[E0277]: the size for values of type `impl Iterator` cannot be known at compilation time - --> $DIR/method-resolution4.rs:14:9 - | -LL | foo(false).next().unwrap(); - | ^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `impl Iterator` - = note: the return type of a function must have a statically known size - -error: aborting due to 3 previous errors +error: aborting due to 1 previous error -Some errors have detailed explanations: E0277, E0282. -For more information about an error, try `rustc --explain E0277`. +For more information about this error, try `rustc --explain E0282`. diff --git a/tests/ui/impl-trait/method-resolution4.rs b/tests/ui/impl-trait/method-resolution4.rs index 8eeedf04cbeb1..5c8813ed79224 100644 --- a/tests/ui/impl-trait/method-resolution4.rs +++ b/tests/ui/impl-trait/method-resolution4.rs @@ -9,11 +9,9 @@ //@[current] check-pass fn foo(b: bool) -> impl Iterator { - //[next]~^ ERROR the size for values of type `impl Iterator` cannot be known at compilation time if b { foo(false).next().unwrap(); //[next]~^ type annotations needed - //[next]~| ERROR the size for values of type `impl Iterator` cannot be known at compilation time } std::iter::empty() } diff --git a/tests/ui/impl-trait/recursive-coroutine-boxed.next.stderr b/tests/ui/impl-trait/recursive-coroutine-boxed.next.stderr index b38850c9214e4..132f7de4ef230 100644 --- a/tests/ui/impl-trait/recursive-coroutine-boxed.next.stderr +++ b/tests/ui/impl-trait/recursive-coroutine-boxed.next.stderr @@ -1,9 +1,9 @@ error[E0282]: type annotations needed - --> $DIR/recursive-coroutine-boxed.rs:16:23 + --> $DIR/recursive-coroutine-boxed.rs:14:23 | LL | let mut gen = Box::pin(foo()); | ^^^^^^^^ cannot infer type of the type parameter `T` declared on the struct `Box` -... +LL | LL | let mut r = gen.as_mut().resume(()); | ------ type must be known at this point | @@ -12,25 +12,6 @@ help: consider specifying the generic argument LL | let mut gen = Box::::pin(foo()); | +++++ -error[E0277]: the size for values of type `impl Coroutine` cannot be known at compilation time - --> $DIR/recursive-coroutine-boxed.rs:9:13 - | -LL | fn foo() -> impl Coroutine { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `impl Coroutine` - = note: the return type of a function must have a statically known size - -error[E0277]: the size for values of type `impl Coroutine` cannot be known at compilation time - --> $DIR/recursive-coroutine-boxed.rs:16:32 - | -LL | let mut gen = Box::pin(foo()); - | ^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `impl Coroutine` - = note: the return type of a function must have a statically known size - -error: aborting due to 3 previous errors +error: aborting due to 1 previous error -Some errors have detailed explanations: E0277, E0282. -For more information about an error, try `rustc --explain E0277`. +For more information about this error, try `rustc --explain E0282`. diff --git a/tests/ui/impl-trait/recursive-coroutine-boxed.rs b/tests/ui/impl-trait/recursive-coroutine-boxed.rs index 8e670dd78ecb5..8d38e6aed1246 100644 --- a/tests/ui/impl-trait/recursive-coroutine-boxed.rs +++ b/tests/ui/impl-trait/recursive-coroutine-boxed.rs @@ -7,15 +7,12 @@ use std::ops::{Coroutine, CoroutineState}; fn foo() -> impl Coroutine { - //[next]~^ ERROR the size for values of type `impl Coroutine` cannot be known at compilation time - // FIXME(-Znext-solver): this fails with a mismatched types as the // hidden type of the opaque ends up as {type error}. We should not // emit errors for such goals. #[coroutine] || { let mut gen = Box::pin(foo()); //[next]~^ ERROR type annotations needed - //[next]~| ERROR the size for values of type `impl Coroutine` cannot be known at compilation time let mut r = gen.as_mut().resume(()); while let CoroutineState::Yielded(v) = r { yield v; diff --git a/tests/ui/traits/negative-bounds/opaque-type-unsatisfied-bound.rs b/tests/ui/traits/negative-bounds/opaque-type-unsatisfied-bound.rs index 70cc47bb0225f..25034b67e35b8 100644 --- a/tests/ui/traits/negative-bounds/opaque-type-unsatisfied-bound.rs +++ b/tests/ui/traits/negative-bounds/opaque-type-unsatisfied-bound.rs @@ -15,15 +15,12 @@ fn main() { fn weird0() -> impl Sized + !Sized {} //~^ ERROR the size for values of type `()` cannot be known at compilation time [E0277] //~| ERROR the size for values of type `()` cannot be known at compilation time [E0277] -//~| ERROR the size for values of type `impl !Sized + Sized` cannot be known at compilation time [E0277] //~| ERROR the size for values of type `()` cannot be known at compilation time [E0277] fn weird1() -> impl !Sized + Sized {} //~^ ERROR the size for values of type `()` cannot be known at compilation time [E0277] //~| ERROR the size for values of type `()` cannot be known at compilation time [E0277] -//~| ERROR the size for values of type `impl !Sized + Sized` cannot be known at compilation time [E0277] //~| ERROR the size for values of type `()` cannot be known at compilation time [E0277] fn weird2() -> impl !Sized {} //~^ ERROR the size for values of type `()` cannot be known at compilation time [E0277] //~| ERROR the size for values of type `()` cannot be known at compilation time [E0277] -//~| ERROR the size for values of type `impl !Sized` cannot be known at compilation time [E0277] //~| ERROR the size for values of type `()` cannot be known at compilation time [E0277] diff --git a/tests/ui/traits/negative-bounds/opaque-type-unsatisfied-bound.stderr b/tests/ui/traits/negative-bounds/opaque-type-unsatisfied-bound.stderr index 366baf26dea94..3e803a1c24fa3 100644 --- a/tests/ui/traits/negative-bounds/opaque-type-unsatisfied-bound.stderr +++ b/tests/ui/traits/negative-bounds/opaque-type-unsatisfied-bound.stderr @@ -14,15 +14,6 @@ LL | fn weird0() -> impl Sized + !Sized {} | = help: the trait bound `(): !Sized` is not satisfied -error[E0277]: the size for values of type `impl !Sized + Sized` cannot be known at compilation time - --> $DIR/opaque-type-unsatisfied-bound.rs:15:16 - | -LL | fn weird0() -> impl Sized + !Sized {} - | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `impl !Sized + Sized` - = note: the return type of a function must have a statically known size - error[E0277]: the size for values of type `()` cannot be known at compilation time --> $DIR/opaque-type-unsatisfied-bound.rs:15:1 | @@ -32,7 +23,7 @@ LL | fn weird0() -> impl Sized + !Sized {} = help: the trait bound `(): !Sized` is not satisfied error[E0277]: the size for values of type `()` cannot be known at compilation time - --> $DIR/opaque-type-unsatisfied-bound.rs:20:16 + --> $DIR/opaque-type-unsatisfied-bound.rs:19:16 | LL | fn weird1() -> impl !Sized + Sized {} | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time @@ -40,24 +31,15 @@ LL | fn weird1() -> impl !Sized + Sized {} = help: the trait bound `(): !Sized` is not satisfied error[E0277]: the size for values of type `()` cannot be known at compilation time - --> $DIR/opaque-type-unsatisfied-bound.rs:20:36 + --> $DIR/opaque-type-unsatisfied-bound.rs:19:36 | LL | fn weird1() -> impl !Sized + Sized {} | ^^ doesn't have a size known at compile-time | = help: the trait bound `(): !Sized` is not satisfied -error[E0277]: the size for values of type `impl !Sized + Sized` cannot be known at compilation time - --> $DIR/opaque-type-unsatisfied-bound.rs:20:16 - | -LL | fn weird1() -> impl !Sized + Sized {} - | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `impl !Sized + Sized` - = note: the return type of a function must have a statically known size - error[E0277]: the size for values of type `()` cannot be known at compilation time - --> $DIR/opaque-type-unsatisfied-bound.rs:20:1 + --> $DIR/opaque-type-unsatisfied-bound.rs:19:1 | LL | fn weird1() -> impl !Sized + Sized {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time @@ -65,7 +47,7 @@ LL | fn weird1() -> impl !Sized + Sized {} = help: the trait bound `(): !Sized` is not satisfied error[E0277]: the size for values of type `()` cannot be known at compilation time - --> $DIR/opaque-type-unsatisfied-bound.rs:25:16 + --> $DIR/opaque-type-unsatisfied-bound.rs:23:16 | LL | fn weird2() -> impl !Sized {} | ^^^^^^^^^^^ doesn't have a size known at compile-time @@ -73,24 +55,15 @@ LL | fn weird2() -> impl !Sized {} = help: the trait bound `(): !Sized` is not satisfied error[E0277]: the size for values of type `()` cannot be known at compilation time - --> $DIR/opaque-type-unsatisfied-bound.rs:25:28 + --> $DIR/opaque-type-unsatisfied-bound.rs:23:28 | LL | fn weird2() -> impl !Sized {} | ^^ doesn't have a size known at compile-time | = help: the trait bound `(): !Sized` is not satisfied -error[E0277]: the size for values of type `impl !Sized` cannot be known at compilation time - --> $DIR/opaque-type-unsatisfied-bound.rs:25:16 - | -LL | fn weird2() -> impl !Sized {} - | ^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `impl !Sized` - = note: the return type of a function must have a statically known size - error[E0277]: the size for values of type `()` cannot be known at compilation time - --> $DIR/opaque-type-unsatisfied-bound.rs:25:1 + --> $DIR/opaque-type-unsatisfied-bound.rs:23:1 | LL | fn weird2() -> impl !Sized {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time @@ -111,6 +84,6 @@ note: required by a bound in `consume` LL | fn consume(_: impl Trait) {} | ^^^^^ required by this bound in `consume` -error: aborting due to 13 previous errors +error: aborting due to 10 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/negative-bounds/opaque-type-unsatisfied-fn-bound.rs b/tests/ui/traits/negative-bounds/opaque-type-unsatisfied-fn-bound.rs index 3633e9f3f481c..7538e3c0d2bba 100644 --- a/tests/ui/traits/negative-bounds/opaque-type-unsatisfied-fn-bound.rs +++ b/tests/ui/traits/negative-bounds/opaque-type-unsatisfied-fn-bound.rs @@ -5,7 +5,6 @@ fn produce() -> impl !Fn<(u32,)> {} //~^ ERROR expected a `Fn(u32)` closure, found `()` //~| ERROR expected a `Fn(u32)` closure, found `()` -//~| ERROR the size for values of type `impl !Fn<(u32,)>` cannot be known at compilation time //~| ERROR expected a `Fn(u32)` closure, found `()` fn main() {} diff --git a/tests/ui/traits/negative-bounds/opaque-type-unsatisfied-fn-bound.stderr b/tests/ui/traits/negative-bounds/opaque-type-unsatisfied-fn-bound.stderr index cdd89de0d888e..57a423741b394 100644 --- a/tests/ui/traits/negative-bounds/opaque-type-unsatisfied-fn-bound.stderr +++ b/tests/ui/traits/negative-bounds/opaque-type-unsatisfied-fn-bound.stderr @@ -14,15 +14,6 @@ LL | fn produce() -> impl !Fn<(u32,)> {} | = help: the trait bound `(): !Fn(u32)` is not satisfied -error[E0277]: the size for values of type `impl !Fn<(u32,)>` cannot be known at compilation time - --> $DIR/opaque-type-unsatisfied-fn-bound.rs:5:17 - | -LL | fn produce() -> impl !Fn<(u32,)> {} - | ^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `impl !Fn<(u32,)>` - = note: the return type of a function must have a statically known size - error[E0277]: expected a `Fn(u32)` closure, found `()` --> $DIR/opaque-type-unsatisfied-fn-bound.rs:5:1 | @@ -31,6 +22,6 @@ LL | fn produce() -> impl !Fn<(u32,)> {} | = help: the trait bound `(): !Fn(u32)` is not satisfied -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/next-solver/dyn-incompatibility.rs b/tests/ui/traits/next-solver/dyn-incompatibility.rs index b53a6543c90a4..a347984daf6a6 100644 --- a/tests/ui/traits/next-solver/dyn-incompatibility.rs +++ b/tests/ui/traits/next-solver/dyn-incompatibility.rs @@ -13,7 +13,6 @@ pub fn copy_any(t: &T) -> T { //~^ ERROR the trait bound `T: Copy` is not satisfied in `dyn Setup` //~| ERROR mismatched types //~| ERROR the trait bound `T: Copy` is not satisfied - //~| ERROR the size for values of type ` as Setup>::From` cannot be known at compilation time // FIXME(-Znext-solver): These error messages are horrible and some of them // are even simple fallout from previous error. diff --git a/tests/ui/traits/next-solver/dyn-incompatibility.stderr b/tests/ui/traits/next-solver/dyn-incompatibility.stderr index adf46686e081a..7f2c0646ef501 100644 --- a/tests/ui/traits/next-solver/dyn-incompatibility.stderr +++ b/tests/ui/traits/next-solver/dyn-incompatibility.stderr @@ -43,20 +43,7 @@ help: consider restricting type parameter `T` LL | pub fn copy_any(t: &T) -> T { | +++++++++++++++++++ -error[E0277]: the size for values of type ` as Setup>::From` cannot be known at compilation time - --> $DIR/dyn-incompatibility.rs:12:5 - | -LL | copy::>(t) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for ` as Setup>::From` - = note: the return type of a function must have a statically known size -help: consider further restricting the associated type - | -LL | pub fn copy_any(t: &T) -> T where as Setup>::From: Sized { - | +++++++++++++++++++++++++++++++++++++++++++++++++ - -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors Some errors have detailed explanations: E0277, E0308. For more information about an error, try `rustc --explain E0277`.