Skip to content

Commit b100c02

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

22 files changed

+36
-30
lines changed

compiler/rustc_typeck/src/coherence/orphan.rs

Lines changed: 8 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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>> { }

0 commit comments

Comments
 (0)