@@ -251,16 +251,55 @@ impl<'ccx, 'gcx> CheckTypeWellFormedVisitor<'ccx, 'gcx> {
251251 } ) ;
252252 }
253253
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+
254284 fn check_trait ( & mut self ,
255285 item : & hir:: Item ,
256286 items : & [ hir:: TraitItem ] )
257287 {
258288 let trait_def_id = self . tcx ( ) . map . local_def_id ( item. id ) ;
259289
260290 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+
261298 if !items. is_empty ( ) {
262299 error_380 ( self . ccx , item. span ) ;
263300 }
301+
302+ self . check_auto_trait ( trait_def_id, item. span ) ;
264303 }
265304
266305 self . for_item ( item) . with_fcx ( |fcx, this| {
@@ -272,6 +311,8 @@ impl<'ccx, 'gcx> CheckTypeWellFormedVisitor<'ccx, 'gcx> {
272311 } ) ;
273312 }
274313
314+
315+
275316 fn check_item_fn ( & mut self ,
276317 item : & hir:: Item ,
277318 body : & hir:: Block )
@@ -637,6 +678,18 @@ fn error_380(ccx: &CrateCtxt, span: Span) {
637678 Trait for ..`) must have no methods or associated items")
638679}
639680
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+
640693fn error_392 < ' a , ' tcx > ( ccx : & CrateCtxt < ' a , ' tcx > , span : Span , param_name : ast:: Name )
641694 -> DiagnosticBuilder < ' tcx > {
642695 let mut err = struct_span_err ! ( ccx. tcx. sess, span, E0392 ,
0 commit comments