Skip to content

Commit a053bae

Browse files
authored
Rollup merge of rust-lang#63559 - eddyb:v0-mangling-off-by-1, r=estebank
rustc_codegen_utils: account for 1-indexed anonymous lifetimes in v0 mangling. I don't really understand why `anonymize_late_bound_regions` starts with `BrAnon(1)` instead of `BrAnon(0)`, but it does (maybe @nikomatsakis knows?): https://github.com/rust-lang/rust/blob/c43d03a19f326f4a323569328cc501e86eb6d22e/src/librustc/ty/fold.rs#L696-L712 Thankfully, the mangling format and demangler implementations are fine, and I just needed to offset the anonymized lifetime indices by `1` to get the correct mangling. cc @alexcrichton @michaelwoerister
2 parents 5e59787 + c1758d5 commit a053bae

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

src/librustc_codegen_utils/symbol_names/v0.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,14 @@ impl SymbolMangler<'tcx> {
198198

199199
let lifetimes = regions.into_iter().map(|br| {
200200
match br {
201-
ty::BrAnon(i) => i + 1,
201+
ty::BrAnon(i) => {
202+
// FIXME(eddyb) for some reason, `anonymize_late_bound_regions` starts at `1`.
203+
assert_ne!(i, 0);
204+
i - 1
205+
},
202206
_ => bug!("symbol_names: non-anonymized region `{:?}` in `{:?}`", br, value),
203207
}
204-
}).max().unwrap_or(0);
208+
}).max().map_or(0, |max| max + 1);
205209

