Skip to content

Commit 2075316

Browse files
committed
Include InstanceDef's discriminant in the symbol hash.
1 parent 609cc26 commit 2075316

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/librustc_codegen_utils/symbol_names.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ use rustc_mir::monomorphize::Instance;
114114
use syntax_pos::symbol::Symbol;
115115

116116
use std::fmt::Write;
117+
use std::mem::discriminant;
117118

118119
pub fn provide(providers: &mut Providers) {
119120
*providers = Providers {
@@ -220,8 +221,9 @@ fn get_symbol_hash<'a, 'tcx>(
220221
(&tcx.crate_disambiguator(instantiating_crate)).hash_stable(&mut hcx, &mut hasher);
221222
}
222223

223-
let is_vtable_shim = instance.is_vtable_shim();
224-
is_vtable_shim.hash_stable(&mut hcx, &mut hasher);
224+
// We want to avoid accidental collision between different types of instances.
225+
// Especially, VtableShim may overlap with its original instance without this.
226+
discriminant(&instance.def).hash_stable(&mut hcx, &mut hasher);
225227
});
226228

227229
// 64 bits should be enough to avoid collisions.

src/test/ui/symbol-names/basic.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: symbol-name(_ZN5basic4main17h6ab1850bb0b9f417E)
1+
error: symbol-name(_ZN5basic4main17h08bcaf310214ed52E)
22
--> $DIR/basic.rs:13:1
33
|
44
LL | #[rustc_symbol_name] //~ ERROR _ZN5basic4main

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: symbol-name(_ZN5impl13foo3Foo3bar17h99c48478d64a0eb0E)
1+
error: symbol-name(_ZN5impl13foo3Foo3bar17hc487d6ec13fe9124E)
22
--> $DIR/impl1.rs:18:9
33
|
44
LL | #[rustc_symbol_name] //~ ERROR _ZN5impl13foo3Foo3bar
@@ -10,7 +10,7 @@ error: item-path(foo::Foo::bar)
1010
LL | #[rustc_item_path] //~ ERROR item-path(foo::Foo::bar)
1111
| ^^^^^^^^^^^^^^^^^^
1212

13-
error: symbol-name(_ZN5impl13bar33_$LT$impl$u20$impl1..foo..Foo$GT$3baz17hebf13830acf865d9E)
13+
error: symbol-name(_ZN5impl13bar33_$LT$impl$u20$impl1..foo..Foo$GT$3baz17h38577281258e1527E)
1414
--> $DIR/impl1.rs:28:9
1515
|
1616
LL | #[rustc_symbol_name] //~ ERROR _ZN5impl13bar33_$LT$impl$u20$impl1..foo..Foo$GT$3baz

0 commit comments

Comments
 (0)