Skip to content

Commit 03e328d

Browse files
authored
Rollup merge of rust-lang#134081 - oli-obk:push-prpsqxxynxnq, r=BoxyUwU
Try to evaluate constants in legacy mangling Best reviewed commit by commit. It seems kind of odd to treat literals differently from unevaluated free constants. So let's evaluate those constants and only fall back to `_` rendering if that fails to result in an integral constant
2 parents 8abb823 + 9ecdc54 commit 03e328d

File tree

5 files changed

+96
-4
lines changed

5 files changed

+96
-4
lines changed

compiler/rustc_symbol_mangling/src/legacy.rs

+28-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::fmt::{self, Write};
22
use std::mem::{self, discriminant};
33

44
use rustc_data_structures::stable_hasher::{Hash64, HashStable, StableHasher};
5-
use rustc_hir::def_id::CrateNum;
5+
use rustc_hir::def_id::{CrateNum, DefId};
66
use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
77
use rustc_middle::bug;
88
use rustc_middle::ty::print::{PrettyPrinter, Print, PrintError, Printer};
@@ -378,6 +378,33 @@ impl<'tcx> Printer<'tcx> for SymbolPrinter<'tcx> {
378378
Ok(())
379379
}
380380
}
381+
382+
fn print_impl_path(
383+
&mut self,
384+
impl_def_id: DefId,
385+
args: &'tcx [GenericArg<'tcx>],
386+
mut self_ty: Ty<'tcx>,
387+
mut impl_trait_ref: Option<ty::TraitRef<'tcx>>,
388+
) -> Result<(), PrintError> {
389+
let mut typing_env = ty::TypingEnv::post_analysis(self.tcx, impl_def_id);
390+
if !args.is_empty() {
391+
typing_env.param_env =
392+
ty::EarlyBinder::bind(typing_env.param_env).instantiate(self.tcx, args);
393+
}
394+
395+
match &mut impl_trait_ref {
396+
Some(impl_trait_ref) => {
397+
assert_eq!(impl_trait_ref.self_ty(), self_ty);
398+
*impl_trait_ref = self.tcx.normalize_erasing_regions(typing_env, *impl_trait_ref);
399+
self_ty = impl_trait_ref.self_ty();
400+
}
401+
None => {
402+
self_ty = self.tcx.normalize_erasing_regions(typing_env, self_ty);
403+
}
404+
}
405+
406+
self.default_print_impl_path(impl_def_id, args, self_ty, impl_trait_ref)
407+
}
381408
}
382409

383410
impl<'tcx> PrettyPrinter<'tcx> for SymbolPrinter<'tcx> {

tests/ui/symbol-names/types.legacy.stderr

+19-1
Original file line numberDiff line numberDiff line change
@@ -502,5 +502,23 @@ error: demangling-alt(a::b::Type<[T; N]>)
502502
LL | #[rustc_symbol_name]
503503
| ^^^^^^^^^^^^^^^^^^^^
504504

505-
error: aborting due to 84 previous errors
505+
error: symbol-name(_ZN1a1b35Type$LT$$u5b$u8$u3b$$u20$0$u5d$$GT$17h[HASH]E)
506+
--> $DIR/types.rs:272:5
507+
|
508+
LL | #[rustc_symbol_name]
509+
| ^^^^^^^^^^^^^^^^^^^^
510+
511+
error: demangling(a::b::Type<[u8; 0]>::h[HASH])
512+
--> $DIR/types.rs:272:5
513+
|
514+
LL | #[rustc_symbol_name]
515+
| ^^^^^^^^^^^^^^^^^^^^
516+
517+
error: demangling-alt(a::b::Type<[u8; 0]>)
518+
--> $DIR/types.rs:272:5
519+
|
520+
LL | #[rustc_symbol_name]
521+
| ^^^^^^^^^^^^^^^^^^^^
522+
523+
error: aborting due to 87 previous errors
506524

