@@ -38,8 +38,8 @@ use std::ops::ControlFlow;
38
38
use std:: { cmp, fmt, mem} ;
39
39
40
40
use errors:: {
41
- FieldIsPrivate , FieldIsPrivateLabel , InPublicInterface , InPublicInterfaceTraits , ItemIsPrivate ,
42
- UnnamedItemIsPrivate ,
41
+ FieldIsPrivate , FieldIsPrivateLabel , FromPrivateDependencyInPublicInterface , InPublicInterface ,
42
+ InPublicInterfaceTraits , ItemIsPrivate , PrivateInPublicLint , UnnamedItemIsPrivate ,
43
43
} ;
44
44
45
45
////////////////////////////////////////////////////////////////////////////////
@@ -1716,19 +1716,14 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
1716
1716
1717
1717
fn check_def_id ( & mut self , def_id : DefId , kind : & str , descr : & dyn fmt:: Display ) -> bool {
1718
1718
if self . leaks_private_dep ( def_id) {
1719
- self . tcx . struct_span_lint_hir (
1719
+ self . tcx . emit_spanned_lint (
1720
1720
lint:: builtin:: EXPORTED_PRIVATE_DEPENDENCIES ,
1721
1721
self . tcx . hir ( ) . local_def_id_to_hir_id ( self . item_def_id ) ,
1722
1722
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 ) ,
1732
1727
} ,
1733
1728
) ;
1734
1729
}
@@ -1754,12 +1749,14 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
1754
1749
}
1755
1750
} ;
1756
1751
let span = self . tcx . def_span ( self . item_def_id . to_def_id ( ) ) ;
1752
+ let descr = descr. to_string ( ) ;
1757
1753
if self . has_old_errors
1758
1754
|| self . in_assoc_ty
1759
1755
|| self . tcx . resolutions ( ( ) ) . has_pub_restricted
1760
1756
{
1761
1757
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) ) ;
1763
1760
if kind == "trait" {
1764
1761
self . tcx . sess . emit_err ( InPublicInterfaceTraits {
1765
1762
span,
@@ -1778,19 +1775,11 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
1778
1775
} ) ;
1779
1776
}
1780
1777
} else {
1781
- let err_code = if kind == "trait" { "E0445" } else { "E0446" } ;
1782
- self . tcx . struct_span_lint_hir (
1778
+ self . tcx . emit_spanned_lint (
1783
1779
lint:: builtin:: PRIVATE_IN_PUBLIC ,
1784
1780
hir_id,
1785
1781
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 } ,
1794
1783
) ;
1795
1784
}
1796
1785
}
0 commit comments