Skip to content

Commit 0ead25c

Browse files
Register a dummy candidate for failed structural normalization during candiate assembly
1 parent 8528387 commit 0ead25c

11 files changed

+36
-113
lines changed

compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs

+20
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use derive_where::derive_where;
66
use rustc_type_ir::fold::TypeFoldable;
77
use rustc_type_ir::inherent::*;
88
use rustc_type_ir::lang_items::TraitSolverLangItem;
9+
use rustc_type_ir::solve::inspect;
910
use rustc_type_ir::visit::TypeVisitableExt as _;
1011
use rustc_type_ir::{self as ty, Interner, Upcast as _, elaborate};
1112
use tracing::{debug, instrument};
@@ -288,6 +289,25 @@ where
288289
let Ok(normalized_self_ty) =
289290
self.structurally_normalize_ty(goal.param_env, goal.predicate.self_ty())
290291
else {
292+
// FIXME: We register a fake candidate when normalization fails so that
293+
// we can point at the reason for *why*. I'm tempted to say that this
294+
// is the wrong way to do this, though.
295+
let result =
296+
self.probe(|&result| inspect::ProbeKind::RigidAlias { result }).enter(|this| {
297+
let normalized_ty = this.next_ty_infer();
298+
let alias_relate_goal = Goal::new(
299+
this.cx(),
300+
goal.param_env,
301+
ty::PredicateKind::AliasRelate(
302+
goal.predicate.self_ty().into(),
303+
normalized_ty.into(),
304+
ty::AliasRelationDirection::Equate,
305+
),
306+
);
307+
this.add_goal(GoalSource::AliasWellFormed, alias_relate_goal);
308+
this.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
309+
});
310+
assert_eq!(result, Err(NoSolution));
291311
return vec![];
292312
};
293313

Original file line numberDiff line numberDiff line change
@@ -1,28 +1,9 @@
11
error[E0282]: type annotations needed
2-
--> $DIR/method-resolution4.rs:14:9
2+
--> $DIR/method-resolution4.rs:13:9
33
|
44
LL | foo(false).next().unwrap();
55
| ^^^^^^^^^^ cannot infer type
66

7-
error[E0277]: the size for values of type `impl Iterator<Item = ()>` cannot be known at compilation time
8-
--> $DIR/method-resolution4.rs:11:20
9-
|
10-
LL | fn foo(b: bool) -> impl Iterator<Item = ()> {
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
12-
|
13-
= help: the trait `Sized` is not implemented for `impl Iterator<Item = ()>`
14-
= note: the return type of a function must have a statically known size
15-
16-
error[E0277]: the size for values of type `impl Iterator<Item = ()>` cannot be known at compilation time
17-
--> $DIR/method-resolution4.rs:14:9
18-
|
19-
LL | foo(false).next().unwrap();
20-
| ^^^^^^^^^^ doesn't have a size known at compile-time
21-
|
22-
= help: the trait `Sized` is not implemented for `impl Iterator<Item = ()>`
23-
= note: the return type of a function must have a statically known size
24-
25-
error: aborting due to 3 previous errors
7+
error: aborting due to 1 previous error
268

27-
Some errors have detailed explanations: E0277, E0282.
28-
For more information about an error, try `rustc --explain E0277`.
9+
For more information about this error, try `rustc --explain E0282`.

tests/ui/impl-trait/method-resolution4.rs

-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@
99
//@[current] check-pass
1010

1111
fn foo(b: bool) -> impl Iterator<Item = ()> {
12-
//[next]~^ ERROR the size for values of type `impl Iterator<Item = ()>` cannot be known at compilation time
1312
if b {
1413
foo(false).next().unwrap();
1514
//[next]~^ type annotations needed
16-
//[next]~| ERROR the size for values of type `impl Iterator<Item = ()>` cannot be known at compilation time
1715
}
1816
std::iter::empty()
1917
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
error[E0282]: type annotations needed
2-
--> $DIR/recursive-coroutine-boxed.rs:16:23
2+
--> $DIR/recursive-coroutine-boxed.rs:14:23
33
|
44
LL | let mut gen = Box::pin(foo());
55
| ^^^^^^^^ cannot infer type of the type parameter `T` declared on the struct `Box`
6-
...
6+
LL |
77
LL | let mut r = gen.as_mut().resume(());
88
| ------ type must be known at this point
99
|
@@ -12,25 +12,6 @@ help: consider specifying the generic argument
1212
LL | let mut gen = Box::<T>::pin(foo());
1313
| +++++
1414

15-
error[E0277]: the size for values of type `impl Coroutine<Yield = (), Return = ()>` cannot be known at compilation time
16-
--> $DIR/recursive-coroutine-boxed.rs:9:13
17-
|
18-
LL | fn foo() -> impl Coroutine<Yield = (), Return = ()> {
19-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
20-
|
21-
= help: the trait `Sized` is not implemented for `impl Coroutine<Yield = (), Return = ()>`
22-
= note: the return type of a function must have a statically known size
23-
24-
error[E0277]: the size for values of type `impl Coroutine<Yield = (), Return = ()>` cannot be known at compilation time
25-
--> $DIR/recursive-coroutine-boxed.rs:16:32
26-
|
27-
LL | let mut gen = Box::pin(foo());
28-
| ^^^^^ doesn't have a size known at compile-time
29-
|
30-
= help: the trait `Sized` is not implemented for `impl Coroutine<Yield = (), Return = ()>`
31-
= note: the return type of a function must have a statically known size
32-
33-
error: aborting due to 3 previous errors
15+
error: aborting due to 1 previous error
3416

35-
Some errors have detailed explanations: E0277, E0282.
36-
For more information about an error, try `rustc --explain E0277`.
17+
For more information about this error, try `rustc --explain E0282`.

tests/ui/impl-trait/recursive-coroutine-boxed.rs

-3
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,12 @@
77
use std::ops::{Coroutine, CoroutineState};
88

99
fn foo() -> impl Coroutine<Yield = (), Return = ()> {
10-
//[next]~^ ERROR the size for values of type `impl Coroutine<Yield = (), Return = ()>` cannot be known at compilation time
11-
1210
// FIXME(-Znext-solver): this fails with a mismatched types as the
1311
// hidden type of the opaque ends up as {type error}. We should not
1412
// emit errors for such goals.
1513
#[coroutine] || {
1614
let mut gen = Box::pin(foo());
1715
//[next]~^ ERROR type annotations needed
18-
//[next]~| ERROR the size for values of type `impl Coroutine<Yield = (), Return = ()>` cannot be known at compilation time
1916
let mut r = gen.as_mut().resume(());
2017
while let CoroutineState::Yielded(v) = r {
2118
yield v;

tests/ui/traits/negative-bounds/opaque-type-unsatisfied-bound.rs

-3
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@ fn main() {
1515
fn weird0() -> impl Sized + !Sized {}
1616
//~^ ERROR the size for values of type `()` cannot be known at compilation time [E0277]
1717
//~| ERROR the size for values of type `()` cannot be known at compilation time [E0277]
18-
//~| ERROR the size for values of type `impl !Sized + Sized` cannot be known at compilation time [E0277]
1918
//~| ERROR the size for values of type `()` cannot be known at compilation time [E0277]
2019
fn weird1() -> impl !Sized + Sized {}
2120
//~^ ERROR the size for values of type `()` cannot be known at compilation time [E0277]
2221
//~| ERROR the size for values of type `()` cannot be known at compilation time [E0277]
23-
//~| ERROR the size for values of type `impl !Sized + Sized` cannot be known at compilation time [E0277]
2422
//~| ERROR the size for values of type `()` cannot be known at compilation time [E0277]
2523
fn weird2() -> impl !Sized {}
2624
//~^ ERROR the size for values of type `()` cannot be known at compilation time [E0277]
2725
//~| ERROR the size for values of type `()` cannot be known at compilation time [E0277]
28-
//~| ERROR the size for values of type `impl !Sized` cannot be known at compilation time [E0277]
2926
//~| ERROR the size for values of type `()` cannot be known at compilation time [E0277]

tests/ui/traits/negative-bounds/opaque-type-unsatisfied-bound.stderr

+7-34
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@ LL | fn weird0() -> impl Sized + !Sized {}
1414
|
1515
= help: the trait bound `(): !Sized` is not satisfied
1616

17-
error[E0277]: the size for values of type `impl !Sized + Sized` cannot be known at compilation time
18-
--> $DIR/opaque-type-unsatisfied-bound.rs:15:16
19-
|
20-
LL | fn weird0() -> impl Sized + !Sized {}
21-
| ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
22-
|
23-
= help: the trait `Sized` is not implemented for `impl !Sized + Sized`
24-
= note: the return type of a function must have a statically known size
25-
2617
error[E0277]: the size for values of type `()` cannot be known at compilation time
2718
--> $DIR/opaque-type-unsatisfied-bound.rs:15:1
2819
|
@@ -32,65 +23,47 @@ LL | fn weird0() -> impl Sized + !Sized {}
3223
= help: the trait bound `(): !Sized` is not satisfied
3324

3425
error[E0277]: the size for values of type `()` cannot be known at compilation time
35-
--> $DIR/opaque-type-unsatisfied-bound.rs:20:16
26+
--> $DIR/opaque-type-unsatisfied-bound.rs:19:16
3627
|
3728
LL | fn weird1() -> impl !Sized + Sized {}
3829
| ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
3930
|
4031
= help: the trait bound `(): !Sized` is not satisfied
4132

4233
error[E0277]: the size for values of type `()` cannot be known at compilation time
43-
--> $DIR/opaque-type-unsatisfied-bound.rs:20:36
34+
--> $DIR/opaque-type-unsatisfied-bound.rs:19:36
4435
|
4536
LL | fn weird1() -> impl !Sized + Sized {}
4637
| ^^ doesn't have a size known at compile-time
4738
|
4839
= help: the trait bound `(): !Sized` is not satisfied
4940

50-
error[E0277]: the size for values of type `impl !Sized + Sized` cannot be known at compilation time
51-
--> $DIR/opaque-type-unsatisfied-bound.rs:20:16
52-
|
53-
LL | fn weird1() -> impl !Sized + Sized {}
54-
| ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
55-
|
56-
= help: the trait `Sized` is not implemented for `impl !Sized + Sized`
57-
= note: the return type of a function must have a statically known size
58-
5941
error[E0277]: the size for values of type `()` cannot be known at compilation time
60-
--> $DIR/opaque-type-unsatisfied-bound.rs:20:1
42+
--> $DIR/opaque-type-unsatisfied-bound.rs:19:1
6143
|
6244
LL | fn weird1() -> impl !Sized + Sized {}
6345
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
6446
|
6547
= help: the trait bound `(): !Sized` is not satisfied
6648

6749
error[E0277]: the size for values of type `()` cannot be known at compilation time
68-
--> $DIR/opaque-type-unsatisfied-bound.rs:25:16
50+
--> $DIR/opaque-type-unsatisfied-bound.rs:23:16
6951
|
7052
LL | fn weird2() -> impl !Sized {}
7153
| ^^^^^^^^^^^ doesn't have a size known at compile-time
7254
|
7355
= help: the trait bound `(): !Sized` is not satisfied
7456

7557
error[E0277]: the size for values of type `()` cannot be known at compilation time
76-
--> $DIR/opaque-type-unsatisfied-bound.rs:25:28
58+
--> $DIR/opaque-type-unsatisfied-bound.rs:23:28
7759
|
7860
LL | fn weird2() -> impl !Sized {}
7961
| ^^ doesn't have a size known at compile-time
8062
|
8163
= help: the trait bound `(): !Sized` is not satisfied
8264

83-
error[E0277]: the size for values of type `impl !Sized` cannot be known at compilation time
84-
--> $DIR/opaque-type-unsatisfied-bound.rs:25:16
85-
|
86-
LL | fn weird2() -> impl !Sized {}
87-
| ^^^^^^^^^^^ doesn't have a size known at compile-time
88-
|
89-
= help: the trait `Sized` is not implemented for `impl !Sized`
90-
= note: the return type of a function must have a statically known size
91-
9265
error[E0277]: the size for values of type `()` cannot be known at compilation time
93-
--> $DIR/opaque-type-unsatisfied-bound.rs:25:1
66+
--> $DIR/opaque-type-unsatisfied-bound.rs:23:1
9467
|
9568
LL | fn weird2() -> impl !Sized {}
9669
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
@@ -111,6 +84,6 @@ note: required by a bound in `consume`
11184
LL | fn consume(_: impl Trait) {}
11285
| ^^^^^ required by this bound in `consume`
11386

114-
error: aborting due to 13 previous errors
87+
error: aborting due to 10 previous errors
11588

11689
For more information about this error, try `rustc --explain E0277`.

tests/ui/traits/negative-bounds/opaque-type-unsatisfied-fn-bound.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
fn produce() -> impl !Fn<(u32,)> {}
66
//~^ ERROR expected a `Fn(u32)` closure, found `()`
77
//~| ERROR expected a `Fn(u32)` closure, found `()`
8-
//~| ERROR the size for values of type `impl !Fn<(u32,)>` cannot be known at compilation time
98
//~| ERROR expected a `Fn(u32)` closure, found `()`
109

1110
fn main() {}

tests/ui/traits/negative-bounds/opaque-type-unsatisfied-fn-bound.stderr

+1-10
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@ LL | fn produce() -> impl !Fn<(u32,)> {}
1414
|
1515
= help: the trait bound `(): !Fn(u32)` is not satisfied
1616

17-
error[E0277]: the size for values of type `impl !Fn<(u32,)>` cannot be known at compilation time
18-
--> $DIR/opaque-type-unsatisfied-fn-bound.rs:5:17
19-
|
20-
LL | fn produce() -> impl !Fn<(u32,)> {}
21-
| ^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
22-
|
23-
= help: the trait `Sized` is not implemented for `impl !Fn<(u32,)>`
24-
= note: the return type of a function must have a statically known size
25-
2617
error[E0277]: expected a `Fn(u32)` closure, found `()`
2718
--> $DIR/opaque-type-unsatisfied-fn-bound.rs:5:1
2819
|
@@ -31,6 +22,6 @@ LL | fn produce() -> impl !Fn<(u32,)> {}
3122
|
3223
= help: the trait bound `(): !Fn(u32)` is not satisfied
3324

34-
error: aborting due to 4 previous errors
25+
error: aborting due to 3 previous errors
3526

3627
For more information about this error, try `rustc --explain E0277`.

tests/ui/traits/next-solver/dyn-incompatibility.rs

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ pub fn copy_any<T>(t: &T) -> T {
1313
//~^ ERROR the trait bound `T: Copy` is not satisfied in `dyn Setup<From = T>`
1414
//~| ERROR mismatched types
1515
//~| ERROR the trait bound `T: Copy` is not satisfied
16-
//~| ERROR the size for values of type `<dyn Setup<From = T> as Setup>::From` cannot be known at compilation time
1716

1817
// FIXME(-Znext-solver): These error messages are horrible and some of them
1918
// are even simple fallout from previous error.

tests/ui/traits/next-solver/dyn-incompatibility.stderr

+1-14
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,7 @@ help: consider restricting type parameter `T`
4343
LL | pub fn copy_any<T: std::marker::Copy>(t: &T) -> T {
4444
| +++++++++++++++++++
4545

46-
error[E0277]: the size for values of type `<dyn Setup<From = T> as Setup>::From` cannot be known at compilation time
47-
--> $DIR/dyn-incompatibility.rs:12:5
48-
|
49-
LL | copy::<dyn Setup<From=T>>(t)
50-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
51-
|
52-
= help: the trait `Sized` is not implemented for `<dyn Setup<From = T> as Setup>::From`
53-
= note: the return type of a function must have a statically known size
54-
help: consider further restricting the associated type
55-
|
56-
LL | pub fn copy_any<T>(t: &T) -> T where <dyn Setup<From = T> as Setup>::From: Sized {
57-
| +++++++++++++++++++++++++++++++++++++++++++++++++
58-
59-
error: aborting due to 4 previous errors
46+
error: aborting due to 3 previous errors
6047

6148
Some errors have detailed explanations: E0277, E0308.
6249
For more information about an error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)