diff --git a/compiler/rustc_typeck/src/coherence/orphan.rs b/compiler/rustc_typeck/src/coherence/orphan.rs index 77a53744829..2fc425a6fc4 100644 --- a/compiler/rustc_typeck/src/coherence/orphan.rs +++ b/compiler/rustc_typeck/src/coherence/orphan.rs @@ -50,6 +50,7 @@ fn orphan_check_impl(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), ErrorGua tcx, sp, tr.path.span, + trait_ref.self_ty(), impl_.self_ty.span, &impl_.generics, err, @@ -201,18 +202,24 @@ fn emit_orphan_check_error<'tcx>( tcx: TyCtxt<'tcx>, sp: Span, trait_span: Span, + self_ty: Ty<'tcx>, self_ty_span: Span, generics: &hir::Generics<'tcx>, err: traits::OrphanCheckErr<'tcx>, ) -> Result { Err(match err { traits::OrphanCheckErr::NonLocalInputType(tys) => { + let msg = match self_ty.kind() { + ty::Adt(..) => "can be implemented for types defined outside of the crate", + ty::Param(_) => "can have blanket implementations defined in this trait", + _ if self_ty.is_primitive() => "can be implemented for primitive types", + _ => "can be implemented for arbitrary types", + }; let mut err = struct_span_err!( tcx.sess, sp, E0117, - "only traits defined in the current crate can be implemented for \ - arbitrary types" + "only traits defined in the current crate {msg}" ); err.span_label(sp, "impl doesn't use only types from inside the current crate"); for (ty, is_target_ty) in &tys { diff --git a/src/test/ui/coherence/coherence-cow.re_a.stderr b/src/test/ui/coherence/coherence-cow.re_a.stderr index 0cf2a406da4..fe4b5b41078 100644 --- a/src/test/ui/coherence/coherence-cow.re_a.stderr +++ b/src/test/ui/coherence/coherence-cow.re_a.stderr @@ -1,4 +1,4 @@ -error[E0117]: only traits defined in the current crate can be implemented for arbitrary types +error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate --> $DIR/coherence-cow.rs:18:1 | LL | impl Remote for Pair> { } diff --git a/src/test/ui/coherence/coherence-cow.re_b.stderr b/src/test/ui/coherence/coherence-cow.re_b.stderr index b523db4da23..da4ede3251e 100644 --- a/src/test/ui/coherence/coherence-cow.re_b.stderr +++ b/src/test/ui/coherence/coherence-cow.re_b.stderr @@ -1,4 +1,4 @@ -error[E0117]: only traits defined in the current crate can be implemented for arbitrary types +error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate --> $DIR/coherence-cow.rs:22:1 | LL | impl Remote for Pair,T> { } diff --git a/src/test/ui/coherence/coherence-cow.re_c.stderr b/src/test/ui/coherence/coherence-cow.re_c.stderr index bd635fc2e8c..d1a20c0ca10 100644 --- a/src/test/ui/coherence/coherence-cow.re_c.stderr +++ b/src/test/ui/coherence/coherence-cow.re_c.stderr @@ -1,4 +1,4 @@ -error[E0117]: only traits defined in the current crate can be implemented for arbitrary types +error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate --> $DIR/coherence-cow.rs:26:1 | LL | impl Remote for Pair,U> { } diff --git a/src/test/ui/coherence/coherence-impls-copy.stderr b/src/test/ui/coherence/coherence-impls-copy.stderr index a7d6968a296..b3ca354c633 100644 --- a/src/test/ui/coherence/coherence-impls-copy.stderr +++ b/src/test/ui/coherence/coherence-impls-copy.stderr @@ -1,4 +1,4 @@ -error[E0117]: only traits defined in the current crate can be implemented for arbitrary types +error[E0117]: only traits defined in the current crate can be implemented for primitive types --> $DIR/coherence-impls-copy.rs:5:1 | LL | impl Copy for i32 {} diff --git a/src/test/ui/coherence/coherence-orphan.stderr b/src/test/ui/coherence/coherence-orphan.stderr index 52d2cc88cbe..01f166a21f7 100644 --- a/src/test/ui/coherence/coherence-orphan.stderr +++ b/src/test/ui/coherence/coherence-orphan.stderr @@ -1,4 +1,4 @@ -error[E0117]: only traits defined in the current crate can be implemented for arbitrary types +error[E0117]: only traits defined in the current crate can be implemented for primitive types --> $DIR/coherence-orphan.rs:10:1 | LL | impl TheTrait for isize { } @@ -10,7 +10,7 @@ LL | impl TheTrait for isize { } | = note: define and implement a trait or new type instead -error[E0117]: only traits defined in the current crate can be implemented for arbitrary types +error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate --> $DIR/coherence-orphan.rs:17:1 | LL | impl !Send for Vec { } diff --git a/src/test/ui/coherence/coherence-overlapping-pairs.stderr b/src/test/ui/coherence/coherence-overlapping-pairs.stderr index c1a02681c13..15c92dfeb07 100644 --- a/src/test/ui/coherence/coherence-overlapping-pairs.stderr +++ b/src/test/ui/coherence/coherence-overlapping-pairs.stderr @@ -1,4 +1,4 @@ -error[E0117]: only traits defined in the current crate can be implemented for arbitrary types +error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate --> $DIR/coherence-overlapping-pairs.rs:8:1 | LL | impl Remote for lib::Pair { } diff --git a/src/test/ui/coherence/coherence-pair-covered-uncovered-1.stderr b/src/test/ui/coherence/coherence-pair-covered-uncovered-1.stderr index b18bf44dbdf..03d78712381 100644 --- a/src/test/ui/coherence/coherence-pair-covered-uncovered-1.stderr +++ b/src/test/ui/coherence/coherence-pair-covered-uncovered-1.stderr @@ -1,4 +1,4 @@ -error[E0117]: only traits defined in the current crate can be implemented for arbitrary types +error[E0117]: only traits defined in the current crate can be implemented for primitive types --> $DIR/coherence-pair-covered-uncovered-1.rs:12:1 | LL | impl Remote1>> for i32 { } diff --git a/src/test/ui/coherence/coherence-pair-covered-uncovered.stderr b/src/test/ui/coherence/coherence-pair-covered-uncovered.stderr index 34fdf64ea10..73dfe2f572a 100644 --- a/src/test/ui/coherence/coherence-pair-covered-uncovered.stderr +++ b/src/test/ui/coherence/coherence-pair-covered-uncovered.stderr @@ -1,4 +1,4 @@ -error[E0117]: only traits defined in the current crate can be implemented for arbitrary types +error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate --> $DIR/coherence-pair-covered-uncovered.rs:8:1 | LL | impl Remote for Pair> { } diff --git a/src/test/ui/coherence/coherence-vec-local-2.stderr b/src/test/ui/coherence/coherence-vec-local-2.stderr index 567b6a6c17f..95fdf172ec2 100644 --- a/src/test/ui/coherence/coherence-vec-local-2.stderr +++ b/src/test/ui/coherence/coherence-vec-local-2.stderr @@ -1,4 +1,4 @@ -error[E0117]: only traits defined in the current crate can be implemented for arbitrary types +error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate --> $DIR/coherence-vec-local-2.rs:11:1 | LL | impl Remote for Vec> { } diff --git a/src/test/ui/coherence/coherence-vec-local.stderr b/src/test/ui/coherence/coherence-vec-local.stderr index 38464f12a21..4835e771abd 100644 --- a/src/test/ui/coherence/coherence-vec-local.stderr +++ b/src/test/ui/coherence/coherence-vec-local.stderr @@ -1,4 +1,4 @@ -error[E0117]: only traits defined in the current crate can be implemented for arbitrary types +error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate --> $DIR/coherence-vec-local.rs:11:1 | LL | impl Remote for Vec { } diff --git a/src/test/ui/coherence/coherence_local_err_struct.stderr b/src/test/ui/coherence/coherence_local_err_struct.stderr index 8c310b318a7..afc6fc45d0e 100644 --- a/src/test/ui/coherence/coherence_local_err_struct.stderr +++ b/src/test/ui/coherence/coherence_local_err_struct.stderr @@ -1,4 +1,4 @@ -error[E0117]: only traits defined in the current crate can be implemented for arbitrary types +error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate --> $DIR/coherence_local_err_struct.rs:14:1 | LL | impl lib::MyCopy for lib::MyStruct { } diff --git a/src/test/ui/coherence/impl-foreign-for-foreign.stderr b/src/test/ui/coherence/impl-foreign-for-foreign.stderr index fe7c9b93f54..93f7a6fdc25 100644 --- a/src/test/ui/coherence/impl-foreign-for-foreign.stderr +++ b/src/test/ui/coherence/impl-foreign-for-foreign.stderr @@ -1,4 +1,4 @@ -error[E0117]: only traits defined in the current crate can be implemented for arbitrary types +error[E0117]: only traits defined in the current crate can be implemented for primitive types --> $DIR/impl-foreign-for-foreign.rs:10:1 | LL | impl Remote for i32 { diff --git a/src/test/ui/coherence/impl-foreign-for-foreign[foreign].stderr b/src/test/ui/coherence/impl-foreign-for-foreign[foreign].stderr index bdf19cf00a7..e24537bce22 100644 --- a/src/test/ui/coherence/impl-foreign-for-foreign[foreign].stderr +++ b/src/test/ui/coherence/impl-foreign-for-foreign[foreign].stderr @@ -1,4 +1,4 @@ -error[E0117]: only traits defined in the current crate can be implemented for arbitrary types +error[E0117]: only traits defined in the current crate can be implemented for primitive types --> $DIR/impl-foreign-for-foreign[foreign].rs:10:1 | LL | impl Remote1> for i32 { @@ -10,7 +10,7 @@ LL | impl Remote1> for i32 { | = note: define and implement a trait or new type instead -error[E0117]: only traits defined in the current crate can be implemented for arbitrary types +error[E0117]: only traits defined in the current crate can be implemented for primitive types --> $DIR/impl-foreign-for-foreign[foreign].rs:14:1 | LL | impl Remote1> for f64 { @@ -22,7 +22,7 @@ LL | impl Remote1> for f64 { | = note: define and implement a trait or new type instead -error[E0117]: only traits defined in the current crate can be implemented for arbitrary types +error[E0117]: only traits defined in the current crate can be implemented for primitive types --> $DIR/impl-foreign-for-foreign[foreign].rs:18:1 | LL | impl Remote1> for f32 { diff --git a/src/test/ui/coherence/impl-foreign-for-fundamental[foreign].stderr b/src/test/ui/coherence/impl-foreign-for-fundamental[foreign].stderr index 20dc955ffe4..55ea4409e6f 100644 --- a/src/test/ui/coherence/impl-foreign-for-fundamental[foreign].stderr +++ b/src/test/ui/coherence/impl-foreign-for-fundamental[foreign].stderr @@ -1,4 +1,4 @@ -error[E0117]: only traits defined in the current crate can be implemented for arbitrary types +error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate --> $DIR/impl-foreign-for-fundamental[foreign].rs:10:1 | LL | impl Remote for Box { @@ -10,7 +10,7 @@ LL | impl Remote for Box { | = note: define and implement a trait or new type instead -error[E0117]: only traits defined in the current crate can be implemented for arbitrary types +error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate --> $DIR/impl-foreign-for-fundamental[foreign].rs:14:1 | LL | impl Remote for Box> { diff --git a/src/test/ui/coherence/impl-foreign[foreign]-for-foreign.stderr b/src/test/ui/coherence/impl-foreign[foreign]-for-foreign.stderr index 5552d825793..65b3aa394a8 100644 --- a/src/test/ui/coherence/impl-foreign[foreign]-for-foreign.stderr +++ b/src/test/ui/coherence/impl-foreign[foreign]-for-foreign.stderr @@ -1,4 +1,4 @@ -error[E0117]: only traits defined in the current crate can be implemented for arbitrary types +error[E0117]: only traits defined in the current crate can be implemented for primitive types --> $DIR/impl-foreign[foreign]-for-foreign.rs:10:1 | LL | impl Remote1 for f64 { diff --git a/src/test/ui/coherence/impl-foreign[fundemental[foreign]]-for-foreign.stderr b/src/test/ui/coherence/impl-foreign[fundemental[foreign]]-for-foreign.stderr index c1e2fdaf5e3..8e77c13e111 100644 --- a/src/test/ui/coherence/impl-foreign[fundemental[foreign]]-for-foreign.stderr +++ b/src/test/ui/coherence/impl-foreign[fundemental[foreign]]-for-foreign.stderr @@ -1,4 +1,4 @@ -error[E0117]: only traits defined in the current crate can be implemented for arbitrary types +error[E0117]: only traits defined in the current crate can be implemented for primitive types --> $DIR/impl-foreign[fundemental[foreign]]-for-foreign.rs:11:1 | LL | impl Remote1> for i32 { @@ -11,7 +11,7 @@ LL | impl Remote1> for i32 { | = note: define and implement a trait or new type instead -error[E0117]: only traits defined in the current crate can be implemented for arbitrary types +error[E0117]: only traits defined in the current crate can be implemented for primitive types --> $DIR/impl-foreign[fundemental[foreign]]-for-foreign.rs:15:1 | LL | impl Remote1>> for f64 { @@ -24,7 +24,7 @@ LL | impl Remote1>> for f64 { | = note: define and implement a trait or new type instead -error[E0117]: only traits defined in the current crate can be implemented for arbitrary types +error[E0117]: only traits defined in the current crate can be implemented for primitive types --> $DIR/impl-foreign[fundemental[foreign]]-for-foreign.rs:19:1 | LL | impl Remote1>> for f32 { diff --git a/src/test/ui/coherence/impl[t]-foreign-for-foreign[t].stderr b/src/test/ui/coherence/impl[t]-foreign-for-foreign[t].stderr index 7f8ec83b24a..92346c29198 100644 --- a/src/test/ui/coherence/impl[t]-foreign-for-foreign[t].stderr +++ b/src/test/ui/coherence/impl[t]-foreign-for-foreign[t].stderr @@ -1,4 +1,4 @@ -error[E0117]: only traits defined in the current crate can be implemented for arbitrary types +error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate --> $DIR/impl[t]-foreign-for-foreign[t].rs:11:1 | LL | impl Remote for Rc { @@ -9,7 +9,7 @@ LL | impl Remote for Rc { | = note: define and implement a trait or new type instead -error[E0117]: only traits defined in the current crate can be implemented for arbitrary types +error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate --> $DIR/impl[t]-foreign-for-foreign[t].rs:16:1 | LL | impl Remote for Arc { diff --git a/src/test/ui/error-codes/E0117.stderr b/src/test/ui/error-codes/E0117.stderr index cdbafff2a20..76d9f5cc0e5 100644 --- a/src/test/ui/error-codes/E0117.stderr +++ b/src/test/ui/error-codes/E0117.stderr @@ -1,4 +1,4 @@ -error[E0117]: only traits defined in the current crate can be implemented for arbitrary types +error[E0117]: only traits defined in the current crate can be implemented for primitive types --> $DIR/E0117.rs:1:1 | LL | impl Drop for u32 {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-and-non-const-impl.rs b/src/test/ui/rfc-2632-const-trait-impl/const-and-non-const-impl.rs index 961968186de..dd509931766 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/const-and-non-const-impl.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/const-and-non-const-impl.rs @@ -3,7 +3,7 @@ pub struct Int(i32); impl const std::ops::Add for i32 { //~ ERROR type annotations needed - //~^ ERROR only traits defined in the current crate can be implemented for arbitrary types + //~^ ERROR only traits defined in the current crate can be implemented for primitive types type Output = Self; fn add(self, rhs: Self) -> Self { diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-and-non-const-impl.stderr b/src/test/ui/rfc-2632-const-trait-impl/const-and-non-const-impl.stderr index 154a6a35a44..9fd82196e79 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/const-and-non-const-impl.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/const-and-non-const-impl.stderr @@ -1,4 +1,4 @@ -error[E0117]: only traits defined in the current crate can be implemented for arbitrary types +error[E0117]: only traits defined in the current crate can be implemented for primitive types --> $DIR/const-and-non-const-impl.rs:5:1 | LL | impl const std::ops::Add for i32 { diff --git a/src/test/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.stderr b/src/test/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.stderr index cf5c15df705..fc3778b7967 100644 --- a/src/test/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.stderr +++ b/src/test/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.stderr @@ -26,7 +26,7 @@ error[E0321]: cross-crate traits with a default impl, like `DefaultedTrait`, can LL | impl DefaultedTrait for Box { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't implement cross-crate trait for type in another crate -error[E0117]: only traits defined in the current crate can be implemented for arbitrary types +error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate --> $DIR/typeck-default-trait-impl-cross-crate-coherence.rs:22:1 | LL | impl DefaultedTrait for lib::Something { }