@@ -11,7 +11,6 @@ use rustc_ast::MacroDef;
1111use rustc_attr as attr;
1212use rustc_data_structures:: fx:: FxHashSet ;
1313use rustc_data_structures:: intern:: Interned ;
14- use rustc_errors:: struct_span_err;
1514use rustc_hir as hir;
1615use rustc_hir:: def:: { DefKind , Res } ;
1716use rustc_hir:: def_id:: { DefId , LocalDefId , LocalDefIdSet , CRATE_DEF_ID } ;
@@ -36,7 +35,10 @@ use std::marker::PhantomData;
3635use std:: ops:: ControlFlow ;
3736use std:: { cmp, fmt, mem} ;
3837
39- use errors:: { FieldIsPrivate , FieldIsPrivateLabel , ItemIsPrivate , UnnamedItemIsPrivate } ;
38+ use errors:: {
39+ FieldIsPrivate , FieldIsPrivateLabel , InPublicInterface , InPublicInterfaceTraits , ItemIsPrivate ,
40+ UnnamedItemIsPrivate ,
41+ } ;
4042
4143////////////////////////////////////////////////////////////////////////////////
4244/// Generic infrastructure used to implement specific visitors below.
@@ -1748,30 +1750,44 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
17481750 }
17491751 }
17501752 } ;
1751- let make_msg = || format ! ( "{} {} `{}` in public interface" , vis_descr, kind, descr) ;
17521753 let span = self . tcx . def_span ( self . item_def_id . to_def_id ( ) ) ;
17531754 if self . has_old_errors
17541755 || self . in_assoc_ty
17551756 || self . tcx . resolutions ( ( ) ) . has_pub_restricted
17561757 {
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 ( ) ;
17621759 let vis_span =
17631760 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+ }
17671778 } else {
17681779 let err_code = if kind == "trait" { "E0445" } else { "E0446" } ;
17691780 self . tcx . struct_span_lint_hir (
17701781 lint:: builtin:: PRIVATE_IN_PUBLIC ,
17711782 hir_id,
17721783 span,
17731784 |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 ( ) ;
17751791 } ,
17761792 ) ;
17771793 }
0 commit comments