@@ -241,7 +241,6 @@ use tracing::{debug, info};
241
241
crate struct CrateLocator < ' a > {
242
242
// Immutable per-session configuration.
243
243
only_needs_metadata : bool ,
244
- sysroot : & ' a Path ,
245
244
metadata_loader : & ' a dyn MetadataLoader ,
246
245
247
246
// Immutable per-search configuration.
@@ -308,7 +307,6 @@ impl<'a> CrateLocator<'a> {
308
307
309
308
CrateLocator {
310
309
only_needs_metadata,
311
- sysroot : & sess. sysroot ,
312
310
metadata_loader,
313
311
crate_name,
314
312
exact_paths : if hash. is_none ( ) {
@@ -547,6 +545,20 @@ impl<'a> CrateLocator<'a> {
547
545
continue ;
548
546
}
549
547
}
548
+ Err ( MetadataError :: VersionMismatch ( found_version) ) => {
549
+ // The file was present and created by the same compiler version, but we
550
+ // couldn't load it for some reason. Give a hard error instead of silently
551
+ // ignoring it, but only if we would have given an error anyway.
552
+ let rustc_version = rustc_version ( ) ;
553
+ info ! (
554
+ "Rejecting via version: expected {} got {}" ,
555
+ rustc_version, found_version
556
+ ) ;
557
+ self . crate_rejections
558
+ . via_version
559
+ . push ( CrateMismatch { path : lib, got : found_version } ) ;
560
+ continue ;
561
+ }
550
562
Err ( MetadataError :: LoadFailure ( err) ) => {
551
563
info ! ( "no metadata found: {}" , err) ;
552
564
// The file was present and created by the same compiler version, but we
@@ -591,16 +603,6 @@ impl<'a> CrateLocator<'a> {
591
603
}
592
604
593
605
fn crate_matches ( & mut self , metadata : & MetadataBlob , libpath : & Path ) -> Option < Svh > {
594
- let rustc_version = rustc_version ( ) ;
595
- let found_version = metadata. get_rustc_version ( ) ;
596
- if found_version != rustc_version {
597
- info ! ( "Rejecting via version: expected {} got {}" , rustc_version, found_version) ;
598
- self . crate_rejections
599
- . via_version
600
- . push ( CrateMismatch { path : libpath. to_path_buf ( ) , got : found_version } ) ;
601
- return None ;
602
- }
603
-
604
606
let root = metadata. get_root ( ) ;
605
607
if root. is_proc_macro_crate ( ) != self . is_proc_macro {
606
608
info ! (
@@ -742,13 +744,9 @@ fn get_metadata_section<'p>(
742
744
}
743
745
} ;
744
746
let blob = MetadataBlob :: new ( raw_bytes) ;
745
- if blob. is_compatible ( ) {
746
- Ok ( blob)
747
- } else {
748
- Err ( MetadataError :: LoadFailure ( format ! (
749
- "invalid metadata version found: {}" ,
750
- filename. display( )
751
- ) ) )
747
+ match blob. check_compatibility ( ) {
748
+ Ok ( ( ) ) => Ok ( blob) ,
749
+ Err ( version) => Err ( MetadataError :: VersionMismatch ( version) ) ,
752
750
}
753
751
}
754
752
@@ -862,6 +860,8 @@ enum MetadataError<'a> {
862
860
NotPresent ( & ' a Path ) ,
863
861
/// The file was present and invalid.
864
862
LoadFailure ( String ) ,
863
+ /// The file was present, but compiled with a different rustc version.
864
+ VersionMismatch ( String ) ,
865
865
}
866
866
867
867
impl fmt:: Display for MetadataError < ' _ > {
@@ -871,6 +871,11 @@ impl fmt::Display for MetadataError<'_> {
871
871
f. write_str ( & format ! ( "no such file: '{}'" , filename. display( ) ) )
872
872
}
873
873
MetadataError :: LoadFailure ( msg) => f. write_str ( msg) ,
874
+ MetadataError :: VersionMismatch ( found_version) => f. write_str ( & format ! (
875
+ "rustc version mismatch. expected {}, found {}" ,
876
+ rustc_version( ) ,
877
+ found_version,
878
+ ) ) ,
874
879
}
875
880
}
876
881
}
0 commit comments