@@ -160,7 +160,11 @@ impl<'tcx> Ty<'tcx> {
160160 _ => {
161161 let width = tcx. sess . diagnostic_width ( ) ;
162162 let length_limit = std:: cmp:: max ( width / 4 , 40 ) ;
163- format ! ( "`{}`" , tcx. string_with_limit( self , length_limit) ) . into ( )
163+ format ! (
164+ "`{}`" ,
165+ tcx. string_with_limit( self , length_limit, hir:: def:: Namespace :: TypeNS )
166+ )
167+ . into ( )
164168 }
165169 }
166170 }
@@ -213,12 +217,12 @@ impl<'tcx> Ty<'tcx> {
213217}
214218
215219impl < ' tcx > TyCtxt < ' tcx > {
216- pub fn string_with_limit < T > ( self , p : T , length_limit : usize ) -> String
220+ pub fn string_with_limit < T > ( self , p : T , length_limit : usize , ns : hir :: def :: Namespace ) -> String
217221 where
218222 T : Copy + for < ' a , ' b > Lift < TyCtxt < ' b > , Lifted : Print < ' b , FmtPrinter < ' a , ' b > > > ,
219223 {
220224 let mut type_limit = 50 ;
221- let regular = FmtPrinter :: print_string ( self , hir :: def :: Namespace :: TypeNS , |cx| {
225+ let regular = FmtPrinter :: print_string ( self , ns , |cx| {
222226 self . lift ( p) . expect ( "could not lift for printing" ) . print ( cx)
223227 } )
224228 . expect ( "could not write to `String`" ) ;
@@ -229,11 +233,7 @@ impl<'tcx> TyCtxt<'tcx> {
229233 loop {
230234 // Look for the longest properly trimmed path that still fits in length_limit.
231235 short = with_forced_trimmed_paths ! ( {
232- let mut cx = FmtPrinter :: new_with_limit(
233- self ,
234- hir:: def:: Namespace :: TypeNS ,
235- rustc_session:: Limit ( type_limit) ,
236- ) ;
236+ let mut cx = FmtPrinter :: new_with_limit( self , ns, rustc_session:: Limit ( type_limit) ) ;
237237 self . lift( p)
238238 . expect( "could not lift for printing" )
239239 . print( & mut cx)
@@ -248,15 +248,27 @@ impl<'tcx> TyCtxt<'tcx> {
248248 short
249249 }
250250
251+ pub fn short_string < T > ( self , p : T , path : & mut Option < PathBuf > ) -> String
252+ where
253+ T : Copy + Hash + for < ' a , ' b > Lift < TyCtxt < ' b > , Lifted : Print < ' b , FmtPrinter < ' a , ' b > > > ,
254+ {
255+ self . short_string_namespace ( p, path, hir:: def:: Namespace :: TypeNS )
256+ }
257+
251258 /// When calling this after a `Diag` is constructed, the preferred way of doing so is
252259 /// `tcx.short_string(ty, diag.long_ty_path())`. The diagnostic itself is the one that keeps
253260 /// the existence of a "long type" anywhere in the diagnostic, so the note telling the user
254261 /// where we wrote the file to is only printed once.
255- pub fn short_string < T > ( self , p : T , path : & mut Option < PathBuf > ) -> String
262+ pub fn short_string_namespace < T > (
263+ self ,
264+ p : T ,
265+ path : & mut Option < PathBuf > ,
266+ namespace : hir:: def:: Namespace ,
267+ ) -> String
256268 where
257269 T : Copy + Hash + for < ' a , ' b > Lift < TyCtxt < ' b > , Lifted : Print < ' b , FmtPrinter < ' a , ' b > > > ,
258270 {
259- let regular = FmtPrinter :: print_string ( self , hir :: def :: Namespace :: TypeNS , |cx| {
271+ let regular = FmtPrinter :: print_string ( self , namespace , |cx| {
260272 self . lift ( p) . expect ( "could not lift for printing" ) . print ( cx)
261273 } )
262274 . expect ( "could not write to `String`" ) ;
@@ -270,7 +282,7 @@ impl<'tcx> TyCtxt<'tcx> {
270282 if regular. len ( ) <= width * 2 / 3 {
271283 return regular;
272284 }
273- let short = self . string_with_limit ( p, length_limit) ;
285+ let short = self . string_with_limit ( p, length_limit, namespace ) ;
274286 if regular == short {
275287 return regular;
276288 }
0 commit comments