Commit graph

1566 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
Chayim Refael Friedman
02d47f3a81 Fix a case where completion was unable to expand a macro
Which caused the macros of the popular `tracing` crate to not offer completions.

The reason is rather complicated: it boils down to macro ignoring their input and completion always choosing the first expansion.
2024-12-20 13:14:59 +02:00
Lukas Wirth
ada5f2059c fix: Fix path qualified auto-importing completions not working with re-exports
Prior to this commit we used to generate import paths, then zipped them with the existing qualifier to check if they agree on the path to import.
This is brittle when re-exports come into play causing items to have multiple applicable paths that refer to them.
This commit instead rewrites this logic by generating the import path for the qualifier, verifying that the rest of the qualifier resolves and then doing a final lookup on that resolution result for the final segment instead.
2024-12-16 13:20:55 +01: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
15239f612d internal: Show mir eval errors on hover with debug env var set 2024-12-15 17:38:37 +01:00
Lukas Wirth
6aadbae022
Merge pull request #18674 from Veykril/push-lrxotqknvxvr
Show expansion errors in expand_macro feature
2024-12-13 08:50:45 +00:00
Lukas Wirth
28fbecff42 Show expansion errors in expand_macro feature 2024-12-13 09:36:03 +01:00
Lukas Wirth
f748eb510e internal: Implement naked_asm! builtin 2024-12-12 17:43:27 +01:00
roife
78fb0e47ca feat: preserve order of parameters in extract_functions 2024-12-11 02:26:58 +08: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
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
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
Chayim Refael Friedman
890d155ffe Complete derive helper attributes
Only their names, anything can go inside.
2024-12-04 08:20:41 +02: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
Vincent Esche
e6461522bc Add direct_supertraits(…) HIR-level method to hir::Trait type 2024-11-06 10:02:13 +01:00
Vincent Esche
5a9767b115 Refactor hir::Trait's existing items_with_supertraits(…) method based on new all_supertraits(…) method 2024-11-06 10:02:13 +01:00
Vincent Esche
89a002ef9b Add pub fn all_supertraits(…) HIR-level method to hir::Trait type 2024-11-06 10:02:13 +01: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
Lukas Wirth
436ace3ecb
Merge pull request #18436 from Veykril/lw-yvkqwpnwsouo
Do not render meta info when hovering usages
2024-10-30 09:21:35 +00:00
Lukas Wirth
a953875f49 Style hover messages a bit differently 2024-10-29 16:59:48 +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
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
Lukas Wirth
715b67c425
Merge pull request #18410 from Veykril/veykril/push-lvwxpnowqrxk
internal: Invert token iteration order in macro mapping
2024-10-27 10:44:32 +00:00
Lukas Wirth
20ac30fb75 Invert token iteration order in macro mapping 2024-10-27 11:32:12 +01: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
1fae57fa55 Fix memory usage calculation's queries list 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
98935325ca minor: Remove intermediate allocations 2024-10-24 13:34:32 +02:00
Chayim Refael Friedman
8adcbdcc49 Implement semitransparent hygiene
Or macro_rules hygiene, or mixed site hygiene. In other words, hygiene for variables and labels but not items.

The realization that made me implement this was that while "full" hygiene (aka. def site hygiene) is really hard for us to implement, and will likely involve intrusive changes and performance losses, since every `Name` will have to carry hygiene, mixed site hygiene is very local: it applies only to bodies, and we very well can save it in a side map with minor losses.

This fixes one diagnostic in r-a that was about `izip!()` using hygiene (yay!) but it introduces a huge number of others, because of #18262. Up until now this issue wasn't a major problem because it only affected few cases, but with hygiene identifiers referred by macros like that are not resolved at all. The next commit will fix that.
2024-10-22 21:26:56 +03:00
Lukas Wirth
c286786888
Merge pull request #18254 from ChayimFriedman2/fix-mut
fix: Nail destructuring assignment once and for all
2024-10-22 17:40:52 +00:00
bors
d509449d7e Auto merge of #18370 - duncpro:goto-def-ranges, r=Veykril
feat: resolve range patterns to their structs

Closes #18367
2024-10-22 12:24:25 +00:00
Duncan Proctor
4fd471c571 tidy 2024-10-22 06:54:44 -04:00
Duncan Proctor
271f64f94d resolve range patterns to the their struct types 2024-10-22 06:20:16 -04:00
Lukas Wirth
6c23f25e7f Fix new nightly lints 2024-10-22 11:48:41 +02:00
bors
17055aaca9 Auto merge of #18362 - duncpro:goto-def-ranges, r=Veykril
feat: goto definition on range operators

Closes #18342
2024-10-22 07:49:18 +00:00
Duncan Proctor
2f6923b844 tidy 2024-10-22 03:19:47 -04:00
Duncan Proctor
f54a863965 goto definition on RangeFrom, RangeFull, RangeTo, and RangeToInclusive links to respective struct 2024-10-22 03:11:23 -04:00
duncanproctor
c7a8be110d Move explicit range handling out of goto_definition, use OperatorClass instead 2024-10-21 20:07:07 -04:00
Lukas Wirth
d878b8caad fix: Fix token downmapping failing for include! inputs 2024-10-21 17:22:18 +02:00
Chayim Refael Friedman
2d4d6b678f Store patterns desugared from destructuring assignments in source map
And few more fixups.

I was worried this will lead to more memory usage since `ExprOrPatId` is double the size of `ExprId`, but this does not regress `analysis-stats .`. If this turns out to be a problem, we can easily use the high bit to encode this information.
2024-10-20 19:11:32 +03:00