@@ -251,16 +251,55 @@ impl<'ccx, 'gcx> CheckTypeWellFormedVisitor<'ccx, 'gcx> {
251
251
} ) ;
252
252
}
253
253
254
+ fn check_auto_trait ( & mut self ,
255
+ trait_def_id : DefId ,
256
+ span : Span )
257
+ {
258
+ let predicates = self . tcx ( ) . lookup_predicates ( trait_def_id) ;
259
+
260
+ // If we must exclude the Self : Trait predicate contained by all
261
+ // traits.
262
+ let no_refl_predicates : Vec < _ > =
263
+ predicates. predicates . iter ( ) . filter ( |predicate| {
264
+ match * predicate {
265
+ & ty:: Predicate :: Trait ( ref poly_trait_ref) =>
266
+ poly_trait_ref. def_id ( ) != trait_def_id,
267
+ _ => true ,
268
+ }
269
+ } ) . collect ( ) ;
270
+
271
+ let trait_def = self . tcx ( ) . lookup_trait_def ( trait_def_id) ;
272
+
273
+ // We use an if-else here, since the generics will also trigger
274
+ // an extraneous error message when we find predicates like
275
+ // `T : Sized` for a trait like: `trait Magic<T>`.
276
+ if !trait_def. generics . types . get_slice ( ParamSpace :: TypeSpace ) . is_empty ( ) {
277
+ error_566 ( self . ccx , span) ;
278
+ } else if !no_refl_predicates. is_empty ( ) {
279
+ error_565 ( self . ccx , span) ;
280
+ }
281
+
282
+ }
283
+
254
284
fn check_trait ( & mut self ,
255
285
item : & hir:: Item ,
256
286
items : & [ hir:: TraitItem ] )
257
287
{
258
288
let trait_def_id = self . tcx ( ) . map . local_def_id ( item. id ) ;
259
289
260
290
if self . tcx ( ) . trait_has_default_impl ( trait_def_id) {
291
+ // We want to both ensure:
292
+ // 1) that there are no items contained within
293
+ // the trait defintion
294
+ //
295
+ // 2) that the definition doesn't violate the no-super trait rule
296
+ // for auto traits.
297
+
261
298
if !items. is_empty ( ) {
262
299
error_380 ( self . ccx , item. span ) ;
263
300
}
301
+
302
+ self . check_auto_trait ( trait_def_id, item. span ) ;
264
303
}
265
304
266
305
self . for_item ( item) . with_fcx ( |fcx, this| {
@@ -272,6 +311,8 @@ impl<'ccx, 'gcx> CheckTypeWellFormedVisitor<'ccx, 'gcx> {
272
311
} ) ;
273
312
}
274
313
314
+
315
+
275
316
fn check_item_fn ( & mut self ,
276
317
item : & hir:: Item ,
277
318
body : & hir:: Block )
@@ -637,6 +678,18 @@ fn error_380(ccx: &CrateCtxt, span: Span) {
637
678
Trait for ..`) must have no methods or associated items")
638
679
}
639
680
681
+ fn error_565 ( ccx : & CrateCtxt , span : Span ) {
682
+ span_err ! ( ccx. tcx. sess, span, E0565 ,
683
+ "traits with default impls (`e.g. unsafe impl \
684
+ Trait for ..`) can not have predicates")
685
+ }
686
+
687
+ fn error_566 ( ccx : & CrateCtxt , span : Span ) {
688
+ span_err ! ( ccx. tcx. sess, span, E0566 ,
689
+ "traits with default impls (`e.g. unsafe impl \
690
+ Trait for ..`) can not have type parameters")
691
+ }
692
+
640
693
fn error_392 < ' a , ' tcx > ( ccx : & CrateCtxt < ' a , ' tcx > , span : Span , param_name : ast:: Name )
641
694
-> DiagnosticBuilder < ' tcx > {
642
695
let mut err = struct_span_err ! ( ccx. tcx. sess, span, E0392 ,
0 commit comments