File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed
compiler/rustc_errors/src Expand file tree Collapse file tree 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;
1313use std:: io:: prelude:: * ;
1414use std:: io:: { self , IsTerminal } ;
1515use std:: iter;
16- use std:: path:: Path ;
16+ use std:: path:: { Path , PathBuf } ;
17+ use std:: process:: Command ;
1718use std:: sync:: Arc ;
1819
1920use derive_setters:: Setters ;
@@ -3571,9 +3572,22 @@ fn is_external_library(sm: &SourceMap, span: Span) -> bool {
35713572
35723573 let registry_path = cargo_home. join ( "registry" ) . join ( "src" ) ;
35733574 let toolchain_path = rustup_home. join ( "toolchains" ) ;
3575+ let sysroot = get_rustc_sysroot ( ) ;
35743576
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) )
35763580 } else {
35773581 false
35783582 }
35793583}
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