@@ -126,12 +126,12 @@ impl Borrow<Fingerprint> for DefPathHash {
126126 }
127127}
128128
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.
132132///
133133/// 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
135135/// collisions when loading crates and abort compilation in order to avoid
136136/// further trouble.
137137#[ derive( Copy , Clone , Hash , PartialEq , Eq , PartialOrd , Ord , Debug ) ]
@@ -152,7 +152,7 @@ impl StableCrateId {
152152 let mut hasher = StableHasher :: new ( ) ;
153153 crate_name. hash ( & mut hasher) ;
154154
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
156156 // -C metadata arguments, so sort them:
157157 metadata. sort ( ) ;
158158 // Every distinct -C metadata value is only incorporated once:
@@ -171,6 +171,12 @@ impl StableCrateId {
171171 // linking against a library of the same name, if this is an executable.
172172 hasher. write ( if is_exe { b"exe" } else { b"lib" } ) ;
173173
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+
174180 StableCrateId ( hasher. finish ( ) )
175181 }
176182}
0 commit comments