@@ -184,11 +184,19 @@ fn emit_orphan_check_error<'tcx>(
184
184
ty:: Adt ( def, _) => tcx. mk_adt ( * def, ty:: List :: empty ( ) ) ,
185
185
_ => ty,
186
186
} ;
187
- let this = "this" . to_string ( ) ;
188
- let ( ty, postfix) = match & ty. kind ( ) {
189
- ty:: Slice ( _) => ( this, " because slices are always foreign" ) ,
190
- ty:: Array ( ..) => ( this, " because arrays are always foreign" ) ,
191
- ty:: Tuple ( ..) => ( this, " because tuples are always foreign" ) ,
187
+ let msg = |ty : & str , postfix : & str | {
188
+ format ! ( "{ty} is not defined in the current crate{postfix}" )
189
+ } ;
190
+ let this = |name : & str | msg ( "this" , & format ! ( " because {name} are always foreign" ) ) ;
191
+ let msg = match & ty. kind ( ) {
192
+ ty:: Slice ( _) => this ( "slices" ) ,
193
+ ty:: Array ( ..) => this ( "arrays" ) ,
194
+ ty:: Tuple ( ..) => this ( "tuples" ) ,
195
+ ty:: Alias ( ty:: Opaque , ..) => {
196
+ "type alias impl trait is treated as if it were foreign, \
197
+ because its hidden type could be from a foreign crate"
198
+ . to_string ( )
199
+ }
192
200
ty:: RawPtr ( ptr_ty) => {
193
201
emit_newtype_suggestion_for_raw_ptr (
194
202
full_impl_span,
@@ -198,12 +206,11 @@ fn emit_orphan_check_error<'tcx>(
198
206
& mut err,
199
207
) ;
200
208
201
- ( format ! ( "`{}`" , ty ) , " because raw pointers are always foreign" )
209
+ msg ( & format ! ( "`{ty }`" ) , " because raw pointers are always foreign" )
202
210
}
203
- _ => ( format ! ( "`{}`" , ty ) , "" ) ,
211
+ _ => msg ( & format ! ( "`{ty }`" ) , "" ) ,
204
212
} ;
205
213
206
- let msg = format ! ( "{} is not defined in the current crate{}" , ty, postfix) ;
207
214
if is_target_ty {
208
215
// Point at `D<A>` in `impl<A, B> for C<B> in D<A>`
209
216
err. span_label ( self_ty_span, & msg) ;
0 commit comments