@@ -126,12 +126,12 @@ impl Borrow<Fingerprint> for DefPathHash {
126
126
}
127
127
}
128
128
129
- /// A [StableCrateId] is a 64 bit hash of the crate name combined with all
130
- /// `-Cmetadata` arguments. It is to [CrateNum] what [DefPathHash] is to
131
- /// [DefId]. It is stable across compilation sessions.
129
+ /// A [` StableCrateId` ] is a 64 bit hash of the crate name combined with all
130
+ /// `-Cmetadata` arguments. It is to [` CrateNum` ] what [` DefPathHash` ] is to
131
+ /// [` DefId` ]. It is stable across compilation sessions.
132
132
///
133
133
/// Since the ID is a hash value there is a (very small) chance that two crates
134
- /// end up with the same [StableCrateId]. The compiler will check for such
134
+ /// end up with the same [` StableCrateId` ]. The compiler will check for such
135
135
/// collisions when loading crates and abort compilation in order to avoid
136
136
/// further trouble.
137
137
#[ derive( Copy , Clone , Hash , PartialEq , Eq , PartialOrd , Ord , Debug ) ]
@@ -152,7 +152,7 @@ impl StableCrateId {
152
152
let mut hasher = StableHasher :: new ( ) ;
153
153
crate_name. hash ( & mut hasher) ;
154
154
155
- // We don't want the stable crate id to dependent on the order
155
+ // We don't want the stable crate ID to depend on the order of
156
156
// -C metadata arguments, so sort them:
157
157
metadata. sort ( ) ;
158
158
// Every distinct -C metadata value is only incorporated once:
@@ -171,6 +171,12 @@ impl StableCrateId {
171
171
// linking against a library of the same name, if this is an executable.
172
172
hasher. write ( if is_exe { b"exe" } else { b"lib" } ) ;
173
173
174
+ // Also incorporate the rustc version. Otherwise, with -Zsymbol-mangling-version=v0
175
+ // and no -Cmetadata, symbols from the same crate compiled with different versions of
176
+ // rustc are named the same.
177
+ let rustc_version = option_env ! ( "CFG_VERSION" ) . unwrap_or ( "unknown version" ) . as_bytes ( ) ;
178
+ hasher. write ( rustc_version) ;
179
+
174
180
StableCrateId ( hasher. finish ( ) )
175
181
}
176
182
}
0 commit comments