Change:
Given the following code: The current output is: <!-- The following is not always necessary. --Ideally the output should look like: A similar error message with an unsized generic type argument does mention the implicit bound. Unfortunately, it also doesn't explain the implicit bound up front in the "required by this bound" text. (It mentions it when suggesting to relax the implicit bound, but I think it would be better to mention it up front as well.) Both error messages could benefit from changing the "required by this bound" text to "required by an implicit bound". <!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOTEND --
label +A-associated-items +A-traits +A-typesystem +D-papercut +D-terse
I'm working on a pull request for this issue. claim
Oh! Very sorry, if you spent too much time on this already, but I have done some work around this already in If you want, you can take over it and bring it to completion, there are some cases, like that still need to be addressed and I haven't yet figured out. Alternatively, if you can find a way to accomplish the same result without touching the and instead deal only with a new , that would be preferable to my approach.
I've pushed what I have so far to , sorry if it conflicts with stuff you've already done. If you'd like to take a look at it, that would be great. I'll take a look at what you have as well. There are some issues to be worked out with conflicting suggestions for associated types for vs the existing suggestion for adding an explicit to a trait's bounds, in test cases such as within a trait declaration.

Discussion:
// Check for foreign traits being reachable. self.tcx.visible_parent_map(()).get(&def_id).is_some() }; <ins> if Some(def_id) == self.tcx.lang_items().sized_trait() && let Some(hir::Node::TraitItem(hir::TraitItem { ident, kind: hir::TraitItemKind::Type(bounds, None), .. })) = tcx.hir().get_if_local(item_def_id) // Do not suggest relaxing if there is an explicit `Sized` obligation. && !bounds.iter() .filter_map(|bound| bound.trait_ref()) .any(|tr| tr.trait_def_id() == self.tcx.lang_items().sized_trait()) { let (span, separator) = if let [.., last] = bounds { (last.span().shrink_to_hi(), " +") } else { (ident.span.shrink_to_hi(), ":") }; err.span_suggestion_verbose( span, "consider relaxing the implicit `Sized` restriction", format!("{separator} ?Sized"), Applicability::MachineApplicable, ); } </ins> if let DefKind::Trait = tcx.def_kind(item_def_id) && !visible_item {

<ins> // run-rustfix trait TraitWithAType { type Item: ?Sized; } trait Trait {} struct A {} impl TraitWithAType for A { type Item = dyn Trait; //~ ERROR E0277 } fn main() {} </ins>

<ins> // run-rustfix trait TraitWithAType { type Item; } trait Trait {} struct A {} impl TraitWithAType for A { type Item = dyn Trait; //~ ERROR E0277 } fn main() {} </ins>

<ins> error[E0277]: the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time --> $DIR/assoc_type_bounds_implicit_sized.rs:8:17 | LL |     type Item = dyn Trait; |                 ^^^^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `(dyn Trait + 'static)` note: required by a bound in `TraitWithAType::Item` --> $DIR/assoc_type_bounds_implicit_sized.rs:3:5 | LL |     type Item; |     ^^^^^^^^^^ required by this bound in `TraitWithAType::Item` help: consider relaxing the implicit `Sized` restriction | LL |     type Item: ?Sized; |              ++++++++ error: aborting due to previous error For more information about this error, try `rustc --explain E0277`. </ins>

LL - fn bop<T: Bop + ?Sized>() { LL + fn bop<T: Bop>() { | <ins> help: consider relaxing the implicit `Sized` restriction | LL |     type Bar: Default + ?Sized |                       ++++++++ </ins> error: aborting due to 2 previous errors