206210
self.push_opt_integer_62("G", lifetimes as u64);
207211
lifetime_depths.end += lifetimes;
@@ -297,6 +301,10 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
297301
// Late-bound lifetimes use indices starting at 1,
298302
// see `BinderLevel` for more details.
299303
ty::ReLateBound(debruijn, ty::BrAnon(i)) => {
304+
// FIXME(eddyb) for some reason, `anonymize_late_bound_regions` starts at `1`.
305+
assert_ne!(i, 0);
306+
let i = i - 1;
307+
300308
let binder = &self.binders[self.binders.len() - 1 - debruijn.index()];
301309
let depth = binder.lifetime_depths.start + i;
302310

src/test/ui/symbol-names/impl1.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ fn main() {
6464
//[legacy]~^ ERROR symbol-name(_ZN198_$LT$$u5b$$RF$dyn$u20$impl1..Foo$u2b$Assoc$u20$$u3d$$u20$extern$u20$$u22$C$u22$$u20$fn$LP$$RF$u8$RP$$u2b$impl1..AutoTrait$u3b$$u20$_$u5d$$u20$as$u20$impl1..main..$u7b$$u7b$closure$u7d$$u7d$..Bar$GT$6method
6565
//[legacy]~| ERROR demangling(<[&dyn impl1::Foo+Assoc = extern "C" fn(&u8)+impl1::AutoTrait; _] as impl1::main::{{closure}}::Bar>::method
6666
//[legacy]~| ERROR demangling-alt(<[&dyn impl1::Foo+Assoc = extern "C" fn(&u8)+impl1::AutoTrait; _] as impl1::main::{{closure}}::Bar>::method)
67-
//[v0]~^^^^ ERROR symbol-name(_RNvXNCNvCs4fqI2P2rA04_5impl14mains_0ARDNtB6_3Foop5AssocFG0_KCRL0_hEuNtB6_9AutoTraitEL_j3_NtB2_3Bar6method)
68-
//[v0]~| ERROR demangling(<[&dyn impl1[317d481089b8c8fe]::Foo<Assoc = for<'a, 'b> extern "C" fn(&'b u8)> + impl1[317d481089b8c8fe]::AutoTrait; 3: usize] as impl1[317d481089b8c8fe]::main::{closure#1}::Bar>::method)
69-
//[v0]~| ERROR demangling-alt(<[&dyn impl1::Foo<Assoc = for<'a, 'b> extern "C" fn(&'b u8)> + impl1::AutoTrait; 3] as impl1::main::{closure#1}::Bar>::method)
67+
//[v0]~^^^^ ERROR symbol-name(_RNvXNCNvCs4fqI2P2rA04_5impl14mains_0ARDNtB6_3Foop5AssocFG_KCRL0_hEuNtB6_9AutoTraitEL_j3_NtB2_3Bar6method)
68+
//[v0]~| ERROR demangling(<[&dyn impl1[317d481089b8c8fe]::Foo<Assoc = for<'a> extern "C" fn(&'a u8)> + impl1[317d481089b8c8fe]::AutoTrait; 3: usize] as impl1[317d481089b8c8fe]::main::{closure#1}::Bar>::method)
69+
//[v0]~| ERROR demangling-alt(<[&dyn impl1::Foo<Assoc = for<'a> extern "C" fn(&'a u8)> + impl1::AutoTrait; 3] as impl1::main::{closure#1}::Bar>::method)
7070
#[rustc_def_path]
7171
//[legacy]~^ ERROR def-path(<[&dyn Foo<Assoc = for<'r> extern "C" fn(&'r u8)> + AutoTrait; _] as main::{{closure}}#1::Bar>::method)
7272
//[v0]~^^ ERROR def-path(<[&dyn Foo<Assoc = for<'r> extern "C" fn(&'r u8)> + AutoTrait; _] as main::{{closure}}#1::Bar>::method)

src/test/ui/symbol-names/impl1.v0.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,19 @@ error: def-path(bar::<impl foo::Foo>::baz)
4646
LL | #[rustc_def_path]
4747
| ^^^^^^^^^^^^^^^^^
4848

49-
error: symbol-name(_RNvXNCNvCs4fqI2P2rA04_5impl14mains_0ARDNtB6_3Foop5AssocFG0_KCRL0_hEuNtB6_9AutoTraitEL_j3_NtB2_3Bar6method)
49+
error: symbol-name(_RNvXNCNvCs4fqI2P2rA04_5impl14mains_0ARDNtB6_3Foop5AssocFG_KCRL0_hEuNtB6_9AutoTraitEL_j3_NtB2_3Bar6method)
5050
--> $DIR/impl1.rs:63:13
5151
|
5252
LL | #[rustc_symbol_name]
5353
| ^^^^^^^^^^^^^^^^^^^^
5454

55-
error: demangling(<[&dyn impl1[317d481089b8c8fe]::Foo<Assoc = for<'a, 'b> extern "C" fn(&'b u8)> + impl1[317d481089b8c8fe]::AutoTrait; 3: usize] as impl1[317d481089b8c8fe]::main::{closure#1}::Bar>::method)
55+
error: demangling(<[&dyn impl1[317d481089b8c8fe]::Foo<Assoc = for<'a> extern "C" fn(&'a u8)> + impl1[317d481089b8c8fe]::AutoTrait; 3: usize] as impl1[317d481089b8c8fe]::main::{closure#1}::Bar>::method)
5656
--> $DIR/impl1.rs:63:13
5757
|
5858
LL | #[rustc_symbol_name]
5959
| ^^^^^^^^^^^^^^^^^^^^
6060

61-
error: demangling-alt(<[&dyn impl1::Foo<Assoc = for<'a, 'b> extern "C" fn(&'b u8)> + impl1::AutoTrait; 3] as impl1::main::{closure#1}::Bar>::method)
61+
error: demangling-alt(<[&dyn impl1::Foo<Assoc = for<'a> extern "C" fn(&'a u8)> + impl1::AutoTrait; 3] as impl1::main::{closure#1}::Bar>::method)
6262
--> $DIR/impl1.rs:63:13
6363
|
6464
LL | #[rustc_symbol_name]

0 commit comments

Comments
 (0)