Skip to content

Commit adfe9a4

Browse files
committed
Call out the types that are non local on E0117
1 parent 03a50ae commit adfe9a4

32 files changed

+74
-61
lines changed

src/librustc/traits/coherence.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ pub fn trait_ref_is_local_or_fundamental<'tcx>(
237237
}
238238

239239
pub enum OrphanCheckErr<'tcx> {
240-
NoLocalInputType,
240+
NonLocalInputType(Vec<Ty<'tcx>>),
241241
UncoveredTy(Ty<'tcx>),
242242
}
243243

@@ -390,6 +390,7 @@ fn orphan_check_trait_ref<'tcx>(
390390
}
391391
}
392392

393+
let mut non_local_spans = vec![];
393394
for input_ty in
394395
trait_ref.input_types().flat_map(|ty| uncover_fundamental_ty(tcx, ty, in_crate))
395396
{
@@ -401,11 +402,13 @@ fn orphan_check_trait_ref<'tcx>(
401402
debug!("orphan_check_trait_ref: uncovered ty: `{:?}`", input_ty);
402403
return Err(OrphanCheckErr::UncoveredTy(input_ty))
403404
}
405+
non_local_spans.push(input_ty);
404406
}
405407
// If we exit above loop, never found a local type.
406408
debug!("orphan_check_trait_ref: no local type");
407-
Err(OrphanCheckErr::NoLocalInputType)
409+
Err(OrphanCheckErr::NonLocalInputType(non_local_spans))
408410
} else {
411+
let mut non_local_spans = vec![];
409412
// First, create an ordered iterator over all the type
410413
// parameters to the trait, with the self type appearing
411414
// first. Find the first input type that either references a
@@ -438,10 +441,12 @@ fn orphan_check_trait_ref<'tcx>(
438441
debug!("orphan_check_trait_ref: uncovered type `{:?}`", param);
439442
return Err(OrphanCheckErr::UncoveredTy(param));
440443
}
444+
445+
non_local_spans.push(input_ty);
441446
}
442447
// If we exit above loop, never found a local type.
443448
debug!("orphan_check_trait_ref: no local type");
444-
Err(OrphanCheckErr::NoLocalInputType)
449+
Err(OrphanCheckErr::NonLocalInputType(non_local_spans))
445450
}
446451
}
447452

