-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add an explanatory note when suggesting to use impl Trait
instead of a type parameter
#104755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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 ( |
@@ -878,6 +878,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something like..
the type of
T
is 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 <[email protected]> Co-authored-by: Thalia Nero <[email protected]>
…Trait Revives rust-lang#112088 and rust-lang#104755. Co-authored-by: sladynnunes <[email protected]> Co-authored-by: Thalia Nero <[email protected]>
…Trait Revives rust-lang#112088 and rust-lang#104755. Co-authored-by: sladynnunes <[email protected]> Co-authored-by: Thalia Nero <[email protected]>
…Trait Revives rust-lang#112088 and rust-lang#104755. Co-authored-by: sladynnunes <[email protected]> Co-authored-by: Thalia Nero <[email protected]>
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 Trait
instead of a generic type variable.r? rust-lang/diagnostics