@@ -2,12 +2,13 @@ use std::fmt::{self, Write};
2
2
use std:: mem:: { self , discriminant} ;
3
3
4
4
use rustc_data_structures:: stable_hasher:: { Hash64 , HashStable , StableHasher } ;
5
- use rustc_hir:: def_id:: CrateNum ;
5
+ use rustc_hir:: def_id:: { CrateNum , DefId } ;
6
6
use rustc_hir:: definitions:: { DefPathData , DisambiguatedDefPathData } ;
7
7
use rustc_middle:: bug;
8
8
use rustc_middle:: ty:: print:: { PrettyPrinter , Print , PrintError , Printer } ;
9
9
use rustc_middle:: ty:: {
10
10
self , GenericArg , GenericArgKind , Instance , ReifyReason , Ty , TyCtxt , TypeVisitableExt ,
11
+ TypingEnv ,
11
12
} ;
12
13
use tracing:: debug;
13
14
@@ -54,7 +55,12 @@ pub(super) fn mangle<'tcx>(
54
55
55
56
let hash = get_symbol_hash ( tcx, instance, instance_ty, instantiating_crate) ;
56
57
57
- let mut printer = SymbolPrinter { tcx, path : SymbolPath :: new ( ) , keep_within_component : false } ;
58
+ let mut printer = SymbolPrinter {
59
+ tcx,
60
+ path : SymbolPath :: new ( ) ,
61
+ keep_within_component : false ,
62
+ instance_def_id : ty_def_id,
63
+ } ;
58
64
printer
59
65
. print_def_path (
60
66
def_id,
@@ -204,6 +210,10 @@ struct SymbolPrinter<'tcx> {
204
210
tcx : TyCtxt < ' tcx > ,
205
211
path : SymbolPath ,
206
212
213
+ // The item currently being printed. Used to obtain a `TypingEnv`
214
+ // for evaluating constants in the signature.
215
+ instance_def_id : DefId ,
216
+
207
217
// When `true`, `finalize_pending_component` isn't used.
208
218
// This is needed when recursing into `path_qualified`,
209
219
// or `path_generic_args`, as any nested paths are
@@ -239,6 +249,13 @@ impl<'tcx> Printer<'tcx> for SymbolPrinter<'tcx> {
239
249
self . write_str ( "[" ) ?;
240
250
self . print_type ( ty) ?;
241
251
self . write_str ( "; " ) ?;
252
+ let size = self
253
+ . tcx
254
+ . try_normalize_erasing_regions (
255
+ TypingEnv :: non_body_analysis ( self . tcx , self . instance_def_id ) ,
256
+ size,
257
+ )
258
+ . unwrap_or ( size) ;
242
259
if let Some ( size) = size. try_to_target_usize ( self . tcx ( ) ) {
243
260
write ! ( self , "{size}" ) ?
244
261
} else if let ty:: ConstKind :: Param ( param) = size. kind ( ) {
@@ -272,6 +289,13 @@ impl<'tcx> Printer<'tcx> for SymbolPrinter<'tcx> {
272
289
}
273
290
274
291
fn print_const ( & mut self , ct : ty:: Const < ' tcx > ) -> Result < ( ) , PrintError > {
292
+ let ct = self
293
+ . tcx
294
+ . try_normalize_erasing_regions (
295
+ TypingEnv :: non_body_analysis ( self . tcx , self . instance_def_id ) ,
296
+ ct,
297
+ )
298
+ . unwrap_or ( ct) ;
275
299
// only print integers
276
300
match ct. kind ( ) {
277
301
ty:: ConstKind :: Value ( ty, ty:: ValTree :: Leaf ( scalar) ) if ty. is_integral ( ) => {
0 commit comments