Skip to content

Commit 4a17552

Browse files
Rollup merge of rust-lang#112981 - spastorino:new-rpitit-22, r=compiler-errors
Fix return type notation errors with -Zlower-impl-trait-in-trait-to-assoc-ty This just adjust the way we check for RPITITs and uses the new helper method to do the "old" and "new" check at once. r? `@compiler-errors`
2 parents 3148bcf + d77e55b commit 4a17552

27 files changed

+287
-25
lines changed

compiler/rustc_hir_analysis/src/astconv/bounds.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
412412
// an RPITIT (return-position impl trait in trait) or AFIT (async fn in trait).
413413
let output = tcx.fn_sig(assoc_item.def_id).skip_binder().output();
414414
let output = if let ty::Alias(ty::Projection, alias_ty) = *output.skip_binder().kind()
415-
&& tcx.def_kind(alias_ty.def_id) == DefKind::ImplTraitPlaceholder
415+
&& tcx.is_impl_trait_in_trait(alias_ty.def_id)
416416
{
417417
alias_ty
418418
} else {

tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.stderr renamed to tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.current.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: return type notation uses `()` instead of `(..)` for elided arguments
2-
--> $DIR/bad-inputs-and-output.rs:18:24
2+
--> $DIR/bad-inputs-and-output.rs:20:24
33
|
44
LL | fn baz<T: Trait<method(..): Send>>() {}
55
| ^^ help: remove the `..`
66

77
error[E0658]: associated type bounds are unstable
8-
--> $DIR/bad-inputs-and-output.rs:10:17
8+
--> $DIR/bad-inputs-and-output.rs:12:17
99
|
1010
LL | fn foo<T: Trait<method(i32): Send>>() {}
1111
| ^^^^^^^^^^^^^^^^^
@@ -14,7 +14,7 @@ LL | fn foo<T: Trait<method(i32): Send>>() {}
1414
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
1515

1616
error[E0658]: associated type bounds are unstable
17-
--> $DIR/bad-inputs-and-output.rs:14:17
17+
--> $DIR/bad-inputs-and-output.rs:16:17
1818
|
1919
LL | fn bar<T: Trait<method() -> (): Send>>() {}
2020
| ^^^^^^^^^^^^^^^^^^^^
@@ -23,7 +23,7 @@ LL | fn bar<T: Trait<method() -> (): Send>>() {}
2323
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
2424

2525
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
26-
--> $DIR/bad-inputs-and-output.rs:3:12
26+
--> $DIR/bad-inputs-and-output.rs:5:12
2727
|
2828
LL | #![feature(return_type_notation, async_fn_in_trait)]
2929
| ^^^^^^^^^^^^^^^^^^^^
@@ -32,13 +32,13 @@ LL | #![feature(return_type_notation, async_fn_in_trait)]
3232
= note: `#[warn(incomplete_features)]` on by default
3333

3434
error: argument types not allowed with return type notation
35-
--> $DIR/bad-inputs-and-output.rs:10:23
35+
--> $DIR/bad-inputs-and-output.rs:12:23
3636
|
3737
LL | fn foo<T: Trait<method(i32): Send>>() {}
3838
| ^^^^^ help: remove the input types: `()`
3939

4040
error: return type not allowed with return type notation
41-
--> $DIR/bad-inputs-and-output.rs:14:25
41+
--> $DIR/bad-inputs-and-output.rs:16:25
4242
|
4343
LL | fn bar<T: Trait<method() -> (): Send>>() {}
4444
| ^^^^^^ help: remove the return type
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
error: return type notation uses `()` instead of `(..)` for elided arguments
2+
--> $DIR/bad-inputs-and-output.rs:20:24
3+
|
4+
LL | fn baz<T: Trait<method(..): Send>>() {}
5+
| ^^ help: remove the `..`
6+
7+
error[E0658]: associated type bounds are unstable
8+
--> $DIR/bad-inputs-and-output.rs:12:17
9+
|
10+
LL | fn foo<T: Trait<method(i32): Send>>() {}
11+
| ^^^^^^^^^^^^^^^^^
12+
|
13+
= note: see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more information
14+
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
15+
16+
error[E0658]: associated type bounds are unstable
17+
--> $DIR/bad-inputs-and-output.rs:16:17
18+
|
19+
LL | fn bar<T: Trait<method() -> (): Send>>() {}
20+
| ^^^^^^^^^^^^^^^^^^^^
21+
|
22+
= note: see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more information
23+
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
24+
25+
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
26+
--> $DIR/bad-inputs-and-output.rs:5:12
27+
|
28+
LL | #![feature(return_type_notation, async_fn_in_trait)]
29+
| ^^^^^^^^^^^^^^^^^^^^
30+
|
31+
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
32+
= note: `#[warn(incomplete_features)]` on by default
33+
34+
error: argument types not allowed with return type notation
35+
--> $DIR/bad-inputs-and-output.rs:12:23
36+
|
37+
LL | fn foo<T: Trait<method(i32): Send>>() {}
38+
| ^^^^^ help: remove the input types: `()`
39+
40+
error: return type not allowed with return type notation
41+
--> $DIR/bad-inputs-and-output.rs:16:25
42+
|
43+
LL | fn bar<T: Trait<method() -> (): Send>>() {}
44+
| ^^^^^^ help: remove the return type
45+
46+
error: aborting due to 5 previous errors; 1 warning emitted
47+
48+
For more information about this error, try `rustc --explain E0658`.

tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// edition: 2021
2+
// [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
3+
// revisions: current next
24

35
#![feature(return_type_notation, async_fn_in_trait)]
46
//~^ WARN the feature `return_type_notation` is incomplete
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/basic.rs:8:12
3+
|
4+
LL | #![feature(return_type_notation, async_fn_in_trait)]
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: 1 warning emitted
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/basic.rs:8:12
3+
|
4+
LL | #![feature(return_type_notation, async_fn_in_trait)]
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
error: future cannot be sent between threads safely
11+
--> $DIR/basic.rs:26:13
12+
|
13+
LL | is_send(foo::<T>());
14+
| ^^^^^^^^^^ future returned by `foo` is not `Send`
15+
|
16+
= help: within `impl Future<Output = Result<(), ()>>`, the trait `Send` is not implemented for `impl Future<Output = Result<(), ()>>`
17+
note: future is not `Send` as it awaits another future which is not `Send`
18+
--> $DIR/basic.rs:16:5
19+
|
20+
LL | T::method().await?;
21+
| ^^^^^^^^^^^ await occurs here on type `impl Future<Output = Result<(), ()>>`, which is not `Send`
22+
note: required by a bound in `is_send`
23+
--> $DIR/basic.rs:20:20
24+
|
25+
LL | fn is_send(_: impl Send) {}
26+
| ^^^^ required by this bound in `is_send`
27+
28+
error: aborting due to previous error; 1 warning emitted
29+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/basic.rs:8:12
3+
|
4+
LL | #![feature(return_type_notation, async_fn_in_trait)]
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: 1 warning emitted
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/basic.rs:8:12
3+
|
4+
LL | #![feature(return_type_notation, async_fn_in_trait)]
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
error: future cannot be sent between threads safely
11+
--> $DIR/basic.rs:26:13
12+
|
13+
LL | is_send(foo::<T>());
14+
| ^^^^^^^^^^ future returned by `foo` is not `Send`
15+
|
16+
= help: within `impl Future<Output = Result<(), ()>>`, the trait `Send` is not implemented for `impl Future<Output = Result<(), ()>>`
17+
note: future is not `Send` as it awaits another future which is not `Send`
18+
--> $DIR/basic.rs:16:5
19+
|
20+
LL | T::method().await?;
21+
| ^^^^^^^^^^^ await occurs here on type `impl Future<Output = Result<(), ()>>`, which is not `Send`
22+
note: required by a bound in `is_send`
23+
--> $DIR/basic.rs:20:20
24+
|
25+
LL | fn is_send(_: impl Send) {}
26+
| ^^^^ required by this bound in `is_send`
27+
28+
error: aborting due to previous error; 1 warning emitted
29+

tests/ui/associated-type-bounds/return-type-notation/basic.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
// revisions: with without
1+
// revisions: current_with current_without next_with next_without
2+
// [next_with] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
3+
// [next_without] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
24
// edition: 2021
3-
//[with] check-pass
5+
// [current_with] check-pass
6+
// [next_with] check-pass
47

58
#![feature(return_type_notation, async_fn_in_trait)]
69
//~^ WARN the feature `return_type_notation` is incomplete
@@ -17,11 +20,12 @@ async fn foo<T: Foo>() -> Result<(), ()> {
1720
fn is_send(_: impl Send) {}
1821

1922
fn test<
20-
#[cfg(with)] T: Foo<method(): Send>,
21-
#[cfg(without)] T: Foo,
23+
#[cfg(any(current_with, next_with))] T: Foo<method(): Send>,
24+
#[cfg(any(current_without, next_without))] T: Foo,
2225
>() {
2326
is_send(foo::<T>());
24-
//[without]~^ ERROR future cannot be sent between threads safely
27+
//[current_without]~^ ERROR future cannot be sent between threads safely
28+
//[next_without]~^^ ERROR future cannot be sent between threads safely
2529
}
2630

2731
fn main() {}

tests/ui/associated-type-bounds/return-type-notation/equality.stderr renamed to tests/ui/associated-type-bounds/return-type-notation/equality.current.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
2-
--> $DIR/equality.rs:3:12
2+
--> $DIR/equality.rs:5:12
33
|
44
LL | #![feature(return_type_notation, async_fn_in_trait)]
55
| ^^^^^^^^^^^^^^^^^^^^
@@ -8,7 +8,7 @@ LL | #![feature(return_type_notation, async_fn_in_trait)]
88
= note: `#[warn(incomplete_features)]` on by default
99

1010
error: return type notation is not allowed to use type equality
11-
--> $DIR/equality.rs:12:18
11+
--> $DIR/equality.rs:14:18
1212
|
1313
LL | fn test<T: Trait<method() = Box<dyn Future<Output = ()>>>>() {}
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/equality.rs:5:12
3+
|
4+
LL | #![feature(return_type_notation, async_fn_in_trait)]
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
error: return type notation is not allowed to use type equality
11+
--> $DIR/equality.rs:14:18
12+
|
13+
LL | fn test<T: Trait<method() = Box<dyn Future<Output = ()>>>>() {}
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15+
16+
error: aborting due to previous error; 1 warning emitted
17+

tests/ui/associated-type-bounds/return-type-notation/equality.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// edition: 2021
2+
// [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
3+
// revisions: current next
24

35
#![feature(return_type_notation, async_fn_in_trait)]
46
//~^ WARN the feature `return_type_notation` is incomplete
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
2-
--> $DIR/issue-110963-early.rs:4:12
2+
--> $DIR/issue-110963-early.rs:6:12
33
|
44
LL | #![feature(return_type_notation)]
55
| ^^^^^^^^^^^^^^^^^^^^
@@ -8,7 +8,7 @@ LL | #![feature(return_type_notation)]
88
= note: `#[warn(incomplete_features)]` on by default
99

1010
error: higher-ranked lifetime error
11-
--> $DIR/issue-110963-early.rs:15:5
11+
--> $DIR/issue-110963-early.rs:17:5
1212
|
1313
LL | / spawn(async move {
1414
LL | | let mut hc = hc;
@@ -18,10 +18,10 @@ LL | | }
1818
LL | | });
1919
| |______^
2020
|
21-
= note: could not prove `[async block@$DIR/issue-110963-early.rs:15:11: 20:6]: Send`
21+
= note: could not prove `[async block@$DIR/issue-110963-early.rs:17:11: 22:6]: Send`
2222

2323
error: higher-ranked lifetime error
24-
--> $DIR/issue-110963-early.rs:15:5
24+
--> $DIR/issue-110963-early.rs:17:5
2525
|
2626
LL | / spawn(async move {
2727
LL | | let mut hc = hc;
@@ -31,7 +31,7 @@ LL | | }
3131
LL | | });
3232
| |______^
3333
|
34-
= note: could not prove `[async block@$DIR/issue-110963-early.rs:15:11: 20:6]: Send`
34+
= note: could not prove `[async block@$DIR/issue-110963-early.rs:17:11: 22:6]: Send`
3535

