File tree Expand file tree Collapse file tree 1 file changed +29
-2
lines changed
compiler/rustc_errors/src Expand file tree Collapse file tree 1 file changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -3544,8 +3544,35 @@ pub(crate) fn should_show_source_code(
35443544fn is_external_library ( sm : & SourceMap , span : Span ) -> bool {
35453545 let filename = sm. span_to_filename ( span) ;
35463546 if let Some ( path) = filename. into_local_path ( ) {
3547- path. to_string_lossy ( ) . contains ( ".cargo/registry/src/" )
3548- || path. to_string_lossy ( ) . contains ( ".rustup/toolchains/" )
3547+ // use env variable to get path, avoid hardcode
3548+ // use platform independent path
3549+
3550+ let cargo_home = match std:: env:: var ( "CARGO_HOME" ) {
3551+ Ok ( dir) => std:: path:: PathBuf :: from ( dir) ,
3552+ Err ( _) => {
3553+ if let Ok ( home) = std:: env:: var ( "HOME" ) {
3554+ std:: path:: PathBuf :: from ( home) . join ( ".cargo" )
3555+ } else {
3556+ return false ;
3557+ }
3558+ }
3559+ } ;
3560+
3561+ let rustup_home = match std:: env:: var ( "RUSTUP_HOME" ) {
3562+ Ok ( dir) => std:: path:: PathBuf :: from ( dir) ,
3563+ Err ( _) => {
3564+ if let Ok ( home) = std:: env:: var ( "HOME" ) {
3565+ std:: path:: PathBuf :: from ( home) . join ( ".rustup" )
3566+ } else {
3567+ return false ;
3568+ }
3569+ }
3570+ } ;
3571+
3572+ let registry_path = cargo_home. join ( "registry" ) . join ( "src" ) ;
3573+ let toolchain_path = rustup_home. join ( "toolchains" ) ;
3574+
3575+ path. starts_with ( & registry_path) || path. starts_with ( & toolchain_path)
35493576 } else {
35503577 false
35513578 }
You can’t perform that action at this time.
0 commit comments