101 Commits

Author SHA1 Message Date
Chayim Refael Friedman
bd934c08cf Allow IDE layer to "see" fake builtin derive impls
It sees them as regular impls; the details are abstracted. It's beautiful for the IDE layer, and less beautiful for `hir`, so this is a big change.

Some small differences still exist:

 - We show builtin derives impl (to the IDE layer) as if they have had no generic parameters. It is possible to show the parameters, but that means also having to handle fake impls in `TypeParam` etc., and the benefit is questionable.
 - Getting the fn *def* type of a method of a builtin derive impl is not supported, as there is no real `FunctionId`, therefore no `CallableDefId`. The trait method is returned instead. Note: getting the fn *ptr* type of the method is supported well.
 - Builtin derive impls and their methods do not fully support `HasSource`, because, well, they have no source (at least, not in the form of `ast::Impl` and `ast::Fn`). To support them, we use the derive's `TextRange` where possible, and the trait method's source when not.

 It's important to note that the def map still records the `MacroCallId`. I have doubts over this, as this means it's very easy to create the queries we don't want to create, but it does make things more convenient. In particular, a nicety of this setup is that even "Expand macro recursively" works (it creates the macro input/output query, but given that they will only be created when the user invokes the command, that does not seem to be a problem).
2025-12-26 15:00:08 +02:00
Chayim Refael Friedman
5fbff1d7fb Make builtin derives cheaper, by not really expanding them, instead store them unexpanded 2025-12-25 16:26:11 +02:00
Lukas Wirth
af45994feb Introduce cargo-machete ci step 2025-12-25 10:38:05 +01:00
Chayim Refael Friedman
5e2dfbbd02 Add extensive docs for the unsafe operations 2025-12-18 17:30:20 +02:00
Chayim Refael Friedman
36c9f6224c GC support for solver types
A GC is triggered every X revisions, and is synchronous, unfortunately.
2025-12-18 10:12:03 +02:00
Chayim Refael Friedman
776c818882 Lay the basics for non-Copy solver types with GC
That means stop using Salsa for interning solver types.
2025-12-18 10:12:03 +02:00
Chayim Refael Friedman
d7465cb5b7 Upgrade rustc crates
Changes:
 - `const_of_item()` was added to `Interner`, analogous to `type_of()`. No strongly-typed ID (yet).
 - New solver trait lang item: `TrivialClone`.
 - `TypeRelation` changed a bit, the code was copied from rustc.
2025-12-16 17:00:44 +02:00
Chayim Refael Friedman
a4612ce527 Register define_opaque builtin attribute macro
So that we'll correctly treat it as an attribute.

I don't like that we have to register every builtin macro even if we don't need it, but that's what we got.
2025-12-01 02:31:30 +02:00
Zalathar
fe1469ebd1 Basic support for declarative attribute/derive macros 2025-11-24 21:50:56 +11:00
Chayim Refael Friedman
e8e02d5515
Merge pull request #20974 from ChayimFriedman2/ns4
fix: Rewrite method resolution to follow rustc more closely
2025-11-18 23:20:04 +00:00
Lukas Wirth
c1c6682e8b Merge pull request #20994 from Veykril/push-npvyklkuxnlr
perf: Reduce memory usage of symbol index
2025-11-15 09:17:33 +02:00
Chayim Refael Friedman
50384460c6 Rewrite method resolution to follow rustc more closely
It cannot be exactly the same, because we have needs rustc doesn't have (namely, accurate enumeration of all methods, not just with a specific name, for completions etc., while rustc also needs a best-effort implementation for diagnostics) but it is closer than the previous impl.

In addition we rewrite the closely related handling of operator inference and impl collection.

This in turn necessitate changing some other parts of inference in order to retain behavior. As a result, the behavior more closely matches rustc and is also more correct.

This fixes 2 type mismatches on self (1 remains) and 4 diagnostics (1 remains), plus some unknown types.
2025-11-05 18:43:36 +02:00
Chayim Refael Friedman
bdd7f15b3d Implement Interner::impl_specializes()
Using specialization logic ported from rustc.
2025-10-23 20:48:51 +03:00
Chayim Refael Friedman
6b133c6b1b Implement fallback properly
fallback.rs was ported straight from rustc (minus the lint parts).

This fixes the `!` regressions.
2025-09-24 20:42:06 +03:00
Chayim Refael Friedman
7d1860807e Port a bunch of stuff from rustc and fix a bunch of type mismatches/diagnostics
This started from porting coercion, but ended with porting much more.
2025-09-15 18:56:17 +03:00
jackh726
9418a3f2df Implement next trait solver 2025-08-09 16:08:58 +00:00
Chayim Refael Friedman
b1914e420f Support cfg_select! 2025-07-20 11:56:45 +03:00
Shoyu Vanilla
953e9d1c36 Backport new sized-hierarchy trait bounds in old ways 2025-06-26 23:22:26 +09:00
Chayim Refael Friedman
de312d0c71 Don't run doctests 2025-06-23 00:50:22 +03:00
Shoyu Vanilla
4f8767d790 Minic rustc's new format_args! expansion 2025-06-22 13:22:28 +09:00
Lukas Wirth
23712aea06 cargo upgrade 2025-06-13 10:08:20 +02:00
Trevor Gross
e6e5e3cc41 chore: Remove support for concat_idents!
`concat_idents!` was deprecated in [1] and will be removed in the near
future. rust-analyzer's support is independent of rustc's, so drop RA
support now to make syncing easier.

[1]: https://github.com/rust-lang/rust/pull/137653
2025-05-28 03:59:32 +00:00
Matthias Krüger
573c47c9ba remove a couple of clones 2025-05-01 11:41:42 +02:00
Chayim Refael Friedman
4d95ae52f8 Upgrade dashmap and hashbrown
And adapt `intern` to the changes in the API.
2025-04-25 12:47:26 +03:00
Lukas Wirth
34e7d60e30
Merge pull request #19644 from ChayimFriedman2/const-syms
internal: Make predefined symbols `const` instead of `static`
2025-04-21 12:34:59 +00:00
Lukas Wirth
d16b862ea5 fix: Support unstable UnsafePinned struct in type layout calc 2025-04-21 09:35:30 +02:00
Chayim Refael Friedman
9477e46bec Get rid of static predefined symbols
Make them all `const`.
2025-04-21 03:07:35 +03:00
Lukas Wirth
e7ce86ddea fix: Fix format_args lowering for >=1.87 2025-04-06 10:05:56 +02:00
BenjaminBrienen
2462624a7d prefer default over new 2025-04-04 15:49:50 +02:00
Chayim Refael Friedman
7b584ef9bf Allow crate authors to control completion of their things
Via the new `#[rust_analyzer::completions(...)]` attribute.

Also fix a bug with existing settings for that where the paths wouldn't resolve correctly.
2025-03-27 14:01:26 +02:00
Lukas Wirth
c96421ecf4 ci: run intern tests via cargo miri 2025-03-25 07:26:43 +01:00
Lukas Wirth
c28b80c321 internal: Symbol is not PartialOrd 2025-03-16 16:06:06 +01:00
BenjaminBrienen
7535bb4661 cargo fmt 2025-03-15 21:32:01 +01:00
Chayim Refael Friedman
c94e9efbef Salsify the crate graph
I.e. make it not one giant input but multiple, for incrementality and decreased memory usage for Salsa 3 reasons.
2025-03-12 21:02:30 +02:00
Lukas Wirth
af7f89cc9d Fix path macro hygiene 2025-03-10 09:29:27 +01:00
Thalia Archibald
0811ca0a61 Use size_of from the prelude instead of imported
Use `std::mem::{size_of, size_of_val, align_of, align_of_val}` from the
prelude instead of importing or qualifying them.

These functions were added to all preludes in Rust 1.80.
2025-03-05 00:48:44 -08:00
BenjaminBrienen
bd7375a58f enable doctest 2025-02-27 14:58:46 +01:00
Lukas Wirth
09db657439
Merge pull request #19127 from ChayimFriedman2/different-generic-args
feat: Refactor path lowering and serve a new path diagnostic
2025-02-17 08:30:10 +00:00
Chayim Refael Friedman
55c04ab371 Refactor path lowering
And add a new diagnostic for non-`Fn` parenthesized generic args.

Path lowering started to look like a mess, with each function carrying additional parameters for the diagnostic callback (since paths can occur both in type and in expression/pattern position, and their diagnostic handling is different) and the segment index, for the diagnostics report. So I refactored it from stateless functions on `TyLoweringContext` into stateful struct, `PathLoweringContext`, that tracks the process of lowering a path from resolution til assoc types selection.
2025-02-16 19:44:50 +02:00
Laurențiu Nicola
bf51af1a6d Merge from rust-lang/rust 2025-02-10 07:49:43 +02:00
Lukas Wirth
0fd4fc3522
Merge pull request #19084 from Veykril/push-muworpzpzqup
Split cache priming into distinct phases
2025-02-04 13:57:39 +00:00
Lukas Wirth
ab5e821d97 Expose symbol of CrateName 2025-02-04 14:38:58 +01:00
Lukas Wirth
d6645d11da Fix some mir eval/lowerings 2025-02-03 14:42:41 +01:00
Bastian Kersting
8196d260e8 Insert null checks for pointer dereferences when debug assertions are enabled
Similar to how the alignment is already checked, this adds a check
for null pointer dereferences in debug mode. It is implemented similarly
to the alignment check as a MirPass.

This is related to a 2025H1 project goal for better UB checks in debug
mode: https://github.com/rust-lang/rust-project-goals/pull/177.
2025-01-31 11:13:34 +00:00
Chayim Refael Friedman
791b1ebfd4 Support RFC 2396
AKA. target_feature 1.1, or non unsafe target_feature.
2025-01-26 23:31:58 +02:00
Lukas Wirth
090a145d44 Use strict_provenance 2025-01-25 13:47:07 +01:00
Shoyu Vanilla
f4dfbc38c8 feat: Implement arbitrary-self-types 2025-01-24 22:50:59 +09:00
Lukas Wirth
2c040c03cf
Merge pull request #18986 from Veykril/push-zlwvwlowpzqm
Goto `Display::fmt` when invoked on `to_string`
2025-01-21 09:25:05 +00:00
Lukas Wirth
76585539f5 Cleanup Name string rendering 2025-01-21 10:05:32 +01:00
Lukas Wirth
a3eee10638 Goto Display::fmt when invoked on to_string 2025-01-20 17:00:28 +01:00