Skip to content

Commit cb4db0a

Browse files
committed
Account for impl Trait in "add bound" suggestion message
1 parent d860e5b commit cb4db0a

File tree

5 files changed

+10
-4
lines changed

5 files changed

+10
-4
lines changed

compiler/rustc_middle/src/ty/diagnostics.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,12 @@ pub fn suggest_constraining_type_params<'a>(
531531
SuggestChangingConstraintsMessage::RestrictBoundFurther => {
532532
format!("consider further restricting this bound with {post}")
533533
}
534+
SuggestChangingConstraintsMessage::RestrictTypeFurther { ty }
535+
| SuggestChangingConstraintsMessage::RestrictType { ty }
536+
if ty.starts_with("impl ") =>
537+
{
538+
format!("consider restricting opaque type `{ty}` with {post}")
539+
}
534540
SuggestChangingConstraintsMessage::RestrictType { ty } => {
535541
format!("consider restricting type parameter `{ty}` with {post}")
536542
}

tests/ui/suggestions/bound-suggestions.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | println!("{:?}", t);
55
| ^ `impl Sized` cannot be formatted using `{:?}` because it doesn't implement `Debug`
66
|
77
= 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)
8-
help: consider further restricting type parameter `impl Sized` with trait `Debug`
8+
help: consider restricting opaque type `impl Sized` with trait `Debug`
99
|
1010
LL | fn test_impl(t: impl Sized + std::fmt::Debug) {
1111
| +++++++++++++++++

tests/ui/suggestions/clone-bounds-121524.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ trait DoesAThing {}
66
impl DoesAThing for ThingThatDoesAThing {}
77

88
fn clones_impl_ref_inline(thing: &impl DoesAThing) {
9-
//~^ HELP consider further restricting type parameter `impl DoesAThing` with trait `Clone`
9+
//~^ HELP consider restricting opaque type `impl DoesAThing` with trait `Clone`
1010
drops_impl_owned(thing.clone()); //~ ERROR E0277
1111
//~^ NOTE copies the reference
1212
//~| NOTE the trait `DoesAThing` is not implemented for `&impl DoesAThing`

tests/ui/suggestions/clone-bounds-121524.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ note: this `clone()` copies the reference, which does not do anything, because `
99
|
1010
LL | drops_impl_owned(thing.clone());
1111
| ^^^^^
12-
help: consider further restricting type parameter `impl DoesAThing` with trait `Clone`
12+
help: consider restricting opaque type `impl DoesAThing` with trait `Clone`
1313
|
1414
LL | fn clones_impl_ref_inline(thing: &impl DoesAThing + Clone) {
1515
| +++++++

tests/ui/suggestions/restrict-type-argument.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ note: required by a bound in `is_send`
1111
|
1212
LL | fn is_send<T: Send>(val: T) {}
1313
| ^^^^ required by this bound in `is_send`
14-
help: consider further restricting type parameter `impl Sync` with trait `Send`
14+
help: consider restricting opaque type `impl Sync` with trait `Send`
1515
|
1616
LL | fn use_impl_sync(val: impl Sync + std::marker::Send) {
1717
| +++++++++++++++++++

0 commit comments

Comments
 (0)