Commit 69569d1
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 76cd4d6 commit 69569d1
File tree
22 files changed
+632
-21
lines changed- crates
- base-db/src
- hir-def/src
- item_tree
- nameres
- tests
- ide/src
- project-model
- src
- test_data
- output
- test-fixture/src
- test-utils/src
- docs/book/src
22 files changed
+632
-21
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 | | |
536 | 539 | | |
537 | 540 | | |
538 | 541 | | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
539 | 545 | | |
540 | 546 | | |
541 | 547 | | |
| |||
545 | 551 | | |
546 | 552 | | |
547 | 553 | | |
| 554 | + | |
548 | 555 | | |
549 | 556 | | |
550 | 557 | | |
| |||
648 | 655 | | |
649 | 656 | | |
650 | 657 | | |
| 658 | + | |
651 | 659 | | |
652 | 660 | | |
653 | 661 | | |
| |||
975 | 983 | | |
976 | 984 | | |
977 | 985 | | |
| 986 | + | |
978 | 987 | | |
979 | 988 | | |
980 | 989 | | |
| |||
988 | 997 | | |
989 | 998 | | |
990 | 999 | | |
| 1000 | + | |
991 | 1001 | | |
992 | 1002 | | |
993 | 1003 | | |
| |||
1001 | 1011 | | |
1002 | 1012 | | |
1003 | 1013 | | |
| 1014 | + | |
1004 | 1015 | | |
1005 | 1016 | | |
1006 | 1017 | | |
| |||
1034 | 1045 | | |
1035 | 1046 | | |
1036 | 1047 | | |
| 1048 | + | |
1037 | 1049 | | |
1038 | 1050 | | |
1039 | 1051 | | |
| |||
1047 | 1059 | | |
1048 | 1060 | | |
1049 | 1061 | | |
| 1062 | + | |
1050 | 1063 | | |
1051 | 1064 | | |
1052 | 1065 | | |
| |||
1075 | 1088 | | |
1076 | 1089 | | |
1077 | 1090 | | |
| 1091 | + | |
1078 | 1092 | | |
1079 | 1093 | | |
1080 | 1094 | | |
| |||
1088 | 1102 | | |
1089 | 1103 | | |
1090 | 1104 | | |
| 1105 | + | |
1091 | 1106 | | |
1092 | 1107 | | |
1093 | 1108 | | |
| |||
1101 | 1116 | | |
1102 | 1117 | | |
1103 | 1118 | | |
| 1119 | + | |
1104 | 1120 | | |
1105 | 1121 | | |
1106 | 1122 | | |
| |||
1129 | 1145 | | |
1130 | 1146 | | |
1131 | 1147 | | |
| 1148 | + | |
1132 | 1149 | | |
1133 | 1150 | | |
1134 | 1151 | | |
| |||
1142 | 1159 | | |
1143 | 1160 | | |
1144 | 1161 | | |
| 1162 | + | |
1145 | 1163 | | |
1146 | 1164 | | |
1147 | 1165 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
41 | 42 | | |
42 | | - | |
| 43 | + | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
| |||
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 | + | |
| 325 | + | |
| 326 | + | |
295 | 327 | | |
296 | 328 | | |
297 | 329 | | |
| |||
349 | 381 | | |
350 | 382 | | |
351 | 383 | | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
352 | 404 | | |
353 | 405 | | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
| 406 | + | |
358 | 407 | | |
359 | 408 | | |
360 | 409 | | |
| |||
1480 | 1529 | | |
1481 | 1530 | | |
1482 | 1531 | | |
1483 | | - | |
1484 | | - | |
| 1532 | + | |
| 1533 | + | |
| 1534 | + | |
1485 | 1535 | | |
1486 | 1536 | | |
1487 | 1537 | | |
| |||
1617 | 1667 | | |
1618 | 1668 | | |
1619 | 1669 | | |
| 1670 | + | |
| 1671 | + | |
| 1672 | + | |
| 1673 | + | |
| 1674 | + | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + | |
| 1678 | + | |
| 1679 | + | |
| 1680 | + | |
1620 | 1681 | | |
| 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 | + | |
| 123 | + | |
| 124 | + | |
91 | 125 | | |
92 | 126 | | |
93 | 127 | | |
| |||
98 | 132 | | |
99 | 133 | | |
100 | 134 | | |
101 | | - | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
102 | 156 | | |
103 | 157 | | |
104 | 158 | | |
| |||
0 commit comments