@@ -20,7 +20,7 @@ use rustc_session::lint::builtin::{
20
20
DEPRECATED_WHERE_CLAUSE_LOCATION , MISSING_ABI , PATTERNS_IN_FNS_WITHOUT_BODY ,
21
21
} ;
22
22
use rustc_session:: lint:: { BuiltinLintDiagnostics , LintBuffer } ;
23
- use rustc_session:: Session ;
23
+ use rustc_session:: { Session , SessionDiagnostic } ;
24
24
use rustc_span:: source_map:: Spanned ;
25
25
use rustc_span:: symbol:: { kw, sym, Ident } ;
26
26
use rustc_span:: Span ;
@@ -404,15 +404,16 @@ impl<'a> AstValidator<'a> {
404
404
}
405
405
}
406
406
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
+ {
408
411
let span = match bounds {
409
412
[ ] => return ,
410
413
[ b0] => b0. span ( ) ,
411
414
[ b0, .., bl] => b0. span ( ) . to ( bl. span ( ) ) ,
412
415
} ;
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) ) ;
416
417
}
417
418
418
419
fn check_foreign_ty_genericless ( & self , generics : & Generics , where_span : Span ) {
@@ -1205,7 +1206,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
1205
1206
replace_span : self . ending_semi_or_hi ( item. span ) ,
1206
1207
} ) ;
1207
1208
}
1208
- self . check_type_no_bounds ( bounds, "this context" ) ;
1209
+ self . check_type_no_bounds ( bounds, |span| TyAliasWithBound { span } ) ;
1209
1210
if where_clauses. 1 . 0 {
1210
1211
let mut err = self . err_handler ( ) . struct_span_err (
1211
1212
where_clauses. 1 . 1 ,
@@ -1241,7 +1242,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
1241
1242
} ) => {
1242
1243
self . check_defaultness ( fi. span , * defaultness) ;
1243
1244
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 } ) ;
1245
1246
self . check_foreign_ty_genericless ( generics, where_clauses. 0 . 1 ) ;
1246
1247
self . check_foreign_item_ascii_only ( fi. ident ) ;
1247
1248
}
@@ -1539,7 +1540,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
1539
1540
replace_span : self . ending_semi_or_hi ( item. span ) ,
1540
1541
} ) ;
1541
1542
}
1542
- self . check_type_no_bounds ( bounds, "`impl`s" ) ;
1543
+ self . check_type_no_bounds ( bounds, |span| ImplAssocTypeWithBound { span } ) ;
1543
1544
if ty. is_some ( ) {
1544
1545
self . check_gat_where (
1545
1546
item. id ,
0 commit comments