Skip to content

Commit

Permalink
Register a dummy candidate for failed structural normalization during…
Browse files Browse the repository at this point in the history
… candiate assembly
  • Loading branch information
compiler-errors committed Oct 16, 2024
1 parent c914388 commit 451e19b
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 113 deletions.
20 changes: 20 additions & 0 deletions compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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![];
};

Expand Down
25 changes: 3 additions & 22 deletions tests/ui/impl-trait/method-resolution4.next.stderr
Original file line number Diff line number Diff line change
@@ -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<Item = ()>` cannot be known at compilation time
--> $DIR/method-resolution4.rs:11:20
|
LL | fn foo(b: bool) -> impl Iterator<Item = ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `impl Iterator<Item = ()>`
= note: the return type of a function must have a statically known size

error[E0277]: the size for values of type `impl Iterator<Item = ()>` 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<Item = ()>`
= 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`.
2 changes: 0 additions & 2 deletions tests/ui/impl-trait/method-resolution4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
//@[current] check-pass

fn foo(b: bool) -> impl Iterator<Item = ()> {
//[next]~^ ERROR the size for values of type `impl Iterator<Item = ()>` 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<Item = ()>` cannot be known at compilation time
}
std::iter::empty()
}
Expand Down
27 changes: 4 additions & 23 deletions tests/ui/impl-trait/recursive-coroutine-boxed.next.stderr
Original file line number Diff line number Diff line change
@@ -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
|
Expand All @@ -12,25 +12,6 @@ help: consider specifying the generic argument
LL | let mut gen = Box::<T>::pin(foo());
| +++++

error[E0277]: the size for values of type `impl Coroutine<Yield = (), Return = ()>` cannot be known at compilation time
--> $DIR/recursive-coroutine-boxed.rs:9:13
|
LL | fn foo() -> impl Coroutine<Yield = (), Return = ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `impl Coroutine<Yield = (), Return = ()>`
= note: the return type of a function must have a statically known size

error[E0277]: the size for values of type `impl Coroutine<Yield = (), Return = ()>` 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<Yield = (), Return = ()>`
= 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`.
3 changes: 0 additions & 3 deletions tests/ui/impl-trait/recursive-coroutine-boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@
use std::ops::{Coroutine, CoroutineState};

fn foo() -> impl Coroutine<Yield = (), Return = ()> {
//[next]~^ ERROR the size for values of type `impl Coroutine<Yield = (), Return = ()>` 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<Yield = (), Return = ()>` cannot be known at compilation time
let mut r = gen.as_mut().resume(());
while let CoroutineState::Yielded(v) = r {
yield v;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Original file line number Diff line number Diff line change
Expand Up @@ -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
|
Expand All @@ -32,65 +23,47 @@ 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
|
= 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
|
= 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
|
= 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
Expand All @@ -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`.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Original file line number Diff line number Diff line change
Expand Up @@ -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
|
Expand All @@ -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`.
1 change: 0 additions & 1 deletion tests/ui/traits/next-solver/dyn-incompatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pub fn copy_any<T>(t: &T) -> T {
//~^ ERROR the trait bound `T: Copy` is not satisfied in `dyn Setup<From = T>`
//~| ERROR mismatched types
//~| ERROR the trait bound `T: Copy` is not satisfied
//~| ERROR the size for values of type `<dyn Setup<From = T> 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.
Expand Down
15 changes: 1 addition & 14 deletions tests/ui/traits/next-solver/dyn-incompatibility.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,7 @@ help: consider restricting type parameter `T`
LL | pub fn copy_any<T: std::marker::Copy>(t: &T) -> T {
| +++++++++++++++++++

error[E0277]: the size for values of type `<dyn Setup<From = T> as Setup>::From` cannot be known at compilation time
--> $DIR/dyn-incompatibility.rs:12:5
|
LL | copy::<dyn Setup<From=T>>(t)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `<dyn Setup<From = T> 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) -> T where <dyn Setup<From = T> 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`.

0 comments on commit 451e19b

Please sign in to comment.