@@ -74,6 +74,23 @@ impl Sysroot {
7474 pub fn is_empty ( & self ) -> bool {
7575 self . crates . is_empty ( )
7676 }
77+
78+ pub fn loading_warning ( & self ) -> Option < String > {
79+ if self . by_name ( "core" ) . is_none ( ) {
80+ let var_note = if env:: var_os ( "RUST_SRC_PATH" ) . is_some ( ) {
81+ " (`RUST_SRC_PATH` might be incorrect, try unsetting it)"
82+ } else {
83+ " try running `rustup component add rust-src` to possible fix this"
84+ } ;
85+ Some ( format ! (
86+ "could not find libcore in loaded sysroot at `{}`{}" ,
87+ self . src_root. as_path( ) . display( ) ,
88+ var_note,
89+ ) )
90+ } else {
91+ None
92+ }
93+ }
7794}
7895
7996// FIXME: Expose a builder api as loading the sysroot got way too modular and complicated.
@@ -103,7 +120,7 @@ impl Sysroot {
103120
104121 pub fn with_sysroot_dir ( sysroot_dir : AbsPathBuf ) -> Result < Sysroot > {
105122 let sysroot_src_dir = discover_sysroot_src_dir ( & sysroot_dir) . ok_or_else ( || {
106- format_err ! ( "can't load standard library from sysroot {}" , sysroot_dir. display( ) )
123+ format_err ! ( "can't load standard library from sysroot path {}" , sysroot_dir. display( ) )
107124 } ) ?;
108125 Ok ( Sysroot :: load ( sysroot_dir, sysroot_src_dir) )
109126 }
@@ -153,19 +170,6 @@ impl Sysroot {
153170 }
154171 }
155172
156- if sysroot. by_name ( "core" ) . is_none ( ) {
157- let var_note = if env:: var_os ( "RUST_SRC_PATH" ) . is_some ( ) {
158- " (`RUST_SRC_PATH` might be incorrect, try unsetting it)"
159- } else {
160- ""
161- } ;
162- tracing:: error!(
163- "could not find libcore in sysroot path `{}`{}" ,
164- sysroot. src_root. as_path( ) . display( ) ,
165- var_note,
166- ) ;
167- }
168-
169173 sysroot
170174 }
171175
0 commit comments