3636
error: aborting due to 2 previous errors; 1 warning emitted
3737

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/issue-110963-early.rs:6:12
3+
|
4+
LL | #![feature(return_type_notation)]
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
error: higher-ranked lifetime error
11+
--> $DIR/issue-110963-early.rs:17:5
12+
|
13+
LL | / spawn(async move {
14+
LL | | let mut hc = hc;
15+
LL | | if !hc.check().await {
16+
LL | | log_health_check_failure().await;
17+
LL | | }
18+
LL | | });
19+
| |______^
20+
|
21+
= note: could not prove `[async block@$DIR/issue-110963-early.rs:17:11: 22:6]: Send`
22+
23+
error: higher-ranked lifetime error
24+
--> $DIR/issue-110963-early.rs:17:5
25+
|
26+
LL | / spawn(async move {
27+
LL | | let mut hc = hc;
28+
LL | | if !hc.check().await {
29+
LL | | log_health_check_failure().await;
30+
LL | | }
31+
LL | | });
32+
| |______^
33+
|
34+
= note: could not prove `[async block@$DIR/issue-110963-early.rs:17:11: 22:6]: Send`
35+
36+
error: aborting due to 2 previous errors; 1 warning emitted
37+

tests/ui/async-await/return-type-notation/issue-110963-early.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// edition: 2021
22
// known-bug: #110963
3+
// [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
4+
// revisions: current next
35

