@@ -43,23 +43,28 @@ impl ItemLikeVisitor<'v> for OrphanChecker<'tcx> {
43
43
) ;
44
44
err. span_label ( sp, "impl doesn't use only types from inside the current crate" ) ;
45
45
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`.
48
46
let mut ty = * ty;
49
47
self . tcx . infer_ctxt ( ) . enter ( |infcx| {
50
48
// Remove the lifetimes unnecessary for this error.
51
49
ty = infcx. freshen ( ty) ;
52
50
} ) ;
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) ;
63
68
if * is_target_ty {
64
69
// Point at `D<A>` in `impl<A, B> for C<B> in D<A>`
65
70
err. span_label ( impl_ty. span , & msg) ;
0 commit comments