tests/ui/symbol-names/types.rs

+11
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,17 @@ pub fn b() {
266266
//[v0]~| ERROR ::b::Type<[_; _]>>)
267267
//[v0]~| ERROR demangling-alt(<a::b::Type<[_; _]>>)
268268
impl<const N: usize, T> Type<[T; N]> {}
269+
270+
const ZERO: usize = 0;
271+
272+
#[rustc_symbol_name]
273+
//[legacy,verbose-legacy]~^ ERROR symbol-name(_ZN1a1b35Type$LT$$u5b$u8$u3b$$u20$0$u5d$$GT$
274+
//[legacy,verbose-legacy]~| ERROR demangling(a::b::Type<[u8; 0]>::
275+
//[legacy,verbose-legacy]~| ERROR demangling-alt(a::b::Type<[u8; 0]>)
276+
//[v0]~^^^^ ERROR symbol-name(_RMsq_NvCsCRATE_HASH_1a1bINtB<REF>_4TypeAhj0_E)
277+
//[v0]~| ERROR ::b::Type<[u8; 0usize]>>)
278+
//[v0]~| ERROR demangling-alt(<a::b::Type<[u8; 0]>>)
279+
impl Type<[u8; ZERO]> {}
269280
}
270281

271282
fn main() {}

tests/ui/symbol-names/types.v0.stderr

+19-1
Original file line numberDiff line numberDiff line change
@@ -502,5 +502,23 @@ error: demangling-alt(<a::b::Type<[_; _]>>)
502502
LL | #[rustc_symbol_name]
503503
| ^^^^^^^^^^^^^^^^^^^^
504504

505-
error: aborting due to 84 previous errors
505+
error: symbol-name(_RMsq_NvCsCRATE_HASH_1a1bINtB<REF>_4TypeAhj0_E)
506+
--> $DIR/types.rs:272:5
507+
|
508+
LL | #[rustc_symbol_name]
509+
| ^^^^^^^^^^^^^^^^^^^^
510+
511+
error: demangling(<a[HASH]::b::Type<[u8; 0usize]>>)
512+
--> $DIR/types.rs:272:5
513+
|
514+
LL | #[rustc_symbol_name]
515+
| ^^^^^^^^^^^^^^^^^^^^
516+
517+
error: demangling-alt(<a::b::Type<[u8; 0]>>)
518+
--> $DIR/types.rs:272:5
519+
|
520+
LL | #[rustc_symbol_name]
521+
| ^^^^^^^^^^^^^^^^^^^^
522+
523+
error: aborting due to 87 previous errors
506524

tests/ui/symbol-names/types.verbose-legacy.stderr

+19-1
Original file line numberDiff line numberDiff line change
@@ -502,5 +502,23 @@ error: demangling-alt(a::b::Type<[T; N]>)
502502
LL | #[rustc_symbol_name]
503503
| ^^^^^^^^^^^^^^^^^^^^
504504

505-
error: aborting due to 84 previous errors
505+
error: symbol-name(_ZN1a1b35Type$LT$$u5b$u8$u3b$$u20$0$u5d$$GT$17h[HASH]E)
506+
--> $DIR/types.rs:272:5
507+
|
508+
LL | #[rustc_symbol_name]
509+
| ^^^^^^^^^^^^^^^^^^^^
510+
511+
error: demangling(a::b::Type<[u8; 0]>::h[HASH])
512+
--> $DIR/types.rs:272:5
513+
|
514+
LL | #[rustc_symbol_name]
515+
| ^^^^^^^^^^^^^^^^^^^^
516+
517+
error: demangling-alt(a::b::Type<[u8; 0]>)
518+
--> $DIR/types.rs:272:5
519+
|
520+
LL | #[rustc_symbol_name]
521+
| ^^^^^^^^^^^^^^^^^^^^
522+
523+
error: aborting due to 87 previous errors
506524

0 commit comments

Comments
 (0)