Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make E0117 error clear #96273

Merged
merged 2 commits into from
Apr 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions compiler/rustc_typeck/src/coherence/orphan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -201,18 +202,23 @@ 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<!, ErrorGuaranteed> {
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",
_ 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 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/coherence/coherence-cow.re_a.stderr
Original file line number Diff line number Diff line change
@@ -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<T> Remote for Pair<T,Cover<T>> { }
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/coherence/coherence-cow.re_b.stderr
Original file line number Diff line number Diff line change
@@ -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<T> Remote for Pair<Cover<T>,T> { }
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/coherence/coherence-cow.re_c.stderr
Original file line number Diff line number Diff line change
@@ -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<T,U> Remote for Pair<Cover<T>,U> { }
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/coherence/coherence-impls-copy.stderr
Original file line number Diff line number Diff line change
@@ -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 {}
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/coherence/coherence-orphan.stderr
Original file line number Diff line number Diff line change
@@ -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<usize> for isize { }
Expand All @@ -10,7 +10,7 @@ LL | impl TheTrait<usize> 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<isize> { }
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/coherence/coherence-overlapping-pairs.stderr
Original file line number Diff line number Diff line change
@@ -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<T> Remote for lib::Pair<T,Foo> { }
Expand Down
Original file line number Diff line number Diff line change
@@ -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<T, U> Remote1<Pair<T, Local<U>>> for i32 { }
Expand Down
Original file line number Diff line number Diff line change
@@ -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<T,U> Remote for Pair<T,Local<U>> { }
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/coherence/coherence-vec-local-2.stderr
Original file line number Diff line number Diff line change
@@ -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<T> Remote for Vec<Local<T>> { }
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/coherence/coherence-vec-local.stderr
Original file line number Diff line number Diff line change
@@ -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<Local> { }
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/coherence/coherence_local_err_struct.stderr
Original file line number Diff line number Diff line change
@@ -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<MyType> { }
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/coherence/impl-foreign-for-foreign.stderr
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Rc<i32>> for i32 {
Expand All @@ -10,7 +10,7 @@ LL | impl Remote1<Rc<i32>> 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<Rc<Local>> for f64 {
Expand All @@ -22,7 +22,7 @@ LL | impl Remote1<Rc<Local>> 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<T> Remote1<Rc<T>> for f32 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<i32> {
Expand All @@ -10,7 +10,7 @@ LL | impl Remote for Box<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 types defined outside of the crate
--> $DIR/impl-foreign-for-fundamental[foreign].rs:14:1
|
LL | impl<T> Remote for Box<Rc<T>> {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<u32> for f64 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Box<String>> for i32 {
Expand All @@ -11,7 +11,7 @@ LL | impl Remote1<Box<String>> 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<Box<Rc<i32>>> for f64 {
Expand All @@ -24,7 +24,7 @@ LL | impl Remote1<Box<Rc<i32>>> 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<T> Remote1<Box<Rc<T>>> for f32 {
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/coherence/impl[t]-foreign-for-foreign[t].stderr
Original file line number Diff line number Diff line change
@@ -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<Local> {
Expand All @@ -9,7 +9,7 @@ LL | impl Remote for Rc<Local> {
|
= 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<T> Remote for Arc<T> {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/error-codes/E0117.stderr
Original file line number Diff line number Diff line change
@@ -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 {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ error[E0321]: cross-crate traits with a default impl, like `DefaultedTrait`, can
LL | impl DefaultedTrait for Box<C> { }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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<C> { }
Expand Down