Commit graph

687 commits

Author SHA1 Message Date
Chayim Refael Friedman
0d43932235 Fix a stack overflow when computing the sizedness of a struct that includes itself as the tail field 2024-11-25 20:49:35 +02:00
Laurențiu Nicola
aabab29274
Merge pull request #18482 from regexident/hir_trait_supertraits_accessors
internal: Add public `direct_supertraits(…)` & `all_supertraits(…)` accessor methods to `hir::Trait`
2024-11-11 06:58:17 +00:00
Laurențiu Nicola
1042a8c22c
Merge pull request #18490 from ShoyuVanilla/dyn-compat-rename
minor: Rename `dyn compatible` to `dyn-compatible`
2024-11-07 14:21:40 +00:00
Shoyu Vanilla
05e5f9e4fd minor: Rename dyn compatible to dyn-compatible 2024-11-07 23:00:29 +09:00
Vincent Esche
c1155213f3 Add pub fn direct_super_traits(db, trait_id) to hir_ty crate 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
Laurențiu Nicola
b385bf2e53 Format code 2024-11-01 14:12:18 +02:00
Laurențiu Nicola
fabe447c7d Merge from rust-lang/rust 2024-11-01 13:14:25 +02:00
Chayim Refael Friedman
4317927231 Avoid interior mutability in TyLoweringContext
This requires some serious code juggling.
2024-10-30 21:24:19 +02:00
Jubilee Young
92faf55954 rust-analyzer: rustc_abi::Abi => BackendRepr 2024-10-29 15:01:01 -07:00
Lukas Wirth
3fd6a72556
Merge pull request #18427 from ChayimFriedman2/cleanup-ty
Cleanup TypeRef lowering
2024-10-29 10:00:44 +00:00
Laurențiu Nicola
779074df51 Merge from rust-lang/rust 2024-10-29 08:13:34 +02: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
Jubilee Young
f806406728 rust-analyzer: Rename LayoutS to LayoutData 2024-10-27 22:32:58 -07:00
MoskalykA
feba680c39 Use method syntax 2024-10-26 09:39:04 +03:00
MoskalykA
41fa877362 Start using Option::is_none_or 2024-10-26 09:39:04 +03: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
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
Chayim Refael Friedman
4ac3dc1a2f Correctly resolve variables and labels from before macro definition in macro expansion
E.g.:
```rust
let v;
macro_rules! m { () => { v }; }
```

This was an existing bug, but it was less severe because unless the variable was shadowed it would be correctly resolved. With hygiene however, without this fix the variable is never resolved.
2024-10-22 21:49:17 +03: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
c58427ff94 Auto merge of #18371 - Veykril:veykril/push-kwttrusywysp, r=Veykril
fix: Fix incorrect parsing of use bounds

Fixes https://github.com/rust-lang/rust-analyzer/issues/18357
2024-10-22 11:42:11 +00:00
Lukas Wirth
95298a2e61 fix: Fix incorrect parsing of use bounds
Also lower them a bit more
2024-10-22 13:34:26 +02:00
Lukas Wirth
6c23f25e7f Fix new nightly lints 2024-10-22 11:48:41 +02:00
Laurențiu Nicola
a32039278f Replace some LayoutError variants with the rustc_abi errors 2024-10-22 10:19:25 +03:00
Laurențiu Nicola
250bf98d58 Merge from rust-lang/rust 2024-10-22 10:12:22 +03:00
Lukas Wirth
1cdc34fa4a Fix recursive_adt fixture 2024-10-21 11:28:18 +02:00
Noratrieb
6a2b8270c9 Update rustc-hash to version 2
This brings in the new optimized algorithm that was shown to have small performance benefits for
rustc.
2024-10-21 11:28:18 +02:00
roife
834ccbffba fix: classify safe as a contextual kw 2024-10-21 02:56:21 +08: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
Chayim Refael Friedman
61f162a43d Handle destructuring assignments uniformly
Instead of lowering them to `<expr> = <expr>`, then hacking on-demand to resolve them, we lower them to `<pat> = <expr>`, and use the pattern infrastructure to handle them. It turns out, destructuring assignments are surprisingly similar to pattern bindings, and so only minor modifications are needed.

This fixes few bugs that arose because of the non-uniform handling (for example, MIR lowering not handling slice and record patterns, and closure capture calculation not handling destructuring assignments at all), and furthermore, guarantees we won't have such bugs in the future, since the programmer will always have to explicitly handle `Expr::Assignment`.

Tests don't pass yet; that's because the generated patterns do not exist in the source map. The next commit will fix that.
2024-10-20 19:09:51 +03:00
roife
002f6ad6f1 fix: do not emit unsafe diagnositcs for safe statics in extern blocks 2024-10-20 19:49:57 +08:00
roife
9f1e450c4f feat: initial support for safe_kw in extern blocks 2024-10-20 17:12:52 +08:00
Stuart Cook
d6350f60f7
Rollup merge of #131942 - workingjubilee:reduce-haruspicy, r=lukas-code,lnicola
compiler: Adopt rust-analyzer impls for `LayoutCalculatorError`

We're about to massively churn the internals of `rustc_abi`. To minimize the immediate and future impact on rust-analyzer, as a subtree that depends on this crate, grow some API on `LayoutCalculatorError` that reflects their uses of it. This way we can nest the type in theirs, and they can just call functions on it without having to inspect and flatten-out its innards.
2024-10-20 14:06:04 +11:00
Jubilee Young
90ec8053c2 rust-analyzer: Nest LayoutCalculatorError in hir_ty::LayoutError 2024-10-19 11:09:24 -07:00
Lukas Wirth
c11b45a6bd internal: Add more trivially Sized types to is_sized check 2024-10-18 12:41:14 +02:00
Shoyu Vanilla
91293ea4d4 Do not consider match/let/ref of place that evaluates to ! to diverge, disallow coercions from them too 2024-10-15 00:37:40 +09:00
David Barsky
ccee36e8dd chore: rename salsa to ra_salsa 2024-10-14 10:09:22 -04:00
bors
9f1f5cd8f6 Auto merge of #18252 - ShoyuVanilla:issue-15799, r=Veykril
fix: Do not consider mutable usage of deref to `*mut T` as deref_mut

Fixes #15799

We are doing some heuristics for deciding whether the given deref is deref or deref_mut here;

5982d9c420/crates/hir-ty/src/infer/mutability.rs (L182-L200)

But this heuristic is erroneous if we are dereferencing to a mut ptr and normally those cases are filtered out here as builtin;

5982d9c420/crates/hir-ty/src/mir/lower/as_place.rs (L165-L177)

Howerver, this works not so well if the given dereferencing is double dereferencings like the case in the #15799.

```rust
struct WrapPtr(*mut u32);

impl core::ops::Deref for WrapPtr {
    type Target = *mut u32;
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

fn main() {
    let mut x = 0u32;
    let wrap = WrapPtr(&mut x);
    unsafe {
        **wrap = 6;
    }
}
```

Here are two - outer and inner - dereferences here, and the outer dereference is marked as deref_mut because there is an assignment operation.
And this deref_mut marking is propagated into the inner dereferencing.
In the later MIR lowering, the outer dereference is filtered out as it's expr type is `*mut u32`, but the expr type in the inner dereference is an ADT, so this false-mutablility is not filtered out.

This PR cuts propagation of this false mutablilty chain if the expr type is mut ptr.
Since this happens before the resolve_all, it may have some limitations when the expr type is determined as mut ptr at the very end of inferencing, but I couldn't find simple fix for it 🤔
2024-10-14 12:07:31 +00:00
bors
574c89155b Auto merge of #18217 - ChayimFriedman2:cast-unknown-ptr, r=Veykril
fix: Comment out cast checks for unknown ptr kind

Just like we don't check for types containing unknown.

Fixes #18214.

See also https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/Another.20case.20of.20.2318064.3F.
2024-10-14 11:24:08 +00:00
Jake
9434ceba40
include fn prefix for all callable defs 2024-10-08 11:37:08 -07:00
Jake
5cba3e72bc
hir-ty: change struct constructor formatting.
before, when formatting struct constructor for `struct S(usize, usize)` it would format as:

    extern "rust-call" S(usize, usize) -> S

but after this change, we'll format as:

    fn S(usize, usize) -> S
2024-10-08 11:05:03 -07:00
Chayim Refael Friedman
13f853464c Use external stack in borrowck DFS
Because damnit, it can crash r-a. Why do people make this stupid DFSes anyway (I get it, it's easier until it blows).
2024-10-06 23:48:16 +03:00
Shoyu Vanilla
d3446a78a0 fix: Do not consider mutable usage of deref to *mut T as deref_mut 2024-10-07 01:49:14 +09:00
Chayim Refael Friedman
ff3c95f414 Comment out cast checks for unknown ptr kind
Just like we don't check for types containing unknown.
2024-09-30 19:26:16 +03:00
bors
7b60339273 Auto merge of #18207 - mbwilding:master, r=Veykril
fix: Ambiguity with CamelCase diagnostic messages, align with rustc warnings

Fixed diagnostic messages so they say UpperCamelCase rather than CamelCase, as it is ambiguous.
Usually I'd call it PascalCase, but in the code base it is called UpperCamelCase so I left it with that naming choice.

`rustc` says `upper camel case` also when the case is wrong
```
warning: trait `testThing` should have an upper camel case name
 --> src/main.rs:5:7
  |
5 | trait testThing {
  |       ^^^^^^^^^ help: convert the identifier to upper camel case: `TestThing`
  |
  = note: `#[warn(non_camel_case_types)]` on by default
```

This is in line with the UPPER_SNAKE_CASE diagnostic messages.
546339a7be/crates/hir-ty/src/diagnostics/decl_check.rs (L60)
546339a7be/crates/ide-diagnostics/src/handlers/incorrect_case.rs (L535)
2024-09-30 08:22:29 +00:00