@@ -20,7 +20,7 @@ use rustc_session::lint::builtin::{
2020 DEPRECATED_WHERE_CLAUSE_LOCATION , MISSING_ABI , PATTERNS_IN_FNS_WITHOUT_BODY ,
2121} ;
2222use rustc_session:: lint:: { BuiltinLintDiagnostics , LintBuffer } ;
23- use rustc_session:: Session ;
23+ use rustc_session:: { Session , SessionDiagnostic } ;
2424use rustc_span:: source_map:: Spanned ;
2525use rustc_span:: symbol:: { kw, sym, Ident } ;
2626use rustc_span:: Span ;
@@ -404,15 +404,16 @@ impl<'a> AstValidator<'a> {
404404 }
405405 }
406406
407- fn check_type_no_bounds ( & self , bounds : & [ GenericBound ] , ctx : & str ) {
407+ fn check_type_no_bounds < D > ( & self , bounds : & [ GenericBound ] , create_diag : impl FnOnce ( Span ) -> D )
408+ where
409+ D : SessionDiagnostic < ' a > ,
410+ {
408411 let span = match bounds {
409412 [ ] => return ,
410413 [ b0] => b0. span ( ) ,
411414 [ b0, .., bl] => b0. span ( ) . to ( bl. span ( ) ) ,
412415 } ;
413- self . err_handler ( )
414- . struct_span_err ( span, & format ! ( "bounds on `type`s in {} have no effect" , ctx) )
415- . emit ( ) ;
416+ self . session . emit_err ( create_diag ( span) ) ;
416417 }
417418
418419 fn check_foreign_ty_genericless ( & self , generics : & Generics , where_span : Span ) {
@@ -1205,7 +1206,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12051206 replace_span : self . ending_semi_or_hi ( item. span ) ,
12061207 } ) ;
12071208 }
1208- self . check_type_no_bounds ( bounds, "this context" ) ;
1209+ self . check_type_no_bounds ( bounds, |span| TyAliasWithBound { span } ) ;
12091210 if where_clauses. 1 . 0 {
12101211 let mut err = self . err_handler ( ) . struct_span_err (
12111212 where_clauses. 1 . 1 ,
@@ -1241,7 +1242,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12411242 } ) => {
12421243 self . check_defaultness ( fi. span , * defaultness) ;
12431244 self . check_foreign_kind_bodyless ( fi. ident , "type" , ty. as_ref ( ) . map ( |b| b. span ) ) ;
1244- self . check_type_no_bounds ( bounds, "`extern` blocks" ) ;
1245+ self . check_type_no_bounds ( bounds, |span| ForeignTypeWithBound { span } ) ;
12451246 self . check_foreign_ty_genericless ( generics, where_clauses. 0 . 1 ) ;
12461247 self . check_foreign_item_ascii_only ( fi. ident ) ;
12471248 }
@@ -1539,7 +1540,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
15391540 replace_span : self . ending_semi_or_hi ( item. span ) ,
15401541 } ) ;
15411542 }
1542- self . check_type_no_bounds ( bounds, "`impl`s" ) ;
1543+ self . check_type_no_bounds ( bounds, |span| ImplAssocTypeWithBound { span } ) ;
15431544 if ty. is_some ( ) {
15441545 self . check_gat_where (
15451546 item. id ,
0 commit comments