Change:
<!-- Thank you for filing a bug report! Please provide a short summary of the bug, along with any information you feel relevant to replicating the bug. If you cannot produce a minimal reproduction case (something that would work in isolation), please provide the steps or even link to a repository that causes the problematic output to occur. --Given the following code: <!-- Please provide a link to -- The current output is: <!-- The following is not always necessary. --Ideally the output should not reference the debug format of an internal type <!-- If the problem is not self-explanatory, please provide a rationale for the change. --<!-- If dramatically different output is caused by small changes, consider also adding them here. If you're using the stable version of the compiler, you should also check if the bug also exists in the beta or nightly versions. The output might also be different depending on the Edition. -- modify labels +F-specialization +A-specialization +requires-nightly

Discussion:
span: Span, ) { let tcx = infcx.tcx; <del> let impl1_predicates: Vec<_> = traits::elaborate_predicates( </del> <ins> let instantiated = tcx.predicates_of(impl1_def_id).instantiate(tcx, impl1_substs); let impl1_predicates: Vec<_> = traits::elaborate_predicates_with_span( </ins> tcx, <del> tcx.predicates_of(impl1_def_id).instantiate(tcx, impl1_substs).predicates.into_iter(), </del> <ins> std::iter::zip( instantiated.predicates, // Don't drop predicates (unsound!) because `spans` is too short instantiated.spans.into_iter().chain(std::iter::repeat(span)), ), </ins> ) <del> .map(|obligation| obligation.predicate) </del> <ins> .map(|obligation| (obligation.predicate, obligation.cause.span)) </ins> .collect(); let mut impl2_predicates = if impl2_node.is_from_trait() {

// which is sound because we forbid impls like the following // // impl<D: Debug> AlwaysApplicable for D { } <del> let always_applicable_traits = impl1_predicates.iter().copied().filter(|&predicate| { </del> <ins> let always_applicable_traits = impl1_predicates.iter().copied().filter(|&(predicate, _)| { </ins> matches!( trait_predicate_kind(tcx, predicate), Some(TraitSpecializationKind::AlwaysApplicable)

} } impl2_predicates.extend( <del> traits::elaborate_predicates(tcx, always_applicable_traits) </del> <ins> traits::elaborate_predicates_with_span(tcx, always_applicable_traits) </ins> .map(|obligation| obligation.predicate), ); <del> for predicate in impl1_predicates { </del> <ins> for (predicate, span) in impl1_predicates { </ins> if !impl2_predicates.contains(&predicate) { check_specialization_on(tcx, predicate, span) }

.emit(); } } <ins> ty::PredicateKind::Projection(ty::ProjectionPredicate { projection_ty, term }) => { tcx.sess .struct_span_err( span, &format!("cannot specialize on associated type `{projection_ty} == {term}`",), ) .emit(); } </ins> _ => { tcx.sess <del> .struct_span_err(span, &format!("cannot specialize on `{:?}`", predicate)) </del> <ins> .struct_span_err(span, &format!("cannot specialize on predicate `{}`", predicate)) </ins> .emit(); } }

<del> error: cannot specialize on `Binder(ProjectionPredicate(ProjectionTy { substs: [V], item_def_id: DefId(0:6 ~ repeated_projection_type[54ea]::Id::This) }, Ty((I,))), [])` --> $DIR/repeated_projection_type.rs:19:1 </del> <ins> error: cannot specialize on associated type `<V as Id>::This == (I,)` --> $DIR/repeated_projection_type.rs:19:15 </ins> | LL | impl<I, V: Id<This = (I,)>> X for V { <del> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ </del> <ins> |               ^^^^^^^^^^^ </ins> error: aborting due to previous error

error: cannot specialize on trait `HasMethod` <del> --> $DIR/spec-marker-supertraits.rs:22:1 </del> <ins> --> $DIR/spec-marker-supertraits.rs:22:9 </ins> | LL | impl<T: Marker> Spec for T { <del> | ^^^^^^^^^^^^^^^^^^^^^^^^^^ </del> <ins> |         ^^^^^^ </ins> error: aborting due to previous error

error: cannot specialize on trait `Default` <del> --> $DIR/specialization_super_trait.rs:13:1 </del> <ins> --> $DIR/specialization_super_trait.rs:13:9 </ins> | LL | impl<T: Default> SpecMarker for T { <del> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ </del> <ins> |         ^^^^^^^ </ins> error: aborting due to previous error

| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: cannot specialize on trait `Clone` <del> --> $DIR/specialization_trait.rs:21:1 </del> <ins> --> $DIR/specialization_trait.rs:21:9 </ins> | LL | impl<T: Clone> SpecMarker for [T] { <del> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ </del> <ins> |         ^^^^^ </ins> error: aborting due to 3 previous errors

error: cannot specialize on trait `SpecMarker` <del> --> $DIR/specialize_on_trait.rs:15:1 </del> <ins> --> $DIR/specialize_on_trait.rs:15:9 </ins> | LL | impl<T: SpecMarker> X for T { <del> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ </del> <ins> |         ^^^^^^^^^^ </ins> error: aborting due to previous error