@@ -11,7 +11,6 @@ use rustc_ast::MacroDef;
11
11
use rustc_attr as attr;
12
12
use rustc_data_structures:: fx:: FxHashSet ;
13
13
use rustc_data_structures:: intern:: Interned ;
14
- use rustc_errors:: struct_span_err;
15
14
use rustc_hir as hir;
16
15
use rustc_hir:: def:: { DefKind , Res } ;
17
16
use rustc_hir:: def_id:: { DefId , LocalDefId , LocalDefIdSet , CRATE_DEF_ID } ;
@@ -36,7 +35,10 @@ use std::marker::PhantomData;
36
35
use std:: ops:: ControlFlow ;
37
36
use std:: { cmp, fmt, mem} ;
38
37
39
- use errors:: { FieldIsPrivate , FieldIsPrivateLabel , ItemIsPrivate , UnnamedItemIsPrivate } ;
38
+ use errors:: {
39
+ FieldIsPrivate , FieldIsPrivateLabel , InPublicInterface , InPublicInterfaceTraits , ItemIsPrivate ,
40
+ UnnamedItemIsPrivate ,
41
+ } ;
40
42
41
43
////////////////////////////////////////////////////////////////////////////////
42
44
/// Generic infrastructure used to implement specific visitors below.
@@ -1748,30 +1750,44 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
1748
1750
}
1749
1751
}
1750
1752
} ;
1751
- let make_msg = || format ! ( "{} {} `{}` in public interface" , vis_descr, kind, descr) ;
1752
1753
let span = self . tcx . def_span ( self . item_def_id . to_def_id ( ) ) ;
1753
1754
if self . has_old_errors
1754
1755
|| self . in_assoc_ty
1755
1756
|| self . tcx . resolutions ( ( ) ) . has_pub_restricted
1756
1757
{
1757
- let mut err = if kind == "trait" {
1758
- struct_span_err ! ( self . tcx. sess, span, E0445 , "{}" , make_msg( ) )
1759
- } else {
1760
- struct_span_err ! ( self . tcx. sess, span, E0446 , "{}" , make_msg( ) )
1761
- } ;
1758
+ let descr = descr. to_string ( ) ;
1762
1759
let vis_span =
1763
1760
self . tcx . sess . source_map ( ) . guess_head_span ( self . tcx . def_span ( def_id) ) ;
1764
- err. span_label ( span, format ! ( "can't leak {} {}" , vis_descr, kind) ) ;
1765
- err. span_label ( vis_span, format ! ( "`{}` declared as {}" , descr, vis_descr) ) ;
1766
- err. emit ( ) ;
1761
+ if kind == "trait" {
1762
+ self . tcx . sess . emit_err ( InPublicInterfaceTraits {
1763
+ span,
1764
+ vis_descr,
1765
+ kind,
1766
+ descr,
1767
+ vis_span,
1768
+ } ) ;
1769
+ } else {
1770
+ self . tcx . sess . emit_err ( InPublicInterface {
1771
+ span,
1772
+ vis_descr,
1773
+ kind,
1774
+ descr,
1775
+ vis_span,
1776
+ } ) ;
1777
+ }
1767
1778
} else {
1768
1779
let err_code = if kind == "trait" { "E0445" } else { "E0446" } ;
1769
1780
self . tcx . struct_span_lint_hir (
1770
1781
lint:: builtin:: PRIVATE_IN_PUBLIC ,
1771
1782
hir_id,
1772
1783
span,
1773
1784
|lint| {
1774
- lint. build ( & format ! ( "{} (error {})" , make_msg( ) , err_code) ) . emit ( ) ;
1785
+ lint. build ( & format ! (
1786
+ "{} (error {})" ,
1787
+ format!( "{} {} `{}` in public interface" , vis_descr, kind, descr) ,
1788
+ err_code
1789
+ ) )
1790
+ . emit ( ) ;
1775
1791
} ,
1776
1792
) ;
1777
1793
}
0 commit comments