Commit Graph

482 Commits

Author SHA1 Message Date
hkalbasi
f0ba0dbe8a Use debug impl in rendering const eval result 2023-07-08 01:07:38 +03:30
hkalbasi
4a444e768c Implement recursion in mir interpreter without recursion 2023-07-07 15:07:29 +03:30
hkalbasi
3a1054fc1c Replace x with it 2023-07-06 17:33:17 +03:30
bors
4125fea0a7 Auto merge of #15222 - HKalbasi:mir, r=HKalbasi
Fix size_of_val and support min_align_of_val
2023-07-06 12:40:21 +00:00
hkalbasi
171ae2ee5d Fix size_of_val and support min_align_of_val 2023-07-06 15:41:52 +03:30
Ryo Yoshida
827a0530bc
Don't show unresolved-field diagnostic for missing names 2023-07-06 20:39:48 +09:00
bors
e219999a17 Auto merge of #15211 - lowr:patch/gats-in-bounds-for-assoc, r=flodiebold
Support GATs in bounds for associated types

Chalk has a dedicated IR for bounds on trait associated type: `rust_ir::InlineBound`. We have been failing to convert GATs inside those bounds from our IR to chalk IR. This PR provides an easy fix for it: properly take GATs into account during the conversion.
2023-07-04 15:36:16 +00:00
Ryo Yoshida
9fd5f8c670
Support GATs in bounds for associated types 2023-07-04 18:58:19 +09:00
bors
45272efec5 Auto merge of #14990 - HKalbasi:diagnostic-map, r=HKalbasi
Map our diagnostics to rustc and clippy's ones

And control their severity by lint attributes `#[allow]`, `#[deny]` and ... .

It doesn't work with proc macros and I would like to fix that before merge but I don't know how to do it.
2023-07-03 18:58:47 +00:00
bors
daba334611 Auto merge of #15206 - Veykril:let-else-fmt, r=Veykril
internal: Format let-else

As nightly finally got support for it I went ahead and formatted r-a with the latest nightly, then with the latest stable (in case other stuff changed)
2023-07-03 18:41:59 +00:00
Lukas Wirth
69cd3c30ac Format let-else 2023-07-03 20:34:09 +02:00
bors
5703346523 Auto merge of #15118 - alexkirsz:alexkirsz/resolve-deref-raw, r=Veykril
Follow raw pointers in autoderef chain when resolving methods with custom receiver

Fixes #15083

I believe this stopped working after e797479651
2023-07-03 14:55:08 +00:00
Ryo Yoshida
6086ced61d Revert "Support #[rustc_coinductive]"
This reverts commit d026479ba6.
2023-07-03 05:06:55 +09:00
hkalbasi
6f7452882a Fix layout of simd types and respect align in mir interpreter 2023-07-02 00:42:33 +03:30
hkalbasi
15a0da6f30 Fix overflow checking in shift operator 2023-07-01 17:16:56 +03:30
hkalbasi
bb85a980e0 Bump chalk 2023-06-30 23:36:47 +03:30
hkalbasi
45828cdb54 Disable mir interpreter for targets with different pointer size from host 2023-06-30 21:21:52 +03:30
bors
76bcd9946a Auto merge of #15169 - lowr:patch/impl-header-anon-lifetime, r=HKalbasi
Use anonymous lifetime where possible

Because anonymous lifetimes are *super* cool.

More seriously, I believe anonymous lifetimes, especially those in impl headers, reduce cognitive load to a certain extent because they usually signify that they are not relevant in the signature of the methods within (or that we can apply the usual lifetime elision rules even if they are relevant).
2023-06-30 16:57:20 +00:00
hkalbasi
302bb3c871 Fix data layout of reference to nested unsized structs 2023-06-29 23:38:13 +03:30
Ryo Yoshida
4e793e7859
Use anonymous lifetime where possible 2023-06-29 23:27:28 +09:00
hkalbasi
2272803330 Fix realloc problem in allocating smaller amounts 2023-06-29 17:28:48 +03:30
bors
021604431c Auto merge of #15125 - lowr:patch/rustc_coinductive, r=Veykril
internal: support `#[rustc_coinductive]`

rust-lang/rust#100386 changed the trait solver so that `Sized` is treated as coinductive trait, just like auto traits. This is now controlled by the perma-unstable `#[rustc_coinductive]` attribute (rust-lang/rust#108033), which this PR adds support for.

In practice, I don't think this matters much if at all. Currently we don't give chalk enough information so chalk cannot precisely (dis)prove `Sized` bounds.
2023-06-28 10:13:31 +00:00
hkalbasi
6d2d1387af Fix some unsizing problems in mir 2023-06-26 01:57:12 +03:30
Ryo Yoshida
d026479ba6
Support #[rustc_coinductive] 2023-06-25 00:13:31 +09:00
hkalbasi
5eb4796d3d Support more intrinsics in mir interpreter 2023-06-23 21:08:05 +03:30
Alex Kirszenberg
5991f0d869 Follow raw pointers in autoderef chain when resolving methods with custom receiver 2023-06-23 15:35:41 +02:00
hkalbasi
99a4f2e983 Support manual impl of fn traits in mir interpreter 2023-06-22 22:24:21 +03:30
dfireBird
410ede9101
Add some tests in number evaluvation and hover to prevent regression
Added a test near positive extermes and two test near negative
extermes as well one for 0.
Added a test using the `as` cast and one with comparison with 0.
2023-06-22 17:58:12 +05:30
dfireBird
b8017928af
Change comparsion for checking if number is negative to include 128
Reason: The last byte in Little Endian representation of negative
integers start at 128 (Ox80) till 255 (OxFF). The comparison before
the fix didn't check for 128 which made is_negative variable as false.
2023-06-22 12:51:35 +05:30
David Lattimore
bea3a33d84 Change in-tree libs to workspace dependencies 2023-06-20 13:53:39 +10:00
Lukas Wirth
9476fdaaa9 HIR ExternCrateDecl 2023-06-19 14:15:08 +02:00
bors
00b9d9faf4 Auto merge of #15071 - matklad:no-regex, r=matklad
internal: remove spurious regex dependency

- replace tokio's env-filter with a smaller&simpler targets filter
- reshuffle logging infra a bit to make sure there's only a single place where we read environmental variables
- use anyhow::Result in rust-analyzer binary
2023-06-19 10:51:03 +00:00
Alex Kladov
424ef77809 internal: remove spurious regex dependency
- replace tokio's env-filter with a smaller&simpler targets filter
- reshuffle logging infra a bit to make sure there's only a single place
  where we read environmental variables
- use anyhow::Result in rust-analyzer binary
2023-06-18 13:59:32 +01:00
Lukas Wirth
c3186202a2 Shrink size of hir::Binding 2023-06-18 12:03:04 +02:00
hkalbasi
527dfede48 Support Pointee trait 2023-06-16 16:43:43 +03:30
hkalbasi
922be8714d Add more log in "terminator is none" assert 2023-06-15 12:05:15 +03:30
hkalbasi
e55a1f1916 Map our diagnostics to rustc and clippy's ones 2023-06-15 01:47:22 +03:30
Lukas Wirth
abe249559d internal: Give ConstBlockId and InTypeConstId named Location types 2023-06-12 18:21:17 +02:00
bors
6b3659d38f Auto merge of #15026 - lowr:fix/deduplicate-compl-fields, r=Veykril
fix: deduplicate fields and types in completion

Fixes #15024

- `hir_ty::autoderef()` (which is only meant to be used outside `hir-ty`) now deduplicates types and completely resolves inference variables within.
- field completion now deduplicates fields of the same name and only picks such field of the first type in the deref chain.
2023-06-12 12:53:53 +00:00
hkalbasi
a4695788ca Add a bunch of fixme comments 2023-06-12 00:37:11 +03:30
Ryo Yoshida
b4795507e3
autoderef: completely resolve and deduplicate types 2023-06-11 19:34:22 +09:00
hkalbasi
d9136df9e5 Handle return types for in type const bodies 2023-06-11 00:39:28 +03:30
hkalbasi
a481e004b0 Lower const params with a bad id 2023-06-11 00:39:28 +03:30
bors
49b4f15973 Auto merge of #15022 - HKalbasi:nightly-mir-eval-panic, r=HKalbasi
Fix panic in displaying unsized structs
2023-06-10 08:06:56 +00:00
hkalbasi
1dd76e8a9d Fix panic in displaying unsized structs 2023-06-10 11:32:37 +03:30
Lukas Wirth
ccce893577 Count query entries in memory usage command 2023-06-10 01:49:32 +02:00
hkalbasi
6fbf6ef514 Fix panic in displaying const trait objects 2023-06-10 02:10:52 +03:30
Ryo Yoshida
4f0c6fac17
fix: only generate trait bound for associated types in field types 2023-06-07 20:52:49 +09:00
bors
c6a3fe051a Auto merge of #14978 - HKalbasi:lifetime-display, r=HKalbasi
Emit `'_` for lifetime generics in `HirDisplay`

This makes the generated code not linted by `rust_2018_idioms` lint. But that is an allow by default lint, so should we do this? Maybe we should only do this for `DisplayTarget::SourceCode`?
2023-06-05 07:26:30 +00:00
hkalbasi
5531d46c95 Emit '_ for lifetime generics in HirDisplay 2023-06-05 10:55:47 +03:30
bors
2f1b7cedcf Auto merge of #14971 - lowr:fix/captured-item-ty-outer-binder, r=HKalbasi
fix: consider outer binders when folding captured items' type

Fixes #14966

Basically, the crash is caused by us producing a broken type and passing it to chalk: `&dyn for<type> [for<> Implemented(^1.0: A<^0.0>)]` (notice the innermost bound var `^0.0` has no corresponding binder). It's created in `CapturedItemWithoutTy::with_ty()`, which didn't consider outer binders when folding types to replace placeholders with bound variables.

The fix is one-liner, but I've also refactored the surrounding code a little.
2023-06-04 18:25:23 +00:00
hkalbasi
b4907a531f Fix missing terminator for slice pattern 2023-06-04 20:59:27 +03:30
hkalbasi
0408af6453 Fix unused-mut false positive for Box 2023-06-04 15:56:01 +03:30
Ryo Yoshida
f549cacc1d
Destructure InferenceResult in resolve_all()
so that whenever new fields are added we don't forget to handle them.
2023-06-04 20:38:40 +09:00
Ryo Yoshida
a3789eabc9
Minor refactorings
- use `DefWithBodyId::as_generic_def_id()`
- add comments on `InferenceResult` invariant
- move local helper function to bottom to comply with style guide
2023-06-04 19:39:49 +09:00
Ryo Yoshida
275afd6e79
fix: consider outer binders when folding captured items' type 2023-06-04 19:38:47 +09:00
hkalbasi
08f89193b5 Fix drop scopes in mir 2023-06-04 01:03:32 +03:30
hkalbasi
f44fc271d4 Remove unnecessary StorageDead 2023-06-03 17:24:10 +03:30
hkalbasi
aab7589c40 Fix string pattern matching in mir interpreter 2023-06-02 23:45:29 +03:30
bors
dfaca9398a Auto merge of #14950 - HKalbasi:render-const, r=HKalbasi
Support floating point intrinsics in const eval
2023-06-02 13:59:47 +00:00
hkalbasi
a6a27a7ff8 Support floating point intrinsics in const eval 2023-06-02 17:29:17 +03:30
bors
0677c204ca Auto merge of #14947 - HKalbasi:render-const, r=HKalbasi
Add enum, reference, array and slice to `render_const_scalar`
2023-06-02 10:18:36 +00:00
hkalbasi
f9e3b180b7 Add enum, reference, array and slice to render_const_scalar 2023-06-02 13:47:02 +03:30
Lukas Wirth
dc7c6d43c7 Slightly shrink DefMap 2023-06-01 14:46:36 +02:00
hkalbasi
51368793b4 MIR episode 6 2023-05-28 23:25:15 +03:30
Lukas Wirth
8bc826dd53 Add diagnostic for _ expressions (typed holes) 2023-05-28 14:55:28 +02:00
hkalbasi
cd4bffdd69 Evaluate UnevalutedConst before trait solving 2023-05-27 00:28:11 +03:30
Lukas Wirth
be9cc0baae Render size, align and offset hover values in hex 2023-05-26 16:41:45 +02:00
hkalbasi
c21d09f3cc insert type vars in function arguments 2023-05-26 14:26:13 +03:30
hkalbasi
780349bdaf fix need-mut false positive in closure capture of match scrutinee 2023-05-26 02:08:37 +03:30
hkalbasi
7ef185d65e evaluate UnevaluatedConst in unify 2023-05-25 19:37:20 +03:30
hkalbasi
b0f17668f7 use ::core instead of $crate in option_env! 2023-05-25 18:46:34 +03:30
Lukas Wirth
c7ef6c25b7 internal: Replace Display impl for Name 2023-05-24 20:55:12 +02:00
Ryo Yoshida
01f42d2405
fix: introduce new type var when expectation for ref pat is not ref 2023-05-22 23:13:41 +09:00
hkalbasi
92d6670f72 Consider block impls in lookup_impl_assoc_item_for_trait_ref 2023-05-20 01:11:17 +03:30
bors
bb78059be4 Auto merge of #14847 - HKalbasi:layout, r=HKalbasi
Reduce MIR memory usage
2023-05-19 12:06:11 +00:00
hkalbasi
60379dabfb resolve types in closure capture copy detection 2023-05-19 14:54:57 +03:30
hkalbasi
c5ea2d7adc handle match scrutinee in closure captures 2023-05-19 12:04:12 +03:30
hkalbasi
23ce228d54 Reduce MIR memory usage 2023-05-19 00:16:52 +03:30
hkalbasi
b55fbd3ad7 Add moved-out-of-ref diagnostic 2023-05-18 19:17:06 +03:30
hkalbasi
4adfbbfbad partially support panic message in MirEvalError 2023-05-18 18:30:49 +03:30
bors
9ce95674e8 Auto merge of #14837 - Veykril:rustc-lexer, r=Veykril
Support c string literals
2023-05-18 11:55:38 +00:00
Lukas Wirth
3e528b85f9 Fix cstring literals construct &CStr not &str 2023-05-18 12:03:15 +02:00
bors
034d7c8537 Auto merge of #14787 - HKalbasi:mir2, r=HKalbasi
MIR episode 5

This PR inits drop support (it is very broken at this stage, some things are dropped multiple time, drop scopes are wrong, ...) and adds stdout support (`println!` doesn't work since its expansion is dummy, but `stdout().write(b"hello world\n")` works if you use `RA_SYSROOT_HACK`) for interpreting. There is no useful unit test that it can interpret yet, but it is a good sign that it didn't hit a major road block yet.

In MIR lowering, it adds support for slice pattern and anonymous const blocks, and some fixes so that we can evaluate `SmolStr::new_inline` in const eval. With these changes, 57 failed mir body remains.
2023-05-18 09:44:26 +00:00
Lukas Wirth
eab295cc73 Fix mir CString lowering not respecting the extra 0 byte for length calc 2023-05-18 11:29:19 +02:00
Lukas Wirth
4b577e2bc8 Support c string literals 2023-05-18 11:06:05 +02:00
hkalbasi
261047d019 Fix layout for hir_ty::Ty and friends 2023-05-18 11:29:03 +03:30
bors
b7b026bce6 Auto merge of #14825 - HKalbasi:float-const-eval, r=Veykril
Fix evaluating negative for floating point types

fix #14704
Unary operators was missed from #14705
2023-05-18 05:22:41 +00:00
bors
a20a08f3e2 Auto merge of #14824 - Veykril:ty-diag-unit, r=Veykril
fix: Diagnose non-value return and break type mismatches

Could definitely deserve more polished diagnostics, but this at least brings the message across for now.
2023-05-18 05:03:42 +00:00
hkalbasi
fd034bea1a Fix evaluating negative for floating point types 2023-05-17 01:27:45 +03:30
Lukas Wirth
478705baf5 fix: Diagnose non-value return and break type mismatches 2023-05-16 22:47:27 +02:00
Lukas Wirth
08dc0e21af feat: Render hover actions for closure captures and sig 2023-05-15 19:35:27 +02:00
bors
2f8cd66fb4 Auto merge of #14810 - Veykril:inline-module, r=Veykril
internal: Inline handlers module
2023-05-15 10:19:21 +00:00
Lukas Wirth
9e80c8571d internal: Inline handlers module 2023-05-15 11:59:09 +02:00
hkalbasi
431dd32f8a Unsized temporary is not an implementation error 2023-05-14 21:05:33 +03:30
hkalbasi
cbcafd3539 MIR episode 5 2023-05-12 18:17:15 +03:30
bors
9b3387454d Auto merge of #14781 - lowr:patch/macro-subns-and-prelude, r=Veykril
Introduce macro sub-namespaces and `macro_use` prelude

This PR implements two mechanisms needed for correct macro name resolution: macro sub-namespace and `macro_use` prelude.

- [macro sub-namespaces][subns-ref]

  Macros have two sub-namespaces: one for function-like macro and the other for those in attributes (including custom derive macros). When we're resolving a macro name for function-like macro, we should ignore non-function-like macros, and vice versa.

  This helps resolve single-segment macro names because we can (and should, as rustc does) fallback to names in preludes when the name in the current module scope is in different sub-namespace.

- [`macro_use` prelude][prelude-ref]

  `#[macro_use]`'d extern crate declarations (including the standard library) bring their macros into scope, but they should not be prioritized over local macros (those defined in place and those explicitly imported).

  We have been bringing them into legacy (textual) macro scope, which has the highest precedence in name resolution. This PR introduces the `macro_use` prelude in crate-level `DefMap`s, whose precedence is lower than local macros but higher than the standard library prelude.

The first 3 commits are drive-by fixes/refactors.

Fixes #8828 (prelude)
Fixes #12505 (prelude)
Fixes #12734 (prelude)
Fixes #13683 (prelude)
Fixes #13821 (prelude)
Fixes #13974 (prelude)
Fixes #14254 (namespace)

[subns-ref]: https://doc.rust-lang.org/reference/names/namespaces.html#sub-namespaces
[prelude-ref]: https://doc.rust-lang.org/reference/names/preludes.html#macro_use-prelude
2023-05-11 14:26:59 +00:00
Ryo Yoshida
f2a35deb50
Consider macro sub-namespace during name resolution 2023-05-11 21:13:12 +09:00
Ryo Yoshida
34a9129333
fix: column!() and line!() built-in macros return u32 2023-05-11 21:13:05 +09:00
bors
d3ce333ec8 Auto merge of #14742 - Veykril:closure-capture-inlays, r=Veykril
feat: Closure capture inlay hints

I opted for a fictional `move(foo, &bar, &mut qux)` syntax here, disabled by default as these are not correct rust syntax and hence could cause confusion.
![image](https://user-images.githubusercontent.com/3757771/236447484-649a4ea6-ad61-496e-bad8-765a5236150e.png)
2023-05-08 09:52:29 +00:00