diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2025-02-28 21:39:25 +0000 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2025-03-03 18:23:49 +0000 |
| commit | a23566a57e4d53a35827becc2f65ce27951276c8 (patch) | |
| tree | 02d9eecc0a3c126b4ebba69587eb7287c5d57f18 /tests | |
| parent | 81d8edc2000aa38b08ad09fce22d90f1990b6459 (diff) | |
| download | rust-a23566a57e4d53a35827becc2f65ce27951276c8.tar.gz rust-a23566a57e4d53a35827becc2f65ce27951276c8.zip | |
Provide more context on resolve error caused from incorrect RTN
When encountering a resolve E0575 error for an associated method (when a type was expected), see if it could have been an intended return type notation bound.
```
error[E0575]: expected associated type, found associated function `Trait::method`
--> $DIR/bad-inputs-and-output.rs:31:36
|
LL | fn foo_qualified<T: Trait>() where <T as Trait>::method(i32): Send {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^ not a associated type
|
help: you might have meant to use the return type notation syntax
|
LL - fn foo_qualified<T: Trait>() where <T as Trait>::method(i32): Send {}
LL + fn foo_qualified<T: Trait>() where T::method(..): Send {}
|
```
Diffstat (limited to 'tests')
3 files changed, 70 insertions, 11 deletions
diff --git a/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.fixed b/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.fixed new file mode 100644 index 00000000000..7af986267aa --- /dev/null +++ b/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.fixed @@ -0,0 +1,40 @@ +//@ edition: 2021 +//@ run-rustfix +#![feature(return_type_notation)] +#![allow(dead_code)] + +trait Trait { + async fn method() {} +} + +fn foo<T: Trait<method(..): Send>>() {} +//~^ ERROR argument types not allowed with return type notation + +fn bar<T: Trait<method(..): Send>>() {} +//~^ ERROR return type not allowed with return type notation + +fn baz<T: Trait<method(..): Send>>() {} +//~^ ERROR return type notation arguments must be elided with `..` + +fn foo_path<T: Trait>() where T::method(..): Send {} +//~^ ERROR argument types not allowed with return type notation + +fn bar_path<T: Trait>() where T::method(..): Send {} +//~^ ERROR return type not allowed with return type notation + +fn bay_path<T: Trait>() where T::method(..): Send {} +//~^ ERROR return type not allowed with return type notation + +fn baz_path<T: Trait>() where T::method(..): Send {} +//~^ ERROR return type notation arguments must be elided with `..` + +fn foo_qualified<T: Trait>() where T::method(..): Send {} +//~^ ERROR expected associated type + +fn bar_qualified<T: Trait>() where T::method(..): Send {} +//~^ ERROR expected associated type + +fn baz_qualified<T: Trait>() where T::method(..): Send {} +//~^ ERROR expected associated type + +fn main() {} diff --git a/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.rs b/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.rs index 90fd2c2b4f3..983836e6433 100644 --- a/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.rs +++ b/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.rs @@ -1,6 +1,7 @@ //@ edition: 2021 - +//@ run-rustfix #![feature(return_type_notation)] +#![allow(dead_code)] trait Trait { async fn method() {} diff --git a/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.stderr b/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.stderr index bd02b7d6534..e1245a04c7f 100644 --- a/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.stderr +++ b/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.stderr @@ -1,5 +1,5 @@ error: return type not allowed with return type notation - --> $DIR/bad-inputs-and-output.rs:24:45 + --> $DIR/bad-inputs-and-output.rs:25:45 | LL | fn bay_path<T: Trait>() where T::method(..) -> (): Send {} | ^^^^^ @@ -11,25 +11,43 @@ LL + fn bay_path<T: Trait>() where T::method(..): Send {} | error[E0575]: expected associated type, found associated function `Trait::method` - --> $DIR/bad-inputs-and-output.rs:30:36 + --> $DIR/bad-inputs-and-output.rs:31:36 | LL | fn foo_qualified<T: Trait>() where <T as Trait>::method(i32): Send {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ not a associated type + | +help: you might have meant to use the return type notation syntax + | +LL - fn foo_qualified<T: Trait>() where <T as Trait>::method(i32): Send {} +LL + fn foo_qualified<T: Trait>() where T::method(..): Send {} + | error[E0575]: expected associated type, found associated function `Trait::method` - --> $DIR/bad-inputs-and-output.rs:33:36 + --> $DIR/bad-inputs-and-output.rs:34:36 | LL | fn bar_qualified<T: Trait>() where <T as Trait>::method() -> (): Send {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a associated type + | +help: you might have meant to use the return type notation syntax + | +LL - fn bar_qualified<T: Trait>() where <T as Trait>::method() -> (): Send {} +LL + fn bar_qualified<T: Trait>() where T::method(..): Send {} + | error[E0575]: expected associated type, found associated function `Trait::method` - --> $DIR/bad-inputs-and-output.rs:36:36 + --> $DIR/bad-inputs-and-output.rs:37:36 | LL | fn baz_qualified<T: Trait>() where <T as Trait>::method(): Send {} | ^^^^^^^^^^^^^^^^^^^^^^ not a associated type + | +help: you might have meant to use the return type notation syntax + | +LL - fn baz_qualified<T: Trait>() where <T as Trait>::method(): Send {} +LL + fn baz_qualified<T: Trait>() where T::method(..): Send {} + | error: argument types not allowed with return type notation - --> $DIR/bad-inputs-and-output.rs:9:23 + --> $DIR/bad-inputs-and-output.rs:10:23 | LL | fn foo<T: Trait<method(i32): Send>>() {} | ^^^^^ @@ -41,7 +59,7 @@ LL + fn foo<T: Trait<method(..): Send>>() {} | error: return type not allowed with return type notation - --> $DIR/bad-inputs-and-output.rs:12:25 + --> $DIR/bad-inputs-and-output.rs:13:25 | LL | fn bar<T: Trait<method() -> (): Send>>() {} | ^^^^^^ @@ -53,7 +71,7 @@ LL + fn bar<T: Trait<method(..): Send>>() {} | error: return type notation arguments must be elided with `..` - --> $DIR/bad-inputs-and-output.rs:15:23 + --> $DIR/bad-inputs-and-output.rs:16:23 | LL | fn baz<T: Trait<method(): Send>>() {} | ^^ @@ -64,7 +82,7 @@ LL | fn baz<T: Trait<method(..): Send>>() {} | ++ error: argument types not allowed with return type notation - --> $DIR/bad-inputs-and-output.rs:18:40 + --> $DIR/bad-inputs-and-output.rs:19:40 | LL | fn foo_path<T: Trait>() where T::method(i32): Send {} | ^^^^^ @@ -76,7 +94,7 @@ LL + fn foo_path<T: Trait>() where T::method(..): Send {} | error: return type not allowed with return type notation - --> $DIR/bad-inputs-and-output.rs:21:42 + --> $DIR/bad-inputs-and-output.rs:22:42 | LL | fn bar_path<T: Trait>() where T::method() -> (): Send {} | ^^^^^^ @@ -88,7 +106,7 @@ LL + fn bar_path<T: Trait>() where T::method(..): Send {} | error: return type notation arguments must be elided with `..` - --> $DIR/bad-inputs-and-output.rs:27:40 + --> $DIR/bad-inputs-and-output.rs:28:40 | LL | fn baz_path<T: Trait>() where T::method(): Send {} | ^^ |
