1
Fork 0

Account for impl Trait in "add bound" suggestion message

This commit is contained in:
Esteban Küber 2024-11-28 22:20:44 +00:00
parent d860e5b088
commit cb4db0a6c6
5 changed files with 10 additions and 4 deletions

View file

@ -531,6 +531,12 @@ pub fn suggest_constraining_type_params<'a>(
SuggestChangingConstraintsMessage::RestrictBoundFurther => {
format!("consider further restricting this bound with {post}")
}
SuggestChangingConstraintsMessage::RestrictTypeFurther { ty }
| SuggestChangingConstraintsMessage::RestrictType { ty }
if ty.starts_with("impl ") =>
{
format!("consider restricting opaque type `{ty}` with {post}")
}
SuggestChangingConstraintsMessage::RestrictType { ty } => {
format!("consider restricting type parameter `{ty}` with {post}")
}

View file

@ -5,7 +5,7 @@ LL | println!("{:?}", t);
| ^ `impl Sized` cannot be formatted using `{:?}` because it doesn't implement `Debug`
|
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider further restricting type parameter `impl Sized` with trait `Debug`
help: consider restricting opaque type `impl Sized` with trait `Debug`
|
LL | fn test_impl(t: impl Sized + std::fmt::Debug) {
| +++++++++++++++++

View file

@ -6,7 +6,7 @@ trait DoesAThing {}
impl DoesAThing for ThingThatDoesAThing {}
fn clones_impl_ref_inline(thing: &impl DoesAThing) {
//~^ HELP consider further restricting type parameter `impl DoesAThing` with trait `Clone`
//~^ HELP consider restricting opaque type `impl DoesAThing` with trait `Clone`
drops_impl_owned(thing.clone()); //~ ERROR E0277
//~^ NOTE copies the reference
//~| NOTE the trait `DoesAThing` is not implemented for `&impl DoesAThing`

View file

@ -9,7 +9,7 @@ note: this `clone()` copies the reference, which does not do anything, because `
|
LL | drops_impl_owned(thing.clone());
| ^^^^^
help: consider further restricting type parameter `impl DoesAThing` with trait `Clone`
help: consider restricting opaque type `impl DoesAThing` with trait `Clone`
|
LL | fn clones_impl_ref_inline(thing: &impl DoesAThing + Clone) {
| +++++++

View file

@ -11,7 +11,7 @@ note: required by a bound in `is_send`
|
LL | fn is_send<T: Send>(val: T) {}
| ^^^^ required by this bound in `is_send`
help: consider further restricting type parameter `impl Sync` with trait `Send`
help: consider restricting opaque type `impl Sync` with trait `Send`
|
LL | fn use_impl_sync(val: impl Sync + std::marker::Send) {
| +++++++++++++++++++