@@ -683,31 +683,53 @@ impl<'a> AstValidator<'a> {
683683 }
684684 }
685685
686+ fn emit_e0568 ( & self , span : Span , ident_span : Span ) {
687+ struct_span_err ! (
688+ self . session,
689+ span,
690+ E0568 ,
691+ "auto traits cannot have super traits or lifetime bounds"
692+ )
693+ . span_label ( ident_span, "auto trait cannot have super traits or lifetime bounds" )
694+ . span_suggestion (
695+ span,
696+ "remove the super traits or lifetime bounds" ,
697+ String :: new ( ) ,
698+ Applicability :: MachineApplicable ,
699+ )
700+ . emit ( ) ;
701+ }
702+
686703 fn deny_super_traits ( & self , bounds : & GenericBounds , ident_span : Span ) {
687- if let [ first @ last] | [ first, .., last] = & bounds[ ..] {
688- let span = first. span ( ) . to ( last. span ( ) ) ;
689- struct_span_err ! ( self . session, span, E0568 , "auto traits cannot have super traits" )
690- . span_label ( ident_span, "auto trait cannot have super traits" )
691- . span_suggestion (
692- span,
693- "remove the super traits" ,
694- String :: new ( ) ,
695- Applicability :: MachineApplicable ,
696- )
697- . emit ( ) ;
704+ if let [ .., last] = & bounds[ ..] {
705+ let span = ident_span. shrink_to_hi ( ) . to ( last. span ( ) ) ;
706+ self . emit_e0568 ( span, ident_span) ;
707+ }
708+ }
709+
710+ fn deny_where_clause ( & self , where_clause : & WhereClause , ident_span : Span ) {
711+ if !where_clause. predicates . is_empty ( ) {
712+ self . emit_e0568 ( where_clause. span , ident_span) ;
698713 }
699714 }
700715
701716 fn deny_items ( & self , trait_items : & [ P < AssocItem > ] , ident_span : Span ) {
702717 if !trait_items. is_empty ( ) {
703718 let spans: Vec < _ > = trait_items. iter ( ) . map ( |i| i. ident . span ) . collect ( ) ;
719+ let total_span = trait_items. first ( ) . unwrap ( ) . span . to ( trait_items. last ( ) . unwrap ( ) . span ) ;
704720 struct_span_err ! (
705721 self . session,
706722 spans,
707723 E0380 ,
708- "auto traits cannot have methods or associated items"
724+ "auto traits cannot have associated items"
725+ )
726+ . span_suggestion (
727+ total_span,
728+ "remove these associated items" ,
729+ String :: new ( ) ,
730+ Applicability :: MachineApplicable ,
709731 )
710- . span_label ( ident_span, "auto trait cannot have items" )
732+ . span_label ( ident_span, "auto trait cannot have associated items" )
711733 . emit ( ) ;
712734 }
713735 }
@@ -1184,6 +1206,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11841206 // Auto traits cannot have generics, super traits nor contain items.
11851207 self . deny_generic_params ( generics, item. ident . span ) ;
11861208 self . deny_super_traits ( bounds, item. ident . span ) ;
1209+ self . deny_where_clause ( & generics. where_clause , item. ident . span ) ;
11871210 self . deny_items ( trait_items, item. ident . span ) ;
11881211 }
11891212 self . no_questions_in_bounds ( bounds, "supertraits" , true ) ;
0 commit comments