src/librustc_typeck/coherence/orphan.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,20 @@ impl ItemLikeVisitor<'v> for OrphanChecker<'tcx> {
3333
let sp = cm.def_span(item.span);
3434
match traits::orphan_check(self.tcx, def_id) {
3535
Ok(()) => {}
36-
Err(traits::OrphanCheckErr::NoLocalInputType) => {
37-
struct_span_err!(self.tcx.sess,
38-
sp,
39-
E0117,
40-
"only traits defined in the current crate can be \
41-
implemented for arbitrary types")
42-
.span_label(sp, "impl doesn't use types inside crate")
43-
.note("the impl does not reference only types defined in this crate")
44-
.note("define and implement a trait or new type instead")
45-
.emit();
36+
Err(traits::OrphanCheckErr::NonLocalInputType(tys)) => {
37+
let mut err = struct_span_err!(
38+
self.tcx.sess,
39+
sp,
40+
E0117,
41+
"only traits defined in the current crate can be implemented for \
42+
arbitrary types"
43+
);
44+
err.span_label(sp, "impl doesn't use types inside crate");
45+
for ty in &tys {
46+
err.note(&format!("`{}` is not defined in the current create", ty));
47+
}
48+
err.note("define and implement a trait or new type instead");
49+
err.emit();
4650
return;
4751
}
4852
Err(traits::OrphanCheckErr::UncoveredTy(param_ty)) => {

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

Lines changed: 1 addition & 1 deletion
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
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
66
|
7-
= note: the impl does not reference only types defined in this crate
7+
= note: `lib::Pair<T, Cover<T>>` is not defined in the current create
88
= note: define and implement a trait or new type instead
99

1010
error: aborting due to previous error

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

Lines changed: 1 addition & 1 deletion
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
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
66
|
7-
= note: the impl does not reference only types defined in this crate
7+
= note: `lib::Pair<Cover<T>, T>` is not defined in the current create
88
= note: define and implement a trait or new type instead
99

1010
error: aborting due to previous error

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

Lines changed: 1 addition & 1 deletion
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
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
66
|
7-
= note: the impl does not reference only types defined in this crate
7+
= note: `lib::Pair<Cover<T>, U>` is not defined in the current create
88
= note: define and implement a trait or new type instead
99

1010
error: aborting due to previous error

src/test/ui/coherence/coherence-fundamental-trait-objects.old.stderr

Lines changed: 1 addition & 1 deletion
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 Misc for dyn Fundamental<Local> {}
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
66
|
7-
= note: the impl does not reference only types defined in this crate
7+
= note: `(dyn coherence_fundamental_trait_lib::Fundamental<Local> + 'static)` is not defined in the current create
88
= note: define and implement a trait or new type instead
99

1010
error: aborting due to previous error

src/test/ui/coherence/coherence-fundamental-trait-objects.re.stderr

Lines changed: 1 addition & 1 deletion
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 Misc for dyn Fundamental<Local> {}
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
66
|
7-
= note: the impl does not reference only types defined in this crate
7+
= note: `(dyn coherence_fundamental_trait_lib::Fundamental<Local> + 'static)` is not defined in the current create
88
= note: define and implement a trait or new type instead
99

1010
error: aborting due to previous error

src/test/ui/coherence/coherence-impl-trait-for-marker-trait-negative.stderr

Lines changed: 1 addition & 1 deletion
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 dyn Marker2 {}
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
1818
|
19-
= note: the impl does not reference only types defined in this crate
19+
= note: `(dyn Marker2 + 'static)` is not defined in the current create
2020
= note: define and implement a trait or new type instead
2121

2222
error[E0321]: cross-crate traits with a default impl, like `std::marker::Send`, can only be implemented for a struct/enum type, not `(dyn Object + 'static)`

src/test/ui/coherence/coherence-impl-trait-for-marker-trait-positive.stderr

Lines changed: 1 addition & 1 deletion
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 | unsafe impl Send for dyn Marker2 {}
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
1818
|
19-
= note: the impl does not reference only types defined in this crate
19+
= note: `(dyn Marker2 + 'static)` is not defined in the current create
2020
= note: define and implement a trait or new type instead
2121

2222
error[E0321]: cross-crate traits with a default impl, like `std::marker::Send`, can only be implemented for a struct/enum type, not `(dyn Object + 'static)`

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
5151
LL | impl Copy for i32 {}
5252
| ^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
5353
|
54-
= note: the impl does not reference only types defined in this crate
54+
= note: `i32` is not defined in the current create
5555
= note: define and implement a trait or new type instead
5656

5757
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
@@ -60,7 +60,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
6060
LL | impl Copy for (MyType, MyType) {}
6161
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
6262
|
63-
= note: the impl does not reference only types defined in this crate
63+
= note: `(MyType, MyType)` is not defined in the current create
6464
= note: define and implement a trait or new type instead
6565

6666
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
@@ -69,7 +69,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
6969
LL | impl Copy for [MyType] {}
7070
| ^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
7171
|
72-
= note: the impl does not reference only types defined in this crate
72+
= note: `[MyType]` is not defined in the current create
7373
= note: define and implement a trait or new type instead
7474

7575
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
@@ -78,7 +78,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
7878
LL | impl Copy for &'static [NotSync] {}
7979
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
8080
|
81-
= note: the impl does not reference only types defined in this crate
81+
= note: `&'static [NotSync]` is not defined in the current create
8282
= note: define and implement a trait or new type instead
8383

8484
error: aborting due to 10 previous errors

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
5151
LL | impl Copy for i32 {}
5252
| ^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
5353
|
54-
= note: the impl does not reference only types defined in this crate
54+
= note: `i32` is not defined in the current create
5555
= note: define and implement a trait or new type instead
5656

5757
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
@@ -60,7 +60,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
6060
LL | impl Copy for (MyType, MyType) {}
6161
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
6262
|
63-
= note: the impl does not reference only types defined in this crate
63+
= note: `(MyType, MyType)` is not defined in the current create
6464
= note: define and implement a trait or new type instead
6565

6666
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
@@ -69,7 +69,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
6969
LL | impl Copy for [MyType] {}
7070
| ^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
7171
|
72-
= note: the impl does not reference only types defined in this crate
72+
= note: `[MyType]` is not defined in the current create
7373
= note: define and implement a trait or new type instead
7474

7575
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
@@ -78,7 +78,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
7878
LL | impl Copy for &'static [NotSync] {}
7979
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
8080
|
81-
= note: the impl does not reference only types defined in this crate
81+
= note: `[NotSync]` is not defined in the current create
8282
= note: define and implement a trait or new type instead
8383

8484
error: aborting due to 10 previous errors

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

Lines changed: 3 additions & 3 deletions
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
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
66
|
7-
= note: the impl does not reference only types defined in this crate
7+
= note: `(MyType, MyType)` is not defined in the current create
88
= note: define and implement a trait or new type instead
99

1010
error[E0321]: cross-crate traits with a default impl, like `std::marker::Send`, can only be implemented for a struct/enum type, not `&'static NotSync`
@@ -19,7 +19,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
1919
LL | unsafe impl Send for [MyType] {}
2020
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
2121
|
22-
= note: the impl does not reference only types defined in this crate
22+
= note: `[MyType]` is not defined in the current create
2323
= note: define and implement a trait or new type instead
2424

2525
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
@@ -28,7 +28,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
2828
LL | unsafe impl Send for &'static [NotSync] {}
2929
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
3030
|
31-
= note: the impl does not reference only types defined in this crate
31+
= note: `&'static [NotSync]` is not defined in the current create
3232
= note: define and implement a trait or new type instead
3333

3434
error: aborting due to 4 previous errors

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

Lines changed: 3 additions & 3 deletions
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
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
66
|
7-
= note: the impl does not reference only types defined in this crate
7+
= note: `(MyType, MyType)` is not defined in the current create
88
= note: define and implement a trait or new type instead
99

1010
error[E0321]: cross-crate traits with a default impl, like `std::marker::Send`, can only be implemented for a struct/enum type, not `&'static NotSync`
@@ -19,7 +19,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
1919
LL | unsafe impl Send for [MyType] {}
2020
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
2121
|
22-
= note: the impl does not reference only types defined in this crate
22+
= note: `[MyType]` is not defined in the current create
2323
= note: define and implement a trait or new type instead
2424

2525
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
@@ -28,7 +28,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
2828
LL | unsafe impl Send for &'static [NotSync] {}
2929
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
3030
|
31-
= note: the impl does not reference only types defined in this crate
31+
= note: `[NotSync]` is not defined in the current create
3232
= note: define and implement a trait or new type instead
3333

3434
error: aborting due to 4 previous errors

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

Lines changed: 3 additions & 3 deletions
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
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
4242
|
43-
= note: the impl does not reference only types defined in this crate
43+
= note: `(MyType, MyType)` is not defined in the current create
4444
= note: define and implement a trait or new type instead
4545

4646
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
@@ -49,7 +49,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
4949
LL | impl Sized for [MyType] {}
5050
| ^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
5151
|
52-
= note: the impl does not reference only types defined in this crate
52+
= note: `[MyType]` is not defined in the current create
5353
= note: define and implement a trait or new type instead
5454

5555
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
@@ -58,7 +58,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
5858
LL | impl Sized for &'static [NotSync] {}
5959
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
6060
|
61-
= note: the impl does not reference only types defined in this crate
61+
= note: `&'static [NotSync]` is not defined in the current create
6262
= note: define and implement a trait or new type instead
6363

6464
error: aborting due to 9 previous errors

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

Lines changed: 3 additions & 3 deletions
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
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
4242
|
43-
= note: the impl does not reference only types defined in this crate
43+
= note: `(MyType, MyType)` is not defined in the current create
4444
= note: define and implement a trait or new type instead
4545

4646
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
@@ -49,7 +49,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
4949
LL | impl Sized for [MyType] {}
5050
| ^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
5151
|
52-
= note: the impl does not reference only types defined in this crate
52+
= note: `[MyType]` is not defined in the current create
5353
= note: define and implement a trait or new type instead
5454

5555
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
@@ -58,7 +58,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
5858
LL | impl Sized for &'static [NotSync] {}
5959
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
6060
|
61-
= note: the impl does not reference only types defined in this crate
61+
= note: `[NotSync]` is not defined in the current create
6262
= note: define and implement a trait or new type instead
6363

6464
error: aborting due to 9 previous errors

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
44
LL | impl TheTrait<usize> for isize { }
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
66
|
7-
= note: the impl does not reference only types defined in this crate
7+
= note: `isize` is not defined in the current create
8+
= note: `usize` is not defined in the current create
89
= note: define and implement a trait or new type instead
910

1011
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
@@ -13,7 +14,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
1314
LL | impl !Send for Vec<isize> { }
1415
| ^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
1516
|
16-
= note: the impl does not reference only types defined in this crate
17+
= note: `std::vec::Vec<isize>` is not defined in the current create
1718
= note: define and implement a trait or new type instead
1819

1920
error: aborting due to 2 previous errors

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
44
LL | impl TheTrait<usize> for isize { }
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
66
|
7-
= note: the impl does not reference only types defined in this crate
7+
= note: `isize` is not defined in the current create
8+
= note: `usize` is not defined in the current create
89
= note: define and implement a trait or new type instead
910

1011
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
@@ -13,7 +14,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
1314
LL | impl !Send for Vec<isize> { }
1415
| ^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
1516
|
16-
= note: the impl does not reference only types defined in this crate
17+
= note: `std::vec::Vec<isize>` is not defined in the current create
1718
= note: define and implement a trait or new type instead
1819

1920
error: aborting due to 2 previous errors

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

Lines changed: 1 addition & 1 deletion
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
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
66
|
7-
= note: the impl does not reference only types defined in this crate
7+
= note: `lib::Pair<T, Foo>` is not defined in the current create
88
= note: define and implement a trait or new type instead
99

1010
error: aborting due to previous error

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
44
LL | impl<T, U> Remote1<Pair<T, Local<U>>> for i32 { }
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
66
|
7-
= note: the impl does not reference only types defined in this crate
7+
= note: `i32` is not defined in the current create
8+
= note: `lib::Pair<T, Local<U>>` is not defined in the current create
89
= note: define and implement a trait or new type instead
910

1011
error: aborting due to previous error

0 commit comments

Comments
 (0)