Skip to content

Commit b100c02

Browse files
authored
Rollup merge of #96273 - TaKO8Ki:make-E0117-error-clear, r=davidtwco
Make `E0117` error clear closes #96227
2 parents 9834674 + f5a8ee4 commit b100c02

22 files changed

+36
-30
lines changed

compiler/rustc_typeck/src/coherence/orphan.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ fn orphan_check_impl(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), ErrorGua
5050
tcx,
5151
sp,
5252
tr.path.span,
53+
trait_ref.self_ty(),
5354
impl_.self_ty.span,
5455
&impl_.generics,
5556
err,
@@ -201,18 +202,23 @@ fn emit_orphan_check_error<'tcx>(
201202
tcx: TyCtxt<'tcx>,
202203
sp: Span,
203204
trait_span: Span,
205+
self_ty: Ty<'tcx>,
204206
self_ty_span: Span,
205207
generics: &hir::Generics<'tcx>,
206208
err: traits::OrphanCheckErr<'tcx>,
207209
) -> Result<!, ErrorGuaranteed> {
208210
Err(match err {
209211
traits::OrphanCheckErr::NonLocalInputType(tys) => {
212+
let msg = match self_ty.kind() {
213+
ty::Adt(..) => "can be implemented for types defined outside of the crate",
214+
_ if self_ty.is_primitive() => "can be implemented for primitive types",
215+
_ => "can be implemented for arbitrary types",
216+
};
210217
let mut err = struct_span_err!(
211218
tcx.sess,
212219
sp,
213220
E0117,
214-
"only traits defined in the current crate can be implemented for \
215-
arbitrary types"
221+
"only traits defined in the current crate {msg}"
216222
);
217223
err.span_label(sp, "impl doesn't use only types from inside the current crate");
218224
for (ty, is_target_ty) in &tys {

src/test/ui/coherence/coherence-cow.re_a.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
1+
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
22
--> $DIR/coherence-cow.rs:18:1
33
|
44
LL | impl<T> Remote for Pair<T,Cover<T>> { }

src/test/ui/coherence/coherence-cow.re_b.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
1+
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
22
--> $DIR/coherence-cow.rs:22:1
33
|
44
LL | impl<T> Remote for Pair<Cover<T>,T> { }

src/test/ui/coherence/coherence-cow.re_c.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
1+
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
22
--> $DIR/coherence-cow.rs:26:1
33
|
44
LL | impl<T,U> Remote for Pair<Cover<T>,U> { }

src/test/ui/coherence/coherence-impls-copy.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
1+
error[E0117]: only traits defined in the current crate can be implemented for primitive types
22
--> $DIR/coherence-impls-copy.rs:5:1
33
|
44
LL | impl Copy for i32 {}

src/test/ui/coherence/coherence-orphan.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
1+
error[E0117]: only traits defined in the current crate can be implemented for primitive types
22
--> $DIR/coherence-orphan.rs:10:1
33
|
44
LL | impl TheTrait<usize> for isize { }
@@ -10,7 +10,7 @@ LL | impl TheTrait<usize> for isize { }
1010
|
1111
= note: define and implement a trait or new type instead
1212

13-
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
13+
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
1414
--> $DIR/coherence-orphan.rs:17:1
1515
|
1616
LL | impl !Send for Vec<isize> { }

src/test/ui/coherence/coherence-overlapping-pairs.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
1+
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
22
--> $DIR/coherence-overlapping-pairs.rs:8:1
33
|
44
LL | impl<T> Remote for lib::Pair<T,Foo> { }

src/test/ui/coherence/coherence-pair-covered-uncovered-1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
1+
error[E0117]: only traits defined in the current crate can be implemented for primitive types
22
--> $DIR/coherence-pair-covered-uncovered-1.rs:12:1
33
|
44
LL | impl<T, U> Remote1<Pair<T, Local<U>>> for i32 { }

src/test/ui/coherence/coherence-pair-covered-uncovered.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
1+
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
22
--> $DIR/coherence-pair-covered-uncovered.rs:8:1
33
|
44
LL | impl<T,U> Remote for Pair<T,Local<U>> { }

src/test/ui/coherence/coherence-vec-local-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
1+
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
22
--> $DIR/coherence-vec-local-2.rs:11:1
33
|
44
LL | impl<T> Remote for Vec<Local<T>> { }

src/test/ui/coherence/coherence-vec-local.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
1+
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
22
--> $DIR/coherence-vec-local.rs:11:1
33
|
44
LL | impl Remote for Vec<Local> { }

src/test/ui/coherence/coherence_local_err_struct.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
1+
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
22
--> $DIR/coherence_local_err_struct.rs:14:1
33
|
44
LL | impl lib::MyCopy for lib::MyStruct<MyType> { }

src/test/ui/coherence/impl-foreign-for-foreign.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
1+
error[E0117]: only traits defined in the current crate can be implemented for primitive types
22
--> $DIR/impl-foreign-for-foreign.rs:10:1
33
|
44
LL | impl Remote for i32 {

src/test/ui/coherence/impl-foreign-for-foreign[foreign].stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
1+
error[E0117]: only traits defined in the current crate can be implemented for primitive types
22
--> $DIR/impl-foreign-for-foreign[foreign].rs:10:1
33
|
44
LL | impl Remote1<Rc<i32>> for i32 {
@@ -10,7 +10,7 @@ LL | impl Remote1<Rc<i32>> for i32 {
1010
|
1111
= note: define and implement a trait or new type instead
1212

13-
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
13+
error[E0117]: only traits defined in the current crate can be implemented for primitive types
1414
--> $DIR/impl-foreign-for-foreign[foreign].rs:14:1
1515
|
1616
LL | impl Remote1<Rc<Local>> for f64 {
@@ -22,7 +22,7 @@ LL | impl Remote1<Rc<Local>> for f64 {
2222
|
2323
= note: define and implement a trait or new type instead
2424

25-
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
25+
error[E0117]: only traits defined in the current crate can be implemented for primitive types
2626
--> $DIR/impl-foreign-for-foreign[foreign].rs:18:1
2727
|
2828
LL | impl<T> Remote1<Rc<T>> for f32 {

src/test/ui/coherence/impl-foreign-for-fundamental[foreign].stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
1+
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
22
--> $DIR/impl-foreign-for-fundamental[foreign].rs:10:1
33
|
44
LL | impl Remote for Box<i32> {
@@ -10,7 +10,7 @@ LL | impl Remote for Box<i32> {
1010
|
1111
= note: define and implement a trait or new type instead
1212

13-
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
13+
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
1414
--> $DIR/impl-foreign-for-fundamental[foreign].rs:14:1
1515
|
1616
LL | impl<T> Remote for Box<Rc<T>> {

src/test/ui/coherence/impl-foreign[foreign]-for-foreign.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
1+
error[E0117]: only traits defined in the current crate can be implemented for primitive types
22
--> $DIR/impl-foreign[foreign]-for-foreign.rs:10:1
33
|
44
LL | impl Remote1<u32> for f64 {

src/test/ui/coherence/impl-foreign[fundemental[foreign]]-for-foreign.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
1+
error[E0117]: only traits defined in the current crate can be implemented for primitive types
22
--> $DIR/impl-foreign[fundemental[foreign]]-for-foreign.rs:11:1
33
|
44
LL | impl Remote1<Box<String>> for i32 {
@@ -11,7 +11,7 @@ LL | impl Remote1<Box<String>> for i32 {
1111
|
1212
= note: define and implement a trait or new type instead
1313

14-
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
14+
error[E0117]: only traits defined in the current crate can be implemented for primitive types
1515
--> $DIR/impl-foreign[fundemental[foreign]]-for-foreign.rs:15:1
1616
|
1717
LL | impl Remote1<Box<Rc<i32>>> for f64 {
@@ -24,7 +24,7 @@ LL | impl Remote1<Box<Rc<i32>>> for f64 {
2424
|
2525
= note: define and implement a trait or new type instead
2626

27-
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
27+
error[E0117]: only traits defined in the current crate can be implemented for primitive types
2828
--> $DIR/impl-foreign[fundemental[foreign]]-for-foreign.rs:19:1
2929
|
3030
LL | impl<T> Remote1<Box<Rc<T>>> for f32 {

src/test/ui/coherence/impl[t]-foreign-for-foreign[t].stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
1+
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
22
--> $DIR/impl[t]-foreign-for-foreign[t].rs:11:1
33
|
44
LL | impl Remote for Rc<Local> {
@@ -9,7 +9,7 @@ LL | impl Remote for Rc<Local> {
99
|
1010
= note: define and implement a trait or new type instead
1111

12-
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
12+
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
1313
--> $DIR/impl[t]-foreign-for-foreign[t].rs:16:1
1414
|
1515
LL | impl<T> Remote for Arc<T> {

src/test/ui/error-codes/E0117.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
1+
error[E0117]: only traits defined in the current crate can be implemented for primitive types
22
--> $DIR/E0117.rs:1:1
33
|
44
LL | impl Drop for u32 {}

src/test/ui/rfc-2632-const-trait-impl/const-and-non-const-impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
pub struct Int(i32);
44

55
impl const std::ops::Add for i32 { //~ ERROR type annotations needed
6-
//~^ ERROR only traits defined in the current crate can be implemented for arbitrary types
6+
//~^ ERROR only traits defined in the current crate can be implemented for primitive types
77
type Output = Self;
88

99
fn add(self, rhs: Self) -> Self {

src/test/ui/rfc-2632-const-trait-impl/const-and-non-const-impl.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
1+
error[E0117]: only traits defined in the current crate can be implemented for primitive types
22
--> $DIR/const-and-non-const-impl.rs:5:1
33
|
44
LL | impl const std::ops::Add for i32 {

src/test/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ error[E0321]: cross-crate traits with a default impl, like `DefaultedTrait`, can
2626
LL | impl DefaultedTrait for Box<C> { }
2727
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't implement cross-crate trait for type in another crate
2828

29-
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
29+
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
3030
--> $DIR/typeck-default-trait-impl-cross-crate-coherence.rs:22:1
3131
|
3232
LL | impl DefaultedTrait for lib::Something<C> { }

0 commit comments

Comments
 (0)