File tree 1 file changed +16
-2
lines changed
compiler/rustc_errors/src
1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,8 @@ use std::error::Report;
13
13
use std:: io:: prelude:: * ;
14
14
use std:: io:: { self , IsTerminal } ;
15
15
use std:: iter;
16
- use std:: path:: Path ;
16
+ use std:: path:: { Path , PathBuf } ;
17
+ use std:: process:: Command ;
17
18
use std:: sync:: Arc ;
18
19
19
20
use derive_setters:: Setters ;
@@ -3571,9 +3572,22 @@ fn is_external_library(sm: &SourceMap, span: Span) -> bool {
3571
3572
3572
3573
let registry_path = cargo_home. join ( "registry" ) . join ( "src" ) ;
3573
3574
let toolchain_path = rustup_home. join ( "toolchains" ) ;
3575
+ let sysroot = get_rustc_sysroot ( ) ;
3574
3576
3575
- path. starts_with ( & registry_path) || path. starts_with ( & toolchain_path)
3577
+ path. starts_with ( & registry_path)
3578
+ || path. starts_with ( & toolchain_path)
3579
+ || sysroot. as_ref ( ) . map_or ( false , |sr| path. starts_with ( sr) )
3576
3580
} else {
3577
3581
false
3578
3582
}
3579
3583
}
3584
+
3585
+ fn get_rustc_sysroot ( ) -> Option < PathBuf > {
3586
+ let rustc_path = std:: env:: var ( "RUSTC" ) . unwrap_or_else ( |_| "rustc" . to_string ( ) ) ;
3587
+ match Command :: new ( rustc_path) . arg ( "--print" ) . arg ( "sysroot" ) . output ( ) {
3588
+ Ok ( output) if output. status . success ( ) => {
3589
+ String :: from_utf8 ( output. stdout ) . ok ( ) . map ( |s| PathBuf :: from ( s. trim ( ) ) )
3590
+ }
3591
+ _ => None ,
3592
+ }
3593
+ }
You can’t perform that action at this time.
0 commit comments