Account for impl Trait
in "add bound" suggestion message
This commit is contained in:
parent
d860e5b088
commit
cb4db0a6c6
5 changed files with 10 additions and 4 deletions
|
@ -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}")
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
| +++++++++++++++++
|
||||
|
|
|
@ -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`
|
||||
|
|
|
@ -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) {
|
||||
| +++++++
|
||||
|
|
|
@ -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) {
|
||||
| +++++++++++++++++++
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue