Register a dummy candidate for failed structural normalization during candiate assembly

This commit is contained in:
Michael Goulet 2024-10-14 13:49:31 -04:00
parent 8528387743
commit 0ead25c4a9
11 changed files with 36 additions and 113 deletions

View File

@ -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 {
// FIXME: We 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![];
};

View File

@ -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: aborting due to 1 previous error
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
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`.

View File

@ -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()
}

View File

@ -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::<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: aborting due to 1 previous error
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
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`.

View File

@ -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;

View File

@ -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]

View File

@ -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`.

View File

@ -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() {}

View File

@ -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`.

View File

@ -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.

View File

@ -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`.