Skip to content

Commit 109008a

Browse files
authored
Rollup merge of #96516 - oli-obk:impl_trait_inference_accidental_permitted, r=jackh726
Revert diagnostic duplication and accidental stabilization fixes #96460 this is an accidental stabilization that we should put into the beta. I believe it is low-risk, because it was literally what we had before #94081 The effect on tests is massive, but mostly deduplication of diagnostics and some minor span changes.
2 parents cd5dc49 + d22c439 commit 109008a

File tree

46 files changed

+119
-574
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+119
-574
lines changed

compiler/rustc_typeck/src/check/check.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ pub(super) fn check_fn<'a, 'tcx>(
102102
DUMMY_SP,
103103
param_env,
104104
));
105+
// HACK(oli-obk): we rewrite the declared return type, too, so that we don't end up inferring all
106+
// unconstrained RPIT to have `()` as their hidden type. This would happen because further down we
107+
// compare the ret_coercion with declared_ret_ty, and anything uninferred would be inferred to the
108+
// opaque type itself. That again would cause writeback to assume we have a recursive call site
109+
// and do the sadly stabilized fallback to `()`.
110+
let declared_ret_ty = ret_ty;
105111
fcx.ret_coercion = Some(RefCell::new(CoerceMany::new(ret_ty)));
106112
fcx.ret_type_span = Some(decl.output.span());
107113

