@@ -38,8 +38,8 @@ use std::ops::ControlFlow;
3838use std:: { cmp, fmt, mem} ;
3939
4040use errors:: {
41- FieldIsPrivate , FieldIsPrivateLabel , InPublicInterface , InPublicInterfaceTraits , ItemIsPrivate ,
42- UnnamedItemIsPrivate ,
41+ FieldIsPrivate , FieldIsPrivateLabel , FromPrivateDependencyInPublicInterface , InPublicInterface ,
42+ InPublicInterfaceTraits , ItemIsPrivate , PrivateInPublicLint , UnnamedItemIsPrivate ,
4343} ;
4444
4545////////////////////////////////////////////////////////////////////////////////
@@ -1716,19 +1716,14 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
17161716
17171717 fn check_def_id ( & mut self , def_id : DefId , kind : & str , descr : & dyn fmt:: Display ) -> bool {
17181718 if self . leaks_private_dep ( def_id) {
1719- self . tcx . struct_span_lint_hir (
1719+ self . tcx . emit_spanned_lint (
17201720 lint:: builtin:: EXPORTED_PRIVATE_DEPENDENCIES ,
17211721 self . tcx . hir ( ) . local_def_id_to_hir_id ( self . item_def_id ) ,
17221722 self . tcx . def_span ( self . item_def_id . to_def_id ( ) ) ,
1723- |lint| {
1724- lint. build ( & format ! (
1725- "{} `{}` from private dependency '{}' in public \
1726- interface",
1727- kind,
1728- descr,
1729- self . tcx. crate_name( def_id. krate)
1730- ) )
1731- . emit ( ) ;
1723+ FromPrivateDependencyInPublicInterface {
1724+ kind,
1725+ descr : descr. to_string ( ) ,
1726+ krate : self . tcx . crate_name ( def_id. krate ) ,
17321727 } ,
17331728 ) ;
17341729 }
@@ -1754,12 +1749,14 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
17541749 }
17551750 } ;
17561751 let span = self . tcx . def_span ( self . item_def_id . to_def_id ( ) ) ;
1752+ let descr = descr. to_string ( ) ;
17571753 if self . has_old_errors
17581754 || self . in_assoc_ty
17591755 || self . tcx . resolutions ( ( ) ) . has_pub_restricted
17601756 {
17611757 let descr = descr. to_string ( ) ;
1762- let vis_span = self . tcx . def_span ( def_id) ;
1758+ let vis_span =
1759+ self . tcx . sess . source_map ( ) . guess_head_span ( self . tcx . def_span ( def_id) ) ;
17631760 if kind == "trait" {
17641761 self . tcx . sess . emit_err ( InPublicInterfaceTraits {
17651762 span,
@@ -1778,19 +1775,11 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
17781775 } ) ;
17791776 }
17801777 } else {
1781- let err_code = if kind == "trait" { "E0445" } else { "E0446" } ;
1782- self . tcx . struct_span_lint_hir (
1778+ self . tcx . emit_spanned_lint (
17831779 lint:: builtin:: PRIVATE_IN_PUBLIC ,
17841780 hir_id,
17851781 span,
1786- |lint| {
1787- lint. build ( & format ! (
1788- "{} (error {})" ,
1789- format!( "{} {} `{}` in public interface" , vis_descr, kind, descr) ,
1790- err_code
1791- ) )
1792- . emit ( ) ;
1793- } ,
1782+ PrivateInPublicLint { vis_descr, kind, descr } ,
17941783 ) ;
17951784 }
17961785 }
0 commit comments