46
#![feature(return_type_notation)]
57
#![feature(async_fn_in_trait)]

tests/ui/async-await/return-type-notation/issue-110963-late.stderr renamed to tests/ui/async-await/return-type-notation/issue-110963-late.current.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
2-
--> $DIR/issue-110963-late.rs:4:12
2+
--> $DIR/issue-110963-late.rs:6:12
33
|
44
LL | #![feature(return_type_notation)]
55
| ^^^^^^^^^^^^^^^^^^^^
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/issue-110963-late.rs:6:12
3+
|
4+
LL | #![feature(return_type_notation)]
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: 1 warning emitted
11+

tests/ui/async-await/return-type-notation/issue-110963-late.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// edition: 2021
22
// check-pass
3+
// [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
4+
// revisions: current next
35

46
#![feature(return_type_notation)]
57
//~^ WARN the feature `return_type_notation` is incomplete

tests/ui/async-await/return-type-notation/super-method-bound.stderr renamed to tests/ui/async-await/return-type-notation/super-method-bound.current.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
2-
--> $DIR/super-method-bound.rs:4:31
2+
--> $DIR/super-method-bound.rs:6:31
33
|
44
LL | #![feature(async_fn_in_trait, return_type_notation)]
55
| ^^^^^^^^^^^^^^^^^^^^
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/super-method-bound.rs:6:31
3+
|
4+
LL | #![feature(async_fn_in_trait, return_type_notation)]
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: 1 warning emitted
11+

0 commit comments

Comments
 (0)