Add an explanatory note when suggesting to use impl Trait instead of a type parameter#104755
Add an explanatory note when suggesting to use impl Trait instead of a type parameter#104755kvverti wants to merge 3 commits intorust-lang:masterfrom
impl Trait instead of a type parameter#104755Conversation
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @davidtwco (or someone else) soon. Please see the contribution instructions for more information. |
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
You need to bless the tests locally ( |
| format!("impl {}", all_bounds_str), | ||
| Applicability::MaybeIncorrect, | ||
| ); | ||
| err.note("the caller chooses the value of a type parameter"); |
There was a problem hiding this comment.
Maybe something like..
the type of
Tis chosen by the caller
..would be clearer?
I'm not keen on describing type parameters as having a "value", I think that could lead to confusion.
|
Ping from triage: I'm closing this due to inactivity, Please reopen when you are ready to continue with this. @rustbot label: +S-inactive |
…Trait Revives rust-lang#112088 and rust-lang#104755. Co-authored-by: sladynnunes <snunes@usc.edu> Co-authored-by: Thalia Nero <chrisvn00@gmail.com>
…Trait Revives rust-lang#112088 and rust-lang#104755. Co-authored-by: sladynnunes <snunes@usc.edu> Co-authored-by: Thalia Nero <chrisvn00@gmail.com>
…Trait Revives rust-lang#112088 and rust-lang#104755. Co-authored-by: sladynnunes <snunes@usc.edu> Co-authored-by: Thalia Nero <chrisvn00@gmail.com>
…Trait Revives rust-lang#112088 and rust-lang#104755. Co-authored-by: sladynnunes <snunes@usc.edu> Co-authored-by: Thalia Nero <chrisvn00@gmail.com>
Note that the caller chooses a type for type param
```
error[E0308]: mismatched types
--> $DIR/return-impl-trait.rs:23:5
|
LL | fn other_bounds<T>() -> T
| - -
| | |
| | expected `T` because of return type
| | help: consider using an impl return type: `impl Trait`
| expected this type parameter
...
LL | ()
| ^^ expected type parameter `T`, found `()`
|
= note: expected type parameter `T`
found unit type `()`
= note: the caller chooses the type of T which can be different from ()
```
Tried to see if "expected this type parameter" can be replaced, but that goes all the way to `rustc_infer` so seems not worth the effort and can affect other diagnostics.
Revives rust-lang#112088 and rust-lang#104755.
Rollup merge of rust-lang#122195 - jieyouxu:impl-return-note, r=fmease Note that the caller chooses a type for type param ``` error[E0308]: mismatched types --> $DIR/return-impl-trait.rs:23:5 | LL | fn other_bounds<T>() -> T | - - | | | | | expected `T` because of return type | | help: consider using an impl return type: `impl Trait` | expected this type parameter ... LL | () | ^^ expected type parameter `T`, found `()` | = note: expected type parameter `T` found unit type `()` = note: the caller chooses the type of T which can be different from () ``` Tried to see if "expected this type parameter" can be replaced, but that goes all the way to `rustc_infer` so seems not worth the effort and can affect other diagnostics. Revives rust-lang#112088 and rust-lang#104755.
Note that the caller chooses a type for type param
```
error[E0308]: mismatched types
--> $DIR/return-impl-trait.rs:23:5
|
LL | fn other_bounds<T>() -> T
| - -
| | |
| | expected `T` because of return type
| | help: consider using an impl return type: `impl Trait`
| expected this type parameter
...
LL | ()
| ^^ expected type parameter `T`, found `()`
|
= note: expected type parameter `T`
found unit type `()`
= note: the caller chooses the type of T which can be different from ()
```
Tried to see if "expected this type parameter" can be replaced, but that goes all the way to `rustc_infer` so seems not worth the effort and can affect other diagnostics.
Revives rust-lang#112088 and rust-lang#104755.
Add a note to E308 explaining that generic type variables are chosen by the caller rather than the implementer, when suggesting to use
impl Traitinstead of a generic type variable.r? rust-lang/diagnostics