Commit graph

1090 commits

Author SHA1 Message Date
Chayim Refael Friedman
cc11e1a796 Unify handling of path diagnostics in hir-ty
Because it was a mess.

Previously, pretty much you had to handle all path diagnostics manually: remember to check for them and handle them. Now, we wrap the resolver in `TyLoweringContext` and ensure proper error reporting.

This means that you don't have to worry about them: most of the things are handled automatically, and things that cannot will create a compile-time error (forcing you top `drop(ty_lowering_context);`) if forgotten, instead of silently dropping the diagnostics.

The real place for error reporting is in the hir-def resolver, because there are other things resolving, both in hir-ty and in hir-def, and they all need to ensure proper diagnostics. But this is a good start, and future compatible.

This commit also ensures proper path diagnostics for value/pattern paths, which is why it's marked "feat".
2024-12-24 18:58:52 +02:00
Lukas Wirth
027daf1686
Merge pull request #18702 from ChayimFriedman2/prep
minor: Use a record struct instead of a tuple for each namespace in `PerNs`
2024-12-20 11:05:49 +00:00
Lukas Wirth
2780dfd80c
Merge pull request #18708 from ChayimFriedman2/fix-tiny
fix: Fix pretty-printing of `@` patterns
2024-12-18 07:41:09 +00:00
Chayim Refael Friedman
8c8e738636 Fix pretty-printing of @ patterns
It didn't print the `@`.
2024-12-18 01:24:12 +02:00
Chayim Refael Friedman
79214583f6 Use a record struct instead of a tuple for each namespace in PerNs
The reason I did this is because I plan to add another field to this struct (indicating whether the item was cfg'ed out), but it seems worthy even separately and removes a bunch of one-letter variable names and tuple-indexing. It is also easy to separate from future changes, so it will be easier to review this way.
2024-12-16 22:39:50 +02:00
Chayim Refael Friedman
54ce1dda3a Report unresolved idents for implicit captures in format_args!()
And also a bit of cleanup by storing the capture's span with the open quote included.
2024-12-16 10:10:26 +02:00
Lukas Wirth
956ff4d8c5 Rename test fixture crates to ra_test_fixture 2024-12-09 11:40:21 +01:00
Chayim Refael Friedman
26333a467e Fix a test that didn't test what it should
That is, fix the helper function and disable the tests for now.
2024-12-08 15:02:14 +02:00
Lukas Wirth
abc7147bb7
Merge pull request #18594 from ChayimFriedman2/async-closures
feat: Support `AsyncFnX` traits
2024-12-06 12:48:47 +00:00
Lukas Wirth
d6b62265b5 fix: Resolve generic parameters within use captures 2024-12-05 19:11:33 +01:00
Lukas Wirth
f3d7415bd6 Parse lifetime bounds in lifetime param into TypeBoundList
This mainly aids in error recovery but also makes it a bit easier to handle lifetime resolution.
While doing so it also came apparent that we were not actually lowering lifetime outlives relationships within lifetime parameter declaration bounds, so this fixes that.
2024-12-05 17:52:02 +01:00
Lukas Wirth
df7ab62a06 fix: Fix parsing of integer/keyword name refs in various places 2024-12-05 15:27:50 +01:00
Chayim Refael Friedman
21ad3b5b87 Complete diagnostics in ty lowering groundwork
Implement diagnostics in all places left: generics (predicates, defaults, const params' types), fields, and type aliases.

Unfortunately this results in a 20mb addition in `analysis-stats .` due to many type methods returning an addition diagnostics result now (even if it's `None` in most cases). I'm not sure if this can be improved.

An alternative strategy that can prevent the memory usage growth is to never produce diagnostics in hir-ty methods. Instead, lower all types in the hir crate when computing diagnostics from scratch (with diagnostics this time). But this has two serious disadvantages:
 1. This can cause code duplication (although it can probably be not that bad, it will still mean a lot more code).
 2. I believe we eventually want to compute diagnostics for the *entire* workspace (either on-type or on-save or something alike), so users can know when they have diagnostics even in inactive files. Choosing this approach will mean we lose all precomputed salsa queries. For one file this is fine, for the whole workspace this will be very slow.
2024-12-04 14:22:56 +02:00
Chayim Refael Friedman
5f25ae3d1b Lay the foundation for diagnostics in ty lowering, and implement a first diagnostic
The diagnostic implemented is a simple one (E0109). It serves as a test for the new foundation.

This commit only implements diagnostics for type in bodies and body-carrying signatures; the next commit will include diagnostics in the rest of the things.

Also fix one weird bug that was detected when implementing this that caused `Fn::(A, B) -> C` (which is a valid, if bizarre, alternative syntax to `Fn(A, B) -> C` to lower incorrectly.

And also fix a maybe-bug where parentheses were sneaked into a code string needlessly; this was not detected until now because the parentheses were removed (by the make-AST family API), but with a change in this commit they are now inserted. So fix that too.
2024-12-04 14:22:56 +02:00
Chayim Refael Friedman
4e475a3245 Store some hir_def Paths in the type ref source maps
Most paths are types and therefore already are in the source map, but the trait in impl trait and in bounds are not.

We do this by storing them basically as `TypeRef`s. For convenience, I created a wrapper around `TypeRefId` called `PathId` that always stores a path, and implemented indexing from the types map to it.

Fortunately, this change impacts memory usage negligibly (adds 2mb to `analysis-stats .`, but that could be just fluff). Probably because there aren't that many trait bounds and impl traits, and this also shrinks `TypeBound` by 8 bytes.

I also added an accessor to `TypesSourceMap` to get the source code, which will be needed for diagnostics.
2024-12-04 14:09:50 +02:00
Lukas Wirth
65c0b29720 Fix parsing of parenthesized type args and RTN 2024-12-04 11:48:47 +01:00
Lukas Wirth
edb432639b
Merge pull request #18609 from ChayimFriedman2/unsafe-coverage
feat: Extend reported unsafe operations
2024-12-04 06:40:40 +00:00
Chayim Refael Friedman
327b8c9f93 Extend reported unsafe operations
We add union fields access (in both expressions and patterns) and inline assembly.

That completes the unsafe check (there are some other unsafe things but they are unstable), and so also opens the door to reporting unused unsafe without annoying people about their not-unused unsafe blocks.
2024-12-04 08:27:59 +02:00
Lukas Wirth
ab652f7795
Merge pull request #18608 from Veykril/push-rrozmpnyknkx
Better parser recovery for paths
2024-12-04 06:18:39 +00:00
Lukas Wirth
83f5150978 Update mbe test output 2024-12-04 07:03:11 +01:00
Lukas Wirth
4b4cec882a
Merge pull request #18605 from ChayimFriedman2/wildcard-imports
fix: Fixed another bug with glob imports
2024-12-04 05:15:46 +00:00
Chayim Refael Friedman
4ec7e61229 Fix shadowing of record enum variant in patterns 2024-12-04 04:02:54 +02:00
Chayim Refael Friedman
215cbe9e71 Fixed another bug with glob imports
When a glob import overriding the visibility of a previous glob import was not properly resolved when the items are only available in the next fixpoint iteration.

The bug was hidden until #18390.
2024-12-04 03:15:32 +02:00
Chayim Refael Friedman
4049c3b6a9 Support AsyncFnX traits
Only in calls, because to support them in bounds we need support from Chalk. However we don't yet report error from bounds anyway, so this is less severe.

The returned future is shown in its name within inlay hints instead of as a nicer `impl Future`, but that can wait for another PR.
2024-12-03 21:26:26 +02:00
Lukas Wirth
e6276c8b64
Merge pull request #18555 from ChayimFriedman2/issue-17321
fix: Fix a bug when synthetic AST node were searched in the AST ID map and caused panics
2024-12-03 15:39:52 +00:00
Mark Murphy
a53ee64e70 Add macro expansion test for raw variable names 2024-11-26 00:42:27 -05:00
Chayim Refael Friedman
b66bc91b4b Fix a bug when synthetic AST node were searched in the AST ID map and caused panics 2024-11-25 14:52:58 +02:00
Lukas Wirth
36d68c5d0f Support new #[rustc_intrinsic] attribute and fallback bodies 2024-11-04 13:33:55 +01:00
Lukas Wirth
78f3112626 Allow interpreting consts and statics with interpret function command 2024-11-03 15:35:45 +01:00
Lukas Wirth
94c35f6138 Allow static initializers to be const evaluated 2024-11-02 12:43:11 +01:00
Lukas Wirth
70348faf2b Move child_by_source from hir-def to hir 2024-10-31 09:28:08 +01:00
Chayim Refael Friedman
41658de227 Cleanup TypeRef lowering
By removing interior mutability from it.
2024-10-28 17:38:37 +02:00
Lukas Wirth
09547e9ea5
Merge pull request #18413 from ShoyuVanilla/extern-crate-reexport
fix: Allow public re-export of `extern crate` import
2024-10-28 13:51:26 +00:00
Lukas Wirth
343abd9193
Merge pull request #18422 from ChayimFriedman2/cursed-name-res
fix: Properly resolve prelude paths inside modules inside blocks
2024-10-28 13:45:19 +00:00
Lukas Wirth
80e9d014be
Merge pull request #18074 from ChayimFriedman2/typeref-source-map
internal: Build source map for `hir_def::TypeRef`s
2024-10-28 11:01:12 +00:00
Chayim Refael Friedman
1fed2403d1 Properly resolve prelude paths inside modules inside blocks
I.e. the following situation:
```
fn foo() {
    mod bar {
        fn qux() {
            // Prelude path here (e.g. macro use prelude or extern prelude).
        }
    }
}
```
Those were previously unresolved, because, in order to support `self` and `super` properly, since #15148 we do not ascend block paths when there is a module in between, but only crate def maps register preludes, not block def maps, and we can't change this because block def map prelude can always be overridden by another block. E.g.
```
fn foo() {
    struct WithTheSameNameAsPreludeItem;
    {
        WithTheSameNameAsPreludeItem
    }
}
```
Here `WithTheSameNameAsPreludeItem` refer to the item from the top block, but if we would register prelude items in each block the child block would overwrite it incorrectly.
2024-10-27 19:23:12 +02:00
Shoyu Vanilla
eb2a50e75d fix: Allow public re-export of extern crate import 2024-10-27 23:44:44 +09:00
Lukas Wirth
3b3a87fe9b
Merge pull request #18419 from ChayimFriedman2/leading-or
fix: Put leading `|` in patterns under `OrPat`
2024-10-27 11:25:16 +00:00
Chayim Refael Friedman
e12a001b55 Put leading | in patterns under OrPat
Previously it was one level above, and that caused problems with macros that expand to it, because macros expect to get only one top-level node.
2024-10-27 13:11:38 +02:00
Lukas Wirth
79b86f25b4
Merge pull request #18418 from ChayimFriedman2/explicitly-disable
feat: Split `macro-error` diagnostic so users can ignore only parts of it
2024-10-27 09:37:56 +00:00
Chayim Refael Friedman
f4585ea023 Split macro-error diagnostic so users can ignore only parts of it
Split it into `macro-error`, `proc-macros-disabled` and `proc-macro-disabled`.
2024-10-27 02:24:15 +02:00
Lukas Wirth
a12f1781eb Only construct a resolver in macro descension when needed 2024-10-25 10:23:59 +02:00
Chayim Refael Friedman
bf7edd3783 Shrink TypeRef from 16 from 32 bytes
Only references and arrays need to be boxed, and they comprise only 9.4% of the types (according to counting on r-a's code).

This saves 17mb.
2024-10-25 06:44:56 +03:00
Chayim Refael Friedman
061e5d7f71 Shrink Path to 16 bytes
Thanks to the observation (supported by counting) that the vast majority paths have neither generics no type anchors, and thanks to a new datastructure `ThinVecWithHeader` that is essentially `(T, Box<[U]>)` but with the size of a single pointer, we are able to reach this feat.

This (together with `ThinVecWithHeader`) makes the possibility to shrink `TypeRef`, because most types are paths.
2024-10-25 06:44:56 +03:00
Chayim Refael Friedman
bccf0062b7 Do not allocate attributes entry if there are no attributes
This saves 8mb.
2024-10-25 06:15:06 +03:00
Chayim Refael Friedman
d0933cc097 Shrink ItemTreeSourceMaps
This saves 16mb on `analysis-stats .`.
2024-10-25 06:15:06 +03:00
Chayim Refael Friedman
39747cb518 Reuse empty GenericParams
This saves back 15mb that went for typeref source maps.
2024-10-25 06:15:06 +03:00
Chayim Refael Friedman
89c0ffa6b0 Build source map for hir_def::TypeRefs
So that given a `TypeRef` we will be able to trace it back to source code.

This is necessary to be able to provide diagnostics for lowering to chalk tys, since the input to that is `TypeRef`.

This means that `TypeRef`s now have an identity, which means storing them in arena and not interning them, which is an unfortunate (but necessary) loss but also a pretty massive change. Luckily, because of the separation layer we have for IDE and HIR, this change never crosses the IDE boundary.
2024-10-25 06:15:04 +03:00
Lukas Wirth
b12fead6da
Merge pull request #18390 from ShoyuVanilla/issue-18308
fix: Prevent public re-export of private item
2024-10-24 09:25:06 +00:00
Lukas Wirth
40492e15d4
Merge pull request #18392 from Veykril/veykril/push-wktpkuklnzot
Swap query call order in `file_item_tree_query`
2024-10-23 20:31:49 +00:00