Commit 7f6858f
committed
feat: introduce
Since the commit 5038446
("Rewrite method resolution to follow rustc more closely"), the method
resolution logic has changed: rust-analyzer only looks up inherent
methods for primitive types in sysroot crates.
Unfortunately, this change broke at least one project that relies on
`rust-project.json`: Rust-for-Linux. Its auto-generated
`rust-project.json` directly embeds `core`, `alloc`, and `std` in the
`crates` list without defining `sysroot_src`. Consequently,
rust-analyzer fails to identify them as sysroot crates, breaking IDE
support for primitive methods (e.g., `0_i32.rotate_left(0)`).
However, specifying `sysroot_src` creates a new issue: it implicitly
adds `std` as a dependency to all kernel module crates, which are
actually compiled with `-Zcrate-attr=no_std`. Since rust-analyzer cannot
see compiler flags passed outside of the project definition, we need a
method to explicitly specify `#![no_std]` or, more generally,
crate-level attributes through the project configuration.
To resolve this, extend the `rust-project.json` format with a new
`crate_attrs` field. This allows users to specify crate-level attributes
such as `#![no_std]` directly into the configuration, enabling
rust-analyzer to respect them when analyzing crates.
References:
- The original Zulip discussion:
https://rust-lang.zulipchat.com/#narrow/channel/185405-t-compiler.2Frust-analyzer/topic/Primitive.20type.20inherent.20method.20lookup.20fails/with/562983853crate_attrs field in rust-project.json
1 parent efdb3de commit 7f6858f
File tree
26 files changed
+473
-41
lines changed- crates
- base-db/src
- hir-def/src
- item_tree
- nameres
- tests
- hir/src
- ide-diagnostics/src
- handlers
- ide/src
- doc_links
- project-model
- src
- test_data
- output
- test-fixture/src
- test-utils/src
- docs/book/src
26 files changed
+473
-41
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
351 | 351 | | |
352 | 352 | | |
353 | 353 | | |
| 354 | + | |
| 355 | + | |
354 | 356 | | |
355 | 357 | | |
356 | 358 | | |
| |||
530 | 532 | | |
531 | 533 | | |
532 | 534 | | |
| 535 | + | |
533 | 536 | | |
534 | 537 | | |
535 | 538 | | |
| |||
539 | 542 | | |
540 | 543 | | |
541 | 544 | | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
542 | 549 | | |
543 | 550 | | |
544 | 551 | | |
545 | 552 | | |
546 | 553 | | |
547 | 554 | | |
| 555 | + | |
548 | 556 | | |
549 | 557 | | |
550 | 558 | | |
| |||
648 | 656 | | |
649 | 657 | | |
650 | 658 | | |
| 659 | + | |
651 | 660 | | |
652 | 661 | | |
653 | 662 | | |
| |||
975 | 984 | | |
976 | 985 | | |
977 | 986 | | |
| 987 | + | |
978 | 988 | | |
979 | 989 | | |
980 | 990 | | |
| |||
988 | 998 | | |
989 | 999 | | |
990 | 1000 | | |
| 1001 | + | |
991 | 1002 | | |
992 | 1003 | | |
993 | 1004 | | |
| |||
1001 | 1012 | | |
1002 | 1013 | | |
1003 | 1014 | | |
| 1015 | + | |
1004 | 1016 | | |
1005 | 1017 | | |
1006 | 1018 | | |
| |||
1034 | 1046 | | |
1035 | 1047 | | |
1036 | 1048 | | |
| 1049 | + | |
1037 | 1050 | | |
1038 | 1051 | | |
1039 | 1052 | | |
| |||
1047 | 1060 | | |
1048 | 1061 | | |
1049 | 1062 | | |
| 1063 | + | |
1050 | 1064 | | |
1051 | 1065 | | |
1052 | 1066 | | |
| |||
1075 | 1089 | | |
1076 | 1090 | | |
1077 | 1091 | | |
| 1092 | + | |
1078 | 1093 | | |
1079 | 1094 | | |
1080 | 1095 | | |
| |||
1088 | 1103 | | |
1089 | 1104 | | |
1090 | 1105 | | |
| 1106 | + | |
1091 | 1107 | | |
1092 | 1108 | | |
1093 | 1109 | | |
| |||
1101 | 1117 | | |
1102 | 1118 | | |
1103 | 1119 | | |
| 1120 | + | |
1104 | 1121 | | |
1105 | 1122 | | |
1106 | 1123 | | |
| |||
1129 | 1146 | | |
1130 | 1147 | | |
1131 | 1148 | | |
| 1149 | + | |
1132 | 1150 | | |
1133 | 1151 | | |
1134 | 1152 | | |
| |||
1142 | 1160 | | |
1143 | 1161 | | |
1144 | 1162 | | |
| 1163 | + | |
1145 | 1164 | | |
1146 | 1165 | | |
1147 | 1166 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| |||
292 | 292 | | |
293 | 293 | | |
294 | 294 | | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
295 | 325 | | |
296 | 326 | | |
297 | 327 | | |
298 | | - | |
| 328 | + | |
299 | 329 | | |
300 | 330 | | |
301 | 331 | | |
302 | | - | |
| 332 | + | |
| 333 | + | |
303 | 334 | | |
304 | | - | |
305 | | - | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
306 | 339 | | |
307 | 340 | | |
| 341 | + | |
| 342 | + | |
308 | 343 | | |
309 | 344 | | |
310 | | - | |
311 | | - | |
| 345 | + | |
312 | 346 | | |
313 | 347 | | |
314 | 348 | | |
315 | 349 | | |
316 | | - | |
| 350 | + | |
317 | 351 | | |
318 | 352 | | |
319 | 353 | | |
320 | | - | |
| 354 | + | |
321 | 355 | | |
322 | 356 | | |
323 | | - | |
| 357 | + | |
324 | 358 | | |
325 | 359 | | |
326 | 360 | | |
| |||
339 | 373 | | |
340 | 374 | | |
341 | 375 | | |
342 | | - | |
| 376 | + | |
343 | 377 | | |
344 | 378 | | |
345 | 379 | | |
346 | 380 | | |
347 | 381 | | |
348 | 382 | | |
349 | 383 | | |
350 | | - | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
351 | 389 | | |
352 | 390 | | |
353 | 391 | | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
| 392 | + | |
358 | 393 | | |
359 | 394 | | |
360 | 395 | | |
| |||
1013 | 1048 | | |
1014 | 1049 | | |
1015 | 1050 | | |
| 1051 | + | |
| 1052 | + | |
1016 | 1053 | | |
1017 | 1054 | | |
1018 | 1055 | | |
1019 | | - | |
| 1056 | + | |
1020 | 1057 | | |
1021 | 1058 | | |
1022 | 1059 | | |
| |||
1231 | 1268 | | |
1232 | 1269 | | |
1233 | 1270 | | |
1234 | | - | |
| 1271 | + | |
1235 | 1272 | | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
1236 | 1276 | | |
1237 | 1277 | | |
1238 | 1278 | | |
| |||
1480 | 1520 | | |
1481 | 1521 | | |
1482 | 1522 | | |
1483 | | - | |
1484 | | - | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
1485 | 1526 | | |
1486 | 1527 | | |
1487 | 1528 | | |
| |||
1617 | 1658 | | |
1618 | 1659 | | |
1619 | 1660 | | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
| 1666 | + | |
| 1667 | + | |
| 1668 | + | |
| 1669 | + | |
| 1670 | + | |
| 1671 | + | |
1620 | 1672 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
| |||
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
55 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
56 | 60 | | |
57 | | - | |
| 61 | + | |
58 | 62 | | |
59 | 63 | | |
| 64 | + | |
60 | 65 | | |
61 | | - | |
| 66 | + | |
62 | 67 | | |
63 | 68 | | |
64 | 69 | | |
| |||
88 | 93 | | |
89 | 94 | | |
90 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
91 | 123 | | |
92 | 124 | | |
93 | 125 | | |
| |||
98 | 130 | | |
99 | 131 | | |
100 | 132 | | |
101 | | - | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
102 | 146 | | |
103 | 147 | | |
104 | 148 | | |
| |||
0 commit comments