Commit Graph

121 Commits

Author SHA1 Message Date
Lukas Wirth
9f233cd5d2 Parse more repr options 2022-09-20 17:12:27 +02:00
Lukas Wirth
6d0d051628 Simplify 2022-09-20 17:12:10 +02:00
bors
817a6a8609 Auto merge of #12966 - OleStrohm:master, r=Veykril
feat: Display the value of enum variant on hover

fixes #12955

This PR adds const eval support for enums, as well as showing their value on hover, just as consts currently have.

I developed these two things at the same time, but I've realized now that they are separate. However since the hover is just a 10 line change (not including tests), I figured I may as well put them in the same PR. Though if you want them split up into "enum const eval support"  and "show enum variant value on hover", I think that's reasonable too.

Since this adds const eval support for enums this also allows consts that reference enums to have their values computed now too.

The const evaluation itself is quite rudimentary, it doesn't keep track of the actual type of the enum, but it turns out that Rust doesn't actually either, and `E::A as u8` is valid regardless of the `repr` on `E`.

It also doesn't really care about what expression the enum variant contains, it could for example be a string, despite that not being allowed, but I guess it's up to the `cargo check` diagnostics to inform of such issues anyway?
2022-09-20 14:01:16 +00:00
Ryo Yoshida
9845e37f58
Ensure at least one trait bound in TyKind::DynTy 2022-09-20 04:37:34 +09:00
OleStrohm
f87ad8df05 Added FIXME for the repr type of the enum 2022-09-19 19:26:35 +01:00
Laurențiu Nicola
e54f61dbdb Try to fix crash introduced in #13147 2022-09-19 12:45:38 +03:00
bors
ba15f75c39 Auto merge of #13225 - lowr:fix/hir-proj-normalization, r=Veykril
fixup: remove unnecessary `Option`

Fixup for #13223, two things:

- `normalize_projection_query()` (and consequently `HirDatabase::normalize_projection()`) never returns `None` (well, it used to when I first wrote it...), so just return `Ty` instead of `Option<Ty>`
- When chalk cannot normalize projection uniquely, `normalize_trait_assoc_type()` used to return `None` before #13223, but not anymore because of the first point. I restored the behavior so its callers work as before.
2022-09-13 14:52:58 +00:00
OleStrohm
5313bd1984 Cleaned up code based on feedback 2022-09-12 20:20:45 +01:00
OleStrohm
301b8894ea Added more consteval tests and fixed consteval result 2022-09-12 20:20:45 +01:00
OleStrohm
ad0a6bf1a3 Added consteval tests 2022-09-12 20:20:43 +01:00
OleStrohm
2f84b6e2e5 Almost there 2022-09-12 20:20:22 +01:00
OleStrohm
b63234e20b Cleaned up code 2022-09-12 20:19:49 +01:00
OleStrohm
e28046c673 Removed unnecessary TODO 2022-09-12 20:19:19 +01:00
OleStrohm
997fc46efa Implemented basic enum const eval 2022-09-12 20:19:13 +01:00
Ryo Yoshida
d223c28c7d
Remove unnecessary Option 2022-09-13 02:20:35 +09:00
bors
b1a4ba3e84 Auto merge of #13223 - lowr:fix/hir-proj-normalization, r=flodiebold
fix: handle lifetime variables in projection normalization

Fixes #12674

The problem is that we've been skipping the binders of normalized projections assuming they should be empty, but the assumption is unfortunately wrong. We may get back lifetime variables and should handle them before returning them as normalized projections. For those who are curious why we get those even though we treat all lifetimes as 'static, [this comment in chalk](d875af0ff1/chalk-solve/src/infer/unify.rs (L888-L908)) may be interesting.

I thought using `InferenceTable` would be cleaner than the other ways as it already has the methods for canonicalization, normalizing projection, and resolving variables, so moved goal building and trait solving logic to a new `HirDatabase` query. I made it transparent query as the query itself doesn't do much work but the eventual call to `HirDatabase::trait_solve_query()` does.
2022-09-12 14:24:57 +00:00
Ryo Yoshida
efb56160c9
fix: handle lifetime variables in projection normalization 2022-09-12 22:52:58 +09:00
bors
7a704f2cc7 Auto merge of #13147 - lowr:fix/dyn-ty-inherent-methods, r=Veykril
fix: handle trait methods as inherent methods for trait-related types