src/test/ui/associated-types/impl-trait-return-missing-constraint.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ fn bar() -> impl Bar {
2424

2525
fn baz() -> impl Bar<Item = i32> {
2626
//~^ ERROR type mismatch resolving `<impl Bar as Foo>::Item == i32`
27-
//~| ERROR type mismatch resolving `<impl Bar as Foo>::Item == i32`
2827
bar()
2928
}
3029

src/test/ui/associated-types/impl-trait-return-missing-constraint.stderr

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,6 @@ help: consider constraining the associated type `<impl Bar as Foo>::Item` to `i3
1616
LL | fn bar() -> impl Bar<Item = i32> {
1717
| ++++++++++++
1818

19-
error[E0271]: type mismatch resolving `<impl Bar as Foo>::Item == i32`
20-
--> $DIR/impl-trait-return-missing-constraint.rs:25:34
21-
|
22-
LL | fn bar() -> impl Bar {
23-
| -------- the expected opaque type
24-
...
25-
LL | fn baz() -> impl Bar<Item = i32> {
26-
| __________________________________^
27-
LL | |
28-
LL | |
29-
LL | | bar()
30-
LL | | }
31-
| |_^ expected associated type, found `i32`
32-
|
33-
= note: expected associated type `<impl Bar as Foo>::Item`
34-
found type `i32`
35-
= help: consider constraining the associated type `<impl Bar as Foo>::Item` to `i32` or calling a method that returns `<impl Bar as Foo>::Item`
36-
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
37-
help: consider constraining the associated type `<impl Bar as Foo>::Item` to `i32`
38-
|
39-
LL | fn bar() -> impl Bar<Item = i32> {
40-
| ++++++++++++
41-
42-
error: aborting due to 2 previous errors
19+
error: aborting due to previous error
4320

4421
For more information about this error, try `rustc --explain E0271`.

src/test/ui/conservative_impl_trait.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
fn will_ice(something: &u32) -> impl Iterator<Item = &u32> {
44
//~^ ERROR `()` is not an iterator
5-
//~| ERROR `()` is not an iterator
65
}
76

87
fn main() {}

src/test/ui/conservative_impl_trait.stderr

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,6 @@ LL | fn will_ice(something: &u32) -> impl Iterator<Item = &u32> {
66
|
77
= help: the trait `Iterator` is not implemented for `()`
88

9-
error[E0277]: `()` is not an iterator
10-
--> $DIR/conservative_impl_trait.rs:3:60
11-
|
12-
LL | fn will_ice(something: &u32) -> impl Iterator<Item = &u32> {
13-
| ____________________________________________________________^
14-
LL | |
15-
LL | |
16-
LL | | }
17-
| |_^ `()` is not an iterator
18-
|
19-
= help: the trait `Iterator` is not implemented for `()`
20-
21-
error: aborting due to 2 previous errors
9+
error: aborting due to previous error
2210

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

src/test/ui/const-generics/defaults/rp_impl_trait_fail.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ impl<const N: u32> Trait for Uwu<N> {}
55

66
fn rawr() -> impl Trait {
77
//~^ error: the trait bound `Uwu<10_u32, 12_u32>: Trait` is not satisfied
8-
//~| error: the trait bound `Uwu<10_u32, 12_u32>: Trait` is not satisfied
98
Uwu::<10, 12>
109
}
1110

@@ -17,13 +16,11 @@ impl Traitor<1, 2> for u64 {}
1716

1817
fn uwu<const N: u8>() -> impl Traitor<N> {
1918
//~^ error: the trait bound `u32: Traitor<N, N>` is not satisfied
20-
//~| error: the trait bound `u32: Traitor<N, N>` is not satisfied
2119
1_u32
2220
}
2321

2422
fn owo() -> impl Traitor {
2523
//~^ error: the trait bound `u64: Traitor<1_u8, 1_u8>` is not satisfied
26-
//~| error: the trait bound `u64: Traitor<1_u8, 1_u8>` is not satisfied
2724
1_u64
2825
}
2926

src/test/ui/const-generics/defaults/rp_impl_trait_fail.stderr

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,8 @@ LL | fn rawr() -> impl Trait {
66
|
77
= help: the trait `Trait` is implemented for `Uwu<N>`
88

9-
error[E0277]: the trait bound `Uwu<10_u32, 12_u32>: Trait` is not satisfied
10-
--> $DIR/rp_impl_trait_fail.rs:6:25
11-
|
12-
LL | fn rawr() -> impl Trait {
13-
| _________________________^
14-
LL | |
15-
LL | |
16-
LL | | Uwu::<10, 12>
17-
LL | | }
18-
| |_^ the trait `Trait` is not implemented for `Uwu<10_u32, 12_u32>`
19-
|
20-
= help: the trait `Trait` is implemented for `Uwu<N>`
21-
229
error[E0277]: the trait bound `u32: Traitor<N, N>` is not satisfied
23-
--> $DIR/rp_impl_trait_fail.rs:18:26
10+
--> $DIR/rp_impl_trait_fail.rs:17:26
2411
|
2512
LL | fn uwu<const N: u8>() -> impl Traitor<N> {
2613
| ^^^^^^^^^^^^^^^ the trait `Traitor<N, N>` is not implemented for `u32`
@@ -29,23 +16,8 @@ LL | fn uwu<const N: u8>() -> impl Traitor<N> {
2916
<u32 as Traitor<N, 2_u8>>
3017
<u64 as Traitor<1_u8, 2_u8>>
3118

32-
error[E0277]: the trait bound `u32: Traitor<N, N>` is not satisfied
33-
--> $DIR/rp_impl_trait_fail.rs:18:42
34-
|
35-
LL | fn uwu<const N: u8>() -> impl Traitor<N> {
36-
| __________________________________________^
37-
LL | |
38-
LL | |
39-
LL | | 1_u32
40-
LL | | }
41-
| |_^ the trait `Traitor<N, N>` is not implemented for `u32`
42-
|
43-
= help: the following other types implement trait `Traitor<N, M>`:
44-
<u32 as Traitor<N, 2_u8>>
45-
<u64 as Traitor<1_u8, 2_u8>>
46-
4719
error[E0277]: the trait bound `u64: Traitor<1_u8, 1_u8>` is not satisfied
48-
--> $DIR/rp_impl_trait_fail.rs:24:13
20+
--> $DIR/rp_impl_trait_fail.rs:22:13
4921
|
5022
LL | fn owo() -> impl Traitor {
5123
| ^^^^^^^^^^^^ the trait `Traitor<1_u8, 1_u8>` is not implemented for `u64`
@@ -54,21 +26,6 @@ LL | fn owo() -> impl Traitor {
5426
<u32 as Traitor<N, 2_u8>>
5527
<u64 as Traitor<1_u8, 2_u8>>
5628

57-
error[E0277]: the trait bound `u64: Traitor<1_u8, 1_u8>` is not satisfied
58-
--> $DIR/rp_impl_trait_fail.rs:24:26
59-
|
60-
LL | fn owo() -> impl Traitor {
61-
| __________________________^
62-
LL | |
63-
LL | |
64-
LL | | 1_u64
65-
LL | | }
66-
| |_^ the trait `Traitor<1_u8, 1_u8>` is not implemented for `u64`
67-
|
68-
= help: the following other types implement trait `Traitor<N, M>`:
69-
<u32 as Traitor<N, 2_u8>>
70-
<u64 as Traitor<1_u8, 2_u8>>
71-
72-
error: aborting due to 6 previous errors
29+
error: aborting due to 3 previous errors
7330

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

src/test/ui/generator/issue-88653.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@ use std::ops::Generator;
77

88
fn foo(bar: bool) -> impl Generator<(bool,)> {
99
//~^ ERROR: type mismatch in generator arguments [E0631]
10-
//~| ERROR: type mismatch in generator arguments [E0631]
11-
//~| NOTE: expected signature of `fn((bool,)) -> _`
1210
//~| NOTE: expected signature of `fn((bool,)) -> _`
1311
//~| NOTE: in this expansion of desugaring of `impl Trait`
1412
|bar| {
1513
//~^ NOTE: found signature of `fn(bool) -> _`
16-
//~| NOTE: found signature of `fn(bool) -> _`
1714
if bar {
1815
yield bar;
1916
}

src/test/ui/generator/issue-88653.stderr

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,6 @@ LL | fn foo(bar: bool) -> impl Generator<(bool,)> {
77
LL | |bar| {
88
| ----- found signature of `fn(bool) -> _`
99

10-
error[E0631]: type mismatch in generator arguments
11-
--> $DIR/issue-88653.rs:8:46
12-
|
13-
LL | fn foo(bar: bool) -> impl Generator<(bool,)> {
14-
| ______________________________________________^
15-
LL | |
16-
LL | |
17-
LL | |
18-
... |
19-
LL | | |bar| {
20-
| | ----- found signature of `fn(bool) -> _`
21-
... |
22-
LL | | }
23-
LL | | }
24-
| |_^ expected signature of `fn((bool,)) -> _`
25-
26-
error: aborting due to 2 previous errors
10+
error: aborting due to previous error
2711

2812
For more information about this error, try `rustc --explain E0631`.

src/test/ui/generator/type-mismatch-signature-deduction.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::ops::Generator;
44

55
fn foo() -> impl Generator<Return = i32> {
66
//~^ ERROR type mismatch
7-
//~| ERROR type mismatch
87
|| {
98
if false {
109
return Ok(6);

0 commit comments

Comments
 (0)