@@ -54,13 +54,24 @@ impl Sysroot {
54
54
let src = get_or_install_rust_src ( cargo_toml) ?;
55
55
let mut sysroot = Sysroot { crates : Arena :: default ( ) } ;
56
56
for name in SYSROOT_CRATES . trim ( ) . lines ( ) {
57
+ // FIXME: remove this path when 1.47 comes out
58
+ // https://github.com/rust-lang/rust/pull/73265
57
59
let root = src. join ( format ! ( "lib{}" , name) ) . join ( "lib.rs" ) ;
58
60
if root. exists ( ) {
59
61
sysroot. crates . alloc ( SysrootCrateData {
60
62
name : name. into ( ) ,
61
63
root,
62
64
deps : Vec :: new ( ) ,
63
65
} ) ;
66
+ } else {
67
+ let root = src. join ( name) . join ( "src/lib.rs" ) ;
68
+ if root. exists ( ) {
69
+ sysroot. crates . alloc ( SysrootCrateData {
70
+ name : name. into ( ) ,
71
+ root,
72
+ deps : Vec :: new ( ) ,
73
+ } ) ;
74
+ }
64
75
}
65
76
}
66
77
if let Some ( std) = sysroot. std ( ) {
@@ -94,23 +105,38 @@ fn get_or_install_rust_src(cargo_toml: &AbsPath) -> Result<AbsPathBuf> {
94
105
rustc. current_dir ( current_dir) . args ( & [ "--print" , "sysroot" ] ) ;
95
106
let stdout = utf8_stdout ( rustc) ?;
96
107
let sysroot_path = AbsPath :: assert ( Path :: new ( stdout. trim ( ) ) ) ;
97
- let src_path = sysroot_path. join ( "lib/rustlib/src/rust/src" ) ;
98
-
99
- if !src_path. exists ( ) {
108
+ let mut src = get_rust_src ( sysroot_path) ;
109
+ if src. is_none ( ) {
100
110
let mut rustup = Command :: new ( ra_toolchain:: rustup ( ) ) ;
101
111
rustup. current_dir ( current_dir) . args ( & [ "component" , "add" , "rust-src" ] ) ;
102
112
utf8_stdout ( rustup) ?;
113
+ src = get_rust_src ( sysroot_path) ;
103
114
}
104
- if !src_path. exists ( ) {
105
- bail ! (
115
+ match src {
116
+ Some ( r) => Ok ( r) ,
117
+ None => bail ! (
106
118
"can't load standard library from sysroot\n \
107
119
{}\n \
108
120
(discovered via `rustc --print sysroot`)\n \
109
121
try running `rustup component add rust-src` or set `RUST_SRC_PATH`",
110
- src_path. display( ) ,
111
- )
122
+ sysroot_path. display( ) ,
123
+ ) ,
124
+ }
125
+ }
126
+
127
+ fn get_rust_src ( sysroot_path : & AbsPath ) -> Option < AbsPathBuf > {
128
+ // try the new path first since the old one still exists
129
+ let mut src_path = sysroot_path. join ( "lib/rustlib/src/rust/library" ) ;
130
+ if !src_path. exists ( ) {
131
+ // FIXME: remove this path when 1.47 comes out
132
+ // https://github.com/rust-lang/rust/pull/73265
133
+ src_path = sysroot_path. join ( "lib/rustlib/src/rust/src" ) ;
134
+ }
135
+ if src_path. exists ( ) {
136
+ Some ( src_path)
137
+ } else {
138
+ None
112
139
}
113
- Ok ( src_path)
114
140
}
115
141
116
142
impl SysrootCrateData {
0 commit comments