Change:
Given the following code: The current output is: is wrong, specifying another isn't going to fix the problem. Writing just has a suggestion where`, which is good, but the concrete syntax would be nice. <!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOTEND --
We probably should modify E0191 to hint that an supertrait's associated type is shadowed. I think E0719 here is fine to keep as-is, imo.
I agree the message for E0719 is good as-is.
Is this issue fixed ? If not can I take this up, please. Also how exactly should E0191 be modified. Imo, I don't think E0191 should pop up in this case as E0719 conveys the message.
claim
claim
Ask for help How do I specify the association type of supertrait with the same name? In other words, is there an easy way to modify the code in the issue to make it pass compilation? Here's my clumsy way of creating a new trait.
Is this issue still open? If so I would like to take a crack at it.
If you can still reproduce it, then yes indeed. assign
Error: Parsing assign command in failed: ...'zyDutchman' ''... Please file an issue on GitHub at if there's a problem with this bot, or reach out on on Zulip.
I have now a hint about the shadowing: But I am not quite sure about what to do about the actual message. Do we want to suggest renaming to something else Or do we want to suggest the work-around by
If the trait is local, then we could suggest renaming it. It's not required to be super specific here--we could just note the conflict to make the user aware of it, for example.
I have updated the help message so that this case: gives this error message: The rename help message is emitted for both the super trait and the subtrait, if they are local. I think I am ready to make a merge request, or does somebody have something else to add?
I recommend you to just open a PR. Any further discussions can happen over there :)

Discussion:
use rustc_hir as hir; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_infer::traits::FulfillmentError; <del> use rustc_middle::ty::{self, suggest_constraining_type_param, Ty, TyCtxt}; </del> <ins> use rustc_middle::ty::{self, suggest_constraining_type_param, AssocItem, AssocKind, Ty, TyCtxt}; </ins> use rustc_session::parse::feature_err; use rustc_span::edit_distance::find_best_match_for_name; use rustc_span::symbol::{sym, Ident};

if associated_types.values().all(|v| v.is_empty()) { return; } let tcx = self.tcx(); // FIXME: Marked `mut` so that we can replace the spans further below with a more // appropriate one, but this should be handled earlier in the span assignment.

} } <ins> // We get all the associated items that _are_ set, // so that we can check if any of their names match one of the ones we are missing. // This would mean that they are shadowing the associated type we are missing, // and we can then use their span to indicate this to the user. let bound_names = trait_bounds .iter() .filter_map(|poly_trait_ref| { let path = poly_trait_ref.trait_ref.path.segments.last()?; let args = path.args?; Some(args.bindings.iter().filter_map(|binding| { let ident = binding.ident; let trait_def = path.res.def_id(); let assoc_item = tcx.associated_items(trait_def).find_by_name_and_kind( tcx, ident, AssocKind::Type, trait_def, ); Some((ident.name, assoc_item?)) })) }) .flatten() .collect::<FxHashMap<Symbol, &AssocItem>>(); </ins> let mut names = names .into_iter() .map(|(trait_, mut assocs)| {

*names.entry(item.name).or_insert(0) += 1; } let mut dupes = false; <ins> let mut shadows = false; </ins> for item in assoc_items { let prefix = if names[&item.name] > 1 { let trait_def_id = item.container_id(tcx); dupes = true; format!("{}::", tcx.def_path_str(trait_def_id)) <ins> } else if bound_names.get(&item.name).is_some_and(|x| x != &item) { let trait_def_id = item.container_id(tcx); shadows = true; format!("{}::", tcx.def_path_str(trait_def_id)) </ins> } else { String::new() }; <ins> let mut is_shadowed = false; if let Some(assoc_item) = bound_names.get(&item.name) && assoc_item != &item { is_shadowed = true; let rename_message = if assoc_item.def_id.is_local() { ", consider renaming it" } else { "" }; err.span_label( tcx.def_span(assoc_item.def_id), format!("`{}{}` shadowed here{}", prefix, item.name, rename_message), ); } let rename_message = if is_shadowed { ", consider renaming it" } else { "" }; </ins> if let Some(sp) = tcx.hir().span_if_local(item.def_id) { <del> err.span_label(sp, format!("`{}{}` defined here", prefix, item.name)); </del> <ins> err.span_label( sp, format!("`{}{}` defined here{}", prefix, item.name, rename_message), ); </ins> } } if potential_assoc_types.len() == assoc_items.len() {

// extra type arguments present. A suggesting to replace the generic args with // associated types is already emitted. already_has_generics_args_suggestion = true; <del> } else if let (Ok(snippet), false) = (tcx.sess.source_map().span_to_snippet(*span), dupes) </del> <ins> } else if let (Ok(snippet), false, false) = (tcx.sess.source_map().span_to_snippet(*span), dupes, shadows) </ins> { let types: Vec<_> = assoc_items.iter().map(|item| format!("{} = Type", item.name)).collect();

err.span_help(where_constraints, where_msg); } } err.emit(); } }

<ins> // Test that no help message is emitted that suggests renaming the // associated type from a non-local trait pub trait NewIter: Iterator { type Item; } impl<T> Clone for Box<dyn NewIter<Item = T>> { //~^ ERROR the value of the associated type `Item` in `Iterator` must be specified fn clone(&self) -> Self { unimplemented!(); } } pub fn main() {} </ins>

<ins> error[E0191]: the value of the associated type `Item` in `Iterator` must be specified --> $DIR/associated-type-shadowed-from-non-local-supertrait.rs:8:27 | LL |     type Item; |     --------- `Iterator::Item` shadowed here, consider renaming it ... LL | impl<T> Clone for Box<dyn NewIter<Item = T>> { |                           ^^^^^^^^^^^^^^^^^ associated type `Item` must be specified error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0191`. </ins>

<ins> // Test Setting the value of an associated type // that is shadowed from a supertrait pub trait Super { type X; } pub trait Sub: Super { type X; } impl<T> Clone for Box<dyn Sub<X = T>> { //~^ ERROR value of the associated type `X` in `Super` must be specified fn clone(&self) -> Self { unimplemented!(); } } pub fn main() {} </ins>

<ins> error[E0191]: the value of the associated type `X` in `Super` must be specified --> $DIR/associated-type-shadowed-from-supertrait.rs:12:27 | LL |     type X; |     ------ `Super::X` defined here, consider renaming it ... LL |     type X; |     ------ `Super::X` shadowed here, consider renaming it ... LL | impl<T> Clone for Box<dyn Sub<X = T>> { |                           ^^^^^^^^^^ associated type `X` must be specified error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0191`. </ins>