Skip to content

Commit 95364df

Browse files
committed
Do not display ADT type arguments and fix rebase
1 parent db1bfbd commit 95364df

30 files changed

+106
-73
lines changed

src/librustc_typeck/coherence/orphan.rs

+17-12
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,28 @@ impl ItemLikeVisitor<'v> for OrphanChecker<'tcx> {
4343
);
4444
err.span_label(sp, "impl doesn't use only types from inside the current crate");
4545
for (ty, is_target_ty) in &tys {
46-
// FIXME: We want to remove the type arguments from the displayed type.
47-
// The reverse of `resolve_vars_if_possible`.
4846
let mut ty = *ty;
4947
self.tcx.infer_ctxt().enter(|infcx| {
5048
// Remove the lifetimes unnecessary for this error.
5149
ty = infcx.freshen(ty);
5250
});
53-
let msg = format!(
54-
"`{}` is not defined in the current crate{}",
55-
ty,
56-
match &ty.kind {
57-
ty::Slice(_) => " because slices are always foreign",
58-
ty::Array(..) => " because arrays are always foreign",
59-
ty::Tuple(..) => " because tuples are always foreign",
60-
_ => "",
61-
},
62-
);
51+
ty = match ty.kind {
52+
// Remove the type arguments from the output, as they are not relevant.
53+
// You can think of this as the reverse of `resolve_vars_if_possible`.
54+
// That way if we had `Vec<MyType>`, we will properly attribute the
55+
// problem to `Vec<T>` and avoid confusing the user if they were to see
56+
// `MyType` in the error.
57+
ty::Adt(def, _) => self.tcx.mk_adt(def, ty::List::empty()),
58+
_ => ty,
59+
};
60+
let this = "this".to_string();
61+
let (ty, postfix) = match &ty.kind {
62+
ty::Slice(_) => (this, " because slices are always foreign"),
63+
ty::Array(..) => (this, " because arrays are always foreign"),
64+
ty::Tuple(..) => (this, " because tuples are always foreign"),
65+
_ => (format!("`{}`", ty), ""),
66+
};
67+
let msg = format!("{} is not defined in the current crate{}", ty, postfix);
6368
if *is_target_ty {
6469
// Point at `D<A>` in `impl<A, B> for C<B> in D<A>`
6570
err.span_label(impl_ty.span, &msg);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
44
LL | impl<T> Remote for Pair<T,Cover<T>> { }
55
| ^^^^^^^^^^^^^^^^^^^----------------
66
| | |
7-
| | `lib::Pair<T, Cover<T>>` is not defined in the current crate
7+
| | `lib::Pair` is not defined in the current crate
88
| impl doesn't use only types from inside the current crate
99
|
1010
= note: define and implement a trait or new type instead

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
44
LL | impl<T> Remote for Pair<Cover<T>,T> { }
55
| ^^^^^^^^^^^^^^^^^^^----------------
66
| | |
7-
| | `lib::Pair<Cover<T>, T>` is not defined in the current crate
7+
| | `lib::Pair` is not defined in the current crate
88
| impl doesn't use only types from inside the current crate
99
|
1010
= note: define and implement a trait or new type instead

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
44
LL | impl<T,U> Remote for Pair<Cover<T>,U> { }
55
| ^^^^^^^^^^^^^^^^^^^^^----------------
66
| | |
7-
| | `lib::Pair<Cover<T>, U>` is not defined in the current crate
7+
| | `lib::Pair` is not defined in the current crate
88
| impl doesn't use only types from inside the current crate
99
|
1010
= note: define and implement a trait or new type instead

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
6262
LL | impl Copy for (MyType, MyType) {}
6363
| ^^^^^^^^^^^^^^----------------
6464
| | |
65-
| | `(MyType, MyType)` is not defined in the current crate because tuples are always foreign
65+
| | this is not defined in the current crate because tuples are always foreign
6666
| impl doesn't use only types from inside the current crate
6767
|
6868
= note: define and implement a trait or new type instead
@@ -73,7 +73,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
7373
LL | impl Copy for [MyType] {}
7474
| ^^^^^^^^^^^^^^--------
7575
| | |
76-
| | `[MyType]` is not defined in the current crate because slices are always foreign
76+
| | this is not defined in the current crate because slices are always foreign
7777
| impl doesn't use only types from inside the current crate
7878
|
7979
= note: define and implement a trait or new type instead
@@ -84,7 +84,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
8484
LL | impl Copy for &'static [NotSync] {}
8585
| ^^^^^^^^^^^^^^------------------
8686
| | |
87-
| | `[NotSync]` is not defined in the current crate because slices are always foreign
87+
| | this is not defined in the current crate because slices are always foreign
8888
| impl doesn't use only types from inside the current crate
8989
|
9090
= note: define and implement a trait or new type instead

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
6262
LL | impl Copy for (MyType, MyType) {}
6363
| ^^^^^^^^^^^^^^----------------
6464
| | |
65-
| | `(MyType, MyType)` is not defined in the current crate because tuples are always foreign
65+
| | this is not defined in the current crate because tuples are always foreign
6666
| impl doesn't use only types from inside the current crate
6767
|
6868
= note: define and implement a trait or new type instead
@@ -73,7 +73,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
7373
LL | impl Copy for [MyType] {}
7474
| ^^^^^^^^^^^^^^--------
7575
| | |
76-
| | `[MyType]` is not defined in the current crate because slices are always foreign
76+
| | this is not defined in the current crate because slices are always foreign
7777
| impl doesn't use only types from inside the current crate
7878
|
7979
= note: define and implement a trait or new type instead
@@ -84,7 +84,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
8484
LL | impl Copy for &'static [NotSync] {}
8585
| ^^^^^^^^^^^^^^------------------
8686
| | |
87-
| | `[NotSync]` is not defined in the current crate because slices are always foreign
87+
| | this is not defined in the current crate because slices are always foreign
8888
| impl doesn't use only types from inside the current crate
8989
|
9090
= note: define and implement a trait or new type instead

src/test/ui/coherence/coherence-impls-send.old.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
44
LL | unsafe impl Send for (MyType, MyType) {}
55
| ^^^^^^^^^^^^^^^^^^^^^----------------
66
| | |
7-
| | `(MyType, MyType)` is not defined in the current crate because tuples are always foreign
7+
| | this is not defined in the current crate because tuples are always foreign
88
| impl doesn't use only types from inside the current crate
99
|
1010
= note: define and implement a trait or new type instead
@@ -21,7 +21,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
2121
LL | unsafe impl Send for [MyType] {}
2222
| ^^^^^^^^^^^^^^^^^^^^^--------
2323
| | |
24-
| | `[MyType]` is not defined in the current crate because slices are always foreign
24+
| | this is not defined in the current crate because slices are always foreign
2525
| impl doesn't use only types from inside the current crate
2626
|
2727
= note: define and implement a trait or new type instead
@@ -32,7 +32,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
3232
LL | unsafe impl Send for &'static [NotSync] {}
3333
| ^^^^^^^^^^^^^^^^^^^^^------------------
3434
| | |
35-
| | `[NotSync]` is not defined in the current crate because slices are always foreign
35+
| | this is not defined in the current crate because slices are always foreign
3636
| impl doesn't use only types from inside the current crate
3737
|
3838
= note: define and implement a trait or new type instead

src/test/ui/coherence/coherence-impls-send.re.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
44
LL | unsafe impl Send for (MyType, MyType) {}
55
| ^^^^^^^^^^^^^^^^^^^^^----------------
66
| | |
7-
| | `(MyType, MyType)` is not defined in the current crate because tuples are always foreign
7+
| | this is not defined in the current crate because tuples are always foreign
88
| impl doesn't use only types from inside the current crate
99
|
1010
= note: define and implement a trait or new type instead
@@ -21,7 +21,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
2121
LL | unsafe impl Send for [MyType] {}
2222
| ^^^^^^^^^^^^^^^^^^^^^--------
2323
| | |
24-
| | `[MyType]` is not defined in the current crate because slices are always foreign
24+
| | this is not defined in the current crate because slices are always foreign
2525
| impl doesn't use only types from inside the current crate
2626
|
2727
= note: define and implement a trait or new type instead
@@ -32,7 +32,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
3232
LL | unsafe impl Send for &'static [NotSync] {}
3333
| ^^^^^^^^^^^^^^^^^^^^^------------------
3434
| | |
35-
| | `[NotSync]` is not defined in the current crate because slices are always foreign
35+
| | this is not defined in the current crate because slices are always foreign
3636
| impl doesn't use only types from inside the current crate
3737
|
3838
= note: define and implement a trait or new type instead

src/test/ui/coherence/coherence-impls-sized.old.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
4040
LL | impl Sized for (MyType, MyType) {}
4141
| ^^^^^^^^^^^^^^^----------------
4242
| | |
43-
| | `(MyType, MyType)` is not defined in the current crate because tuples are always foreign
43+
| | this is not defined in the current crate because tuples are always foreign
4444
| impl doesn't use only types from inside the current crate
4545
|
4646
= note: define and implement a trait or new type instead
@@ -51,7 +51,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
5151
LL | impl Sized for [MyType] {}
5252
| ^^^^^^^^^^^^^^^--------
5353
| | |
54-
| | `[MyType]` is not defined in the current crate because slices are always foreign
54+
| | this is not defined in the current crate because slices are always foreign
5555
| impl doesn't use only types from inside the current crate
5656
|
5757
= note: define and implement a trait or new type instead
@@ -62,7 +62,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
6262
LL | impl Sized for &'static [NotSync] {}
6363
| ^^^^^^^^^^^^^^^------------------
6464
| | |
65-
| | `[NotSync]` is not defined in the current crate because slices are always foreign
65+
| | this is not defined in the current crate because slices are always foreign
6666
| impl doesn't use only types from inside the current crate
6767
|
6868
= note: define and implement a trait or new type instead

src/test/ui/coherence/coherence-impls-sized.re.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
4040
LL | impl Sized for (MyType, MyType) {}
4141
| ^^^^^^^^^^^^^^^----------------
4242
| | |
43-
| | `(MyType, MyType)` is not defined in the current crate because tuples are always foreign
43+
| | this is not defined in the current crate because tuples are always foreign
4444
| impl doesn't use only types from inside the current crate
4545
|
4646
= note: define and implement a trait or new type instead
@@ -51,7 +51,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
5151
LL | impl Sized for [MyType] {}
5252
| ^^^^^^^^^^^^^^^--------
5353
| | |
54-
| | `[MyType]` is not defined in the current crate because slices are always foreign
54+
| | this is not defined in the current crate because slices are always foreign
5555
| impl doesn't use only types from inside the current crate
5656
|
5757
= note: define and implement a trait or new type instead
@@ -62,7 +62,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
6262
LL | impl Sized for &'static [NotSync] {}
6363
| ^^^^^^^^^^^^^^^------------------
6464
| | |
65-
| | `[NotSync]` is not defined in the current crate because slices are always foreign
65+
| | this is not defined in the current crate because slices are always foreign
6666
| impl doesn't use only types from inside the current crate
6767
|
6868
= note: define and implement a trait or new type instead

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
1616
LL | impl !Send for Vec<isize> { }
1717
| ^^^^^^^^^^^^^^^----------
1818
| | |
19-
| | `std::vec::Vec<isize>` is not defined in the current crate
19+
| | `std::vec::Vec` is not defined in the current crate
2020
| impl doesn't use only types from inside the current crate
2121
|
2222
= note: define and implement a trait or new type instead

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
1616
LL | impl !Send for Vec<isize> { }
1717
| ^^^^^^^^^^^^^^^----------
1818
| | |
19-
| | `std::vec::Vec<isize>` is not defined in the current crate
19+
| | `std::vec::Vec` is not defined in the current crate
2020
| impl doesn't use only types from inside the current crate
2121
|
2222
= note: define and implement a trait or new type instead

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
44
LL | impl<T> Remote for lib::Pair<T,Foo> { }
55
| ^^^^^^^^^^^^^^^^^^^----------------
66
| | |
7-
| | `lib::Pair<T, Foo>` is not defined in the current crate
7+
| | `lib::Pair` is not defined in the current crate
88
| impl doesn't use only types from inside the current crate
99
|
1010
= note: define and implement a trait or new type instead

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | impl<T, U> Remote1<Pair<T, Local<U>>> for i32 { }
55
| ^^^^^^^^^^^--------------------------^^^^^---
66
| | | |
77
| | | `i32` is not defined in the current crate
8-
| | `lib::Pair<T, Local<U>>` is not defined in the current crate
8+
| | `lib::Pair` is not defined in the current crate
99
| impl doesn't use only types from inside the current crate
1010
|
1111
= note: define and implement a trait or new type instead

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
44
LL | impl<T,U> Remote for Pair<T,Local<U>> { }
55
| ^^^^^^^^^^^^^^^^^^^^^----------------
66
| | |
7-
| | `lib::Pair<T, Local<U>>` is not defined in the current crate
7+
| | `lib::Pair` is not defined in the current crate
88
| impl doesn't use only types from inside the current crate
99
|
1010
= note: define and implement a trait or new type instead

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
44
LL | impl<T> Remote for Vec<Local<T>> { }
55
| ^^^^^^^^^^^^^^^^^^^-------------
66
| | |
7-
| | `std::vec::Vec<Local<T>>` is not defined in the current crate
7+
| | `std::vec::Vec` is not defined in the current crate
88
| impl doesn't use only types from inside the current crate
99
|
1010
= note: define and implement a trait or new type instead

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
44
LL | impl Remote for Vec<Local> { }
55
| ^^^^^^^^^^^^^^^^----------
66
| | |
7-
| | `std::vec::Vec<Local>` is not defined in the current crate
7+
| | `std::vec::Vec` is not defined in the current crate
88
| impl doesn't use only types from inside the current crate
99
|
1010
= note: define and implement a trait or new type instead

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
44
LL | impl Remote for Vec<Local> { }
55
| ^^^^^^^^^^^^^^^^----------
66
| | |
7-
| | `std::vec::Vec<Local>` is not defined in the current crate
7+
| | `std::vec::Vec` is not defined in the current crate
88
| impl doesn't use only types from inside the current crate
99
|
1010
= note: define and implement a trait or new type instead

src/test/ui/coherence/coherence_local_err_struct.old.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
44
LL | impl lib::MyCopy for lib::MyStruct<MyType> { }
55
| ^^^^^^^^^^^^^^^^^^^^^---------------------
66
| | |
7-
| | `lib::MyStruct<MyType>` is not defined in the current crate
7+
| | `lib::MyStruct` is not defined in the current crate
88
| impl doesn't use only types from inside the current crate
99
|
1010
= note: define and implement a trait or new type instead

src/test/ui/coherence/coherence_local_err_struct.re.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
44
LL | impl lib::MyCopy for lib::MyStruct<MyType> { }
55
| ^^^^^^^^^^^^^^^^^^^^^---------------------
66
| | |
7-
| | `lib::MyStruct<MyType>` is not defined in the current crate
7+
| | `lib::MyStruct` is not defined in the current crate
88
| impl doesn't use only types from inside the current crate
99
|
1010
= note: define and implement a trait or new type instead

src/test/ui/coherence/coherence_local_err_tuple.old.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
44
LL | impl lib::MyCopy for (MyType,) { }
55
| ^^^^^^^^^^^^^^^^^^^^^---------
66
| | |
7-
| | `(MyType,)` is not defined in the current crate because tuples are always foreign
7+
| | this is not defined in the current crate because tuples are always foreign
88
| impl doesn't use only types from inside the current crate
99
|
1010
= note: define and implement a trait or new type instead

src/test/ui/coherence/coherence_local_err_tuple.re.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
44
LL | impl lib::MyCopy for (MyType,) { }
55
| ^^^^^^^^^^^^^^^^^^^^^---------
66
| | |
7-
| | `(MyType,)` is not defined in the current crate because tuples are always foreign
7+
| | this is not defined in the current crate because tuples are always foreign
88
| impl doesn't use only types from inside the current crate
99
|
1010
= note: define and implement a trait or new type instead

0 commit comments

Comments
 (0)