Fixes #10677

When resolving methods for trait object types and placeholder types that are bounded by traits, we need to count the methods of the trait and its super traits as inherent methods. This matters because these trait methods have higher priority than the other traits' methods.

Relevant code in rustc: [`assemble_inherent_candidates_from_object()`](0631ea5d73/compiler/rustc_typeck/src/check/method/probe.rs (L783-L792)) for trait object types, [`assemble_inherent_candidates_from_param()`](0631ea5d73/compiler/rustc_typeck/src/check/method/probe.rs (L838-L847)) for placeholder types. Notice the second arg of `push_candidate()` is `is_inherent`.
2022-09-12 12:19:14 +00:00
bors
352a5b8625 Auto merge of #13212 - Veykril:no-std-config, r=Veykril
Add config to unconditionally prefer core imports over std

Fixes https://github.com/rust-lang/rust-analyzer/issues/12979
2022-09-12 11:51:31 +00:00
Borys Minaiev
32603baac3 Remove redundant 'resolve_obligations_as_possible' call 2022-09-12 11:03:44 +01:00
Lukas Wirth
7d19971666 Add config to unconditionally prefer core imports over std
Fixes https://github.com/rust-lang/rust-analyzer/issues/12979
2022-09-09 20:04:56 +02:00
Ryo Yoshida
265c75c53f
fix: sort all bounds on trait object types 2022-09-05 19:13:32 +09:00
Lukas Wirth
020f6895e5 Fix nested break expressions, expecting unknown types 2022-09-03 17:32:21 +02:00
Lukas Wirth
8828049b23 Lift out the module scope into a field in the Resolver
A Resolver *always* has a module scope at the end of its scope stack,
instead of encoding this as an invariant we can just lift this scope
out into a field, allowing us to skip going through the scope vec
indirection entirely.
2022-09-02 17:02:12 +02:00
bors
4f8153e4a5 Auto merge of #13167 - iDawer:exhaustive_patterns, r=Veykril
feat: Implement `feature(exhaustive_patterns)` from unstable Rust

Closes #12753

Recognize Rust's unstable `#![feature(exhaustive_patterns)]` (RFC 1872). Allow omitting visibly uninhabited variants from `match` expressions when the feature is on.

This adjusts match checking to the current implementation of the postponed RFC 1872 in rustc.
2022-09-02 12:32:36 +00:00
iDawer
ffd79c2887 Add docs 2022-09-02 17:01:51 +05:00
iDawer
8ae58b9fe4 Record enabled unstable features into DefMap 2022-09-02 16:31:15 +05:00
Lukas Wirth
8110119fef Properly handle break resolution inside non-breakable expressions 2022-09-01 14:54:47 +02:00
Lukas Wirth
1e66a5a8ce Diagnose incorrect continue expressions 2022-09-01 14:41:38 +02:00
Lukas Wirth
d6fc4a9ea6 Simplify breakables handling 2022-09-01 14:41:37 +02:00
iDawer
1fa9d5e07b Correct visibility check 2022-08-31 21:41:24 +05:00
Lukas Wirth
ee02a4721b Remove unnecessary allocations 2022-08-31 18:05:52 +02:00
iDawer
1a580a3396 Implement unstable RFC 1872 exhaustive_patterns 2022-08-31 20:17:54 +05:00
Lukas Wirth
192a79c235 Remove hir::Expr::MacroStmts
This hir expression isn't needed and only existed as it was simpler to
deal with at first as it gave us a direct mapping for the ast version of
the same construct. This PR removes it, properly handling the statements
that are introduced by macro call expressions.
2022-08-31 16:58:11 +02:00
bors
56d888689b Auto merge of #12793 - lowr:fix/12739, r=Veykril
fix: sort and deduplicate auto traits in trait object types

Fixes #12739

Chalk solver doesn't sort and deduplicate auto traits in trait object types, so we need to handle them ourselves in the lowering phase, just like [`rustc`](880416180b/compiler/rustc_typeck/src/astconv/mod.rs (L1487-L1488)) and [`chalk-integration`](https://github.com/rust-lang/chalk/blob/master/chalk-integration/src/lowering.rs#L575) do.

Quoting from [the Chalk book](https://rust-lang.github.io/chalk/book/types/rust_types.html#dyn-types):

> Note that -- for this purpose -- ordering of bounds is significant. That means that if you create a `dyn Foo + Send` and a `dyn Send + Foo`, chalk would consider them distinct types. The assumption is that bounds are ordered in some canonical fashion somewhere else.

Also, trait object types with more than one non-auto traits were previously allowed, but are now disallowed with this patch.
2022-08-31 08:28:12 +00:00
Lukas Wirth
5c0e25237c Drop the expander borrow in all control flow paths
The change in https://github.com/rust-lang/rust-analyzer/pull/13123
actually re-uses the RefMut borrow instead of dropping it so we need to
drop it manually where required.
2022-08-31 10:04:01 +02:00
Ryo Yoshida
484d5b6e70
fix: handle trait methods as inherent methods for placeholders 2022-08-31 01:12:14 +09:00
Ryo Yoshida
7ecead23c8
fix: sort and deduplicate auto traits in trait object types 2022-08-30 20:52:42 +09:00
Ryo Yoshida
f9e2ac56e5
fix: handle trait methods as inherent methods for trait object types 2022-08-30 20:44:31 +09:00
Lukas Wirth
78a7a816bf minor: Simplify 2022-08-26 19:40:01 +02:00
Lukas Wirth
d025c5d8d6 Make use of NoHash hashing for FileId and CrateId 2022-08-25 20:41:49 +02:00
bors
fdc28b4333 Auto merge of #13021 - N3xed:fix-gat-panics, r=flodiebold
fix: Fix panics on GATs involving const generics

This workaround avoids constant crashing of rust analyzer when using GATs with const generics,
even when the const generics are only on the `impl` block.

The workaround treats GATs as non-existing if either itself or the parent has const generics and
removes relevant panicking code-paths.

Fixes #11989, fixes #12193
2022-08-22 14:00:23 +00:00
Dominik Gschwind
ac8cb8ce3b
Expect the test to panic by catching the unwind 2022-08-21 22:48:53 +02:00
Ryo Yoshida
dd22aa48ba
Consider bounds on inherent impl in method resolution 2022-08-21 18:41:46 +09:00
Laurențiu Nicola
c3bb7bfc28 Bump chalk 2022-08-19 21:33:28 +03:00
bors
0a33d04a3d Auto merge of #13053 - lowr:fix/pat-sole-Self, r=Veykril
fix: resolve path `Self` alone in value namespace

Fixes #12968
2022-08-18 11:17:40 +00:00
Ryo Yoshida
dac27679f7
fix: resolve path Self alone in value namespace 2022-08-18 20:12:59 +09:00
bors
1da9156b0d Auto merge of #12982 - jridgewell:into_future, r=Veykril
Implement IntoFuture type inference

One of my projects is using [IntoFuture](https://doc.rust-lang.org/std/future/trait.IntoFuture.html) to make our async code a little less verbose. However, rust-analyzer can't infer the output type of an await expression if the value uses `IntoFuture` to convert into another type. So we're getting `{unknown}` types everywhere since switching.

`foo.await` itself [desugars](e4417cf020/compiler/rustc_ast_lowering/src/expr.rs (L644-L658)) into a `match into_future(foo) {}`, with every `Future` impl getting a [default](e4417cf020/library/core/src/future/into_future.rs (L131-L139)) `IntoFuture` implementation. I'm not sure if we want to disable the old `future_trait` paths, since this only recently [stabilize](https://github.com/rust-lang/rust/pull/98718).
2022-08-18 07:37:47 +00:00
Ryo Yoshida
12abaf8ddd
fix: resolve associated types of bare dyn types 2022-08-18 07:05:41 +09:00
Dominik Gschwind
ad7a1ed8cc
fix: Fix panics on GATs involving const generics
This workaround avoids constant crashing of rust analyzer when using GATs with const generics,
even when the const generics are only on the `impl` block.

The workaround treats GATs as non-existing if either itself or the parent has const generics and
removes relevant panicking code-paths.
2022-08-16 17:30:17 +02:00