@@ -683,31 +683,53 @@ impl<'a> AstValidator<'a> {
683
683
}
684
684
}
685
685
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
+
686
703
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) ;
698
713
}
699
714
}
700
715
701
716
fn deny_items ( & self , trait_items : & [ P < AssocItem > ] , ident_span : Span ) {
702
717
if !trait_items. is_empty ( ) {
703
718
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 ) ;
704
720
struct_span_err ! (
705
721
self . session,
706
722
spans,
707
723
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 ,
709
731
)
710
- . span_label ( ident_span, "auto trait cannot have items" )
732
+ . span_label ( ident_span, "auto trait cannot have associated items" )
711
733
. emit ( ) ;
712
734
}
713
735
}
@@ -1184,6 +1206,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
1184
1206
// Auto traits cannot have generics, super traits nor contain items.
1185
1207
self . deny_generic_params ( generics, item. ident . span ) ;
1186
1208
self . deny_super_traits ( bounds, item. ident . span ) ;
1209
+ self . deny_where_clause ( & generics. where_clause , item. ident . span ) ;
1187
1210
self . deny_items ( trait_items, item. ident . span ) ;
1188
1211
}
1189
1212
self . no_questions_in_bounds ( bounds, "supertraits" , true ) ;
0 commit comments