Commit Graph

241037 Commits

Author SHA1 Message Date
Michael Goulet
cb41509601 Uplift canonicalizer into new trait solver crate 2023-12-08 17:44:01 +00:00
Michael Goulet
11375c8657 Add tests 2023-12-08 17:23:26 +00:00
Michael Goulet
4c77058562 HACK: constrain yield type in check_fn so that projection is successful even with no yield 2023-12-08 17:23:26 +00:00
Michael Goulet
44911b7c67 Make some matches exhaustive to avoid bugs, fix tools 2023-12-08 17:23:26 +00:00
Michael Goulet
a208bae00e Support async gen fn 2023-12-08 17:23:26 +00:00
Michael Goulet
2806c2df7b coro_kind -> coroutine_kind 2023-12-08 17:23:25 +00:00
Michael Goulet
96bb542a31 Implement async gen blocks 2023-12-08 17:23:25 +00:00
Michael Goulet
a0cbc168c9 Rework coroutine transform to be more flexible in preparation for async generators 2023-12-08 17:23:25 +00:00
bors
2b399b5275 Auto merge of #118527 - Nadrieril:never_patterns_parse, r=compiler-errors
never_patterns: Parse match arms with no body

Never patterns are meant to signal unreachable cases, and thus don't take bodies:
```rust
let ptr: *const Option<!> = ...;
match *ptr {
    None => { foo(); }
    Some(!),
}
```
This PR makes rustc accept the above, and enforces that an arm has a body xor is a never pattern. This affects parsing of match arms even with the feature off, so this is delicate. (Plus this is my first non-trivial change to the parser).

~~The last commit is optional; it introduces a bit of churn to allow the new suggestions to be machine-applicable. There may be a better solution? I'm not sure.~~ EDIT: I removed that commit

r? `@compiler-errors`
2023-12-08 17:08:52 +00:00
bors
9e82ab54e8 Auto merge of #16055 - Veykril:field-fallback-method, r=Veykril
Fallback to method resolution on unresolved field access with matching method name

Allows typing out a method name without having to add calling parentheses to do IDE things on it. The inverse of this we already have.
2023-12-08 15:39:42 +00:00
Lukas Wirth
35fbc0210c Fallback to method resolution on unresolved field access with matching method name 2023-12-08 16:36:41 +01:00
Urgau
0f40b6545d Remove extra check-cfg handled by libc directly 2023-12-08 15:51:18 +01:00
bors
9c3de09f6d Auto merge of #16054 - Veykril:fix-downmapping, r=Veykril
fix: Fix token downmapping being quadratic

Fixes https://github.com/rust-lang/rust-analyzer/issues/16050
2023-12-08 14:28:18 +00:00
Lukas Wirth
5d951a6a46 fix: Fix token downmapping being quadratic 2023-12-08 15:26:38 +01:00
David Wood
5d97724002
privacy: visit trait def id of projections
A refactoring in #117076 changed the `DefIdVisitorSkeleton` to avoid
calling `visit_projection_ty` for `ty::Projection` aliases, and instead
just iterate over the args - this makes sense, as `visit_projection_ty`
will indirectly visit all of the same args, but in doing so, will also
create a `TraitRef` containing the trait's `DefId`, which also gets
visited. The trait's `DefId` isn't visited when we only visit the
arguments without separating them into `TraitRef` and own args first.

Signed-off-by: David Wood <david@davidtw.co>
2023-12-08 14:26:03 +00:00
lcnr
929782658e only return true in `fallback_types' if fallback has occurred 2023-12-08 14:50:07 +01:00
bors
ae612bedcb Auto merge of #118689 - compiler-errors:const-drop, r=fee1-dead
Fix const drop checking

Fixes confirmation of `~const Destruct` and const drops.

r? fee1-dead
2023-12-08 13:43:12 +00:00
lcnr
75cfeb1854 cleanup type variable storage 2023-12-08 14:28:57 +01:00
Krasimir Georgiev
b378059e6b update target feature following LLVM API change
LLVM commit e817966718
renamed the `unaligned-scalar-mem` target feature to `fast-unaligned-access`.
2023-12-08 13:06:07 +00:00
bors
b03a0bda18 Auto merge of #15627 - jmintb:sort_imports, r=Veykril
feat: Prioritize import suggestions based on the expected type

Hi, this is a draft PR to solve #15384. `Adt` types work and now I have a few questions :)

1. What other types make sense in this context? Looking at [ModuleDef](05666441ba/crates/hir/src/lib.rs (L275)) I am thinking everything except Modules.
2. Is there an existing way of converting between `ModeuleDef` and `hir::Type` in the rustanalyzer code base?
3. Does this approach seem sound to you?

Ups: Upon writing this I just realised that the enum test is invalided as there are no enum variants and this no variant is passed as a function argument.
2023-12-08 12:39:23 +00:00
Lukas Wirth
1475848250 Cleanup 2023-12-08 13:31:31 +01:00
bors
86cccc76e3 Auto merge of #16048 - Veykril:concat-bytes-fix, r=Veykril
fix: Fix concat_bytes! expansion emitting an identifier

Fixes https://github.com/rust-lang/rust-analyzer/issues/16046 (note that this has always been broken)
2023-12-08 12:27:58 +00:00
Zalathar
e01338aeb8 coverage: Regression test for unwrapping prev when there are no spans 2023-12-08 22:49:12 +11:00
Zalathar
cec814202a coverage: Add #[track_caller] to the span generator's unwrap methods
This should make it easier to investigate unwrap failures in bug reports.
2023-12-08 22:49:12 +11:00
Zalathar
e0cd8057c8 coverage: Simplify the heuristic for ignoring async fn return spans 2023-12-08 22:49:11 +11:00
Zalathar
d90fd027c8 coverage: Use SpanMarker to mark the full condition of if !
When MIR is built for an if-not expression, the `!` part of the condition
doesn't correspond to any MIR statement, so coverage instrumentation normally
can't see it.

We can fix that by deliberately injecting a dummy statement whose sole purpose
is to associate that span with its enclosing block.
2023-12-08 22:40:49 +11:00
Zalathar
98166358a9 coverage: Use SpanMarker to mark continue expressions.
This replaces the previous workaround, which was to inject a dummy `Assign`
statement.
2023-12-08 22:40:49 +11:00
Zalathar
44b47aa976 coverage: Add CoverageKind::SpanMarker for including extra spans in MIR
There are cases where coverage instrumentation wants to show a span for some
syntax element, but there is no MIR node that naturally carries that span, so
the instrumentor can't see it.

MIR building can now use this new kind of coverage statement to deliberately
include those spans in MIR, attached to a dummy statement that has no other
effect.
2023-12-08 22:40:49 +11:00
Zalathar
d2d742c4cc coverage: Add a dedicated test for coverage of if ! 2023-12-08 22:40:49 +11:00
Jessie Chatham Spencer
6abba17a5b Implement function type matching 2023-12-08 12:37:26 +01:00
Jessie Chatham Spencer
14a7a614c1 WIP - Sort suggested imports by type for data types 2023-12-08 12:37:26 +01:00
bors
6bbb2ac304 Auto merge of #15705 - rmehri01:14485_fix_delegate_self_references, r=Veykril
fix: resolve Self type references in delegate method assist

This PR makes the delegate method assist resolve any `Self` type references in the parameters or return type. It also works across macros such as the `uint_impl!` macro used for `saturating_mul` in the issue example.

Closes #14485
2023-12-08 11:31:34 +00:00
Ryan Mehri
7e768cbe70 fix: prefer keeping Self if it is in the same impl def 2023-12-08 12:30:14 +01:00
Ryan Mehri
f4349ff26e fix: preserve where clause in delegate method 2023-12-08 12:29:34 +01:00
Ryan Mehri
934358e95c fix: resolve Self type references in delegate method assist 2023-12-08 12:29:34 +01:00
bors
4f3d862fcf Auto merge of #15486 - petr-tik:n15134_hide_private_from_autocomplete_2, r=Veykril
fix: Fix item tree lowering pub(self) to pub()

Prior to this, the item tree lowered `pub(self)` visibility to `pub()`
Fix #15134 - tested with a unit test and
a manual end-to-end test of building rust-analyzer from my branch and opening the reproduction repository
2023-12-08 11:02:08 +00:00
Lukas Wirth
d54745aed3 fix: Fix item tree lowering pub(self) to pub() 2023-12-08 11:59:44 +01:00
petr-tik
2d879e0431 Stop offering private functions in completions
Before
Private functions have RawVisibility module, but were
missed because take_types returned None early. After resolve_visibility
returned None, Visibility::Public was set instead and private functions
ended up being offered in autocompletion.

Choosing such a function results in an immediate error diagnostic
about using a private function.

After
Pattern match of take_types that returns None and
query for Module-level visibility from the original_module

Fix #15134 - tested with a unit test and a manual end-to-end
test of building rust-analyzer from my branch and opening
the reproduction repository

REVIEW
Refactor to move scope_def_applicable and check function visibility
from a module

Please let me know what's the best way to add a unit tests to
nameres, which is where the root cause was
2023-12-08 11:38:54 +01:00
bors
5ae781562e Auto merge of #15515 - cardoso:flip-binexpr/lhs-binexpr, r=Veykril
Check if lhs is also a binexpr and use its rhs in flip binexpr assist

Closes #15508

From the original PR, flip binexpr assist is not meant to preserve equivalence, so I went with the simplest solution here.

I can add some extra checks to keep equivalence, but I think they should go in different specific assists (eg. flip arith op / flip logic op / etc), otherwise this one will get out of hand pretty quickly.
2023-12-08 10:38:03 +00:00
Matheus Cardoso
3d9221291f flip binexpr works for lhs cmp 2023-12-08 11:36:30 +01:00
Matheus Cardoso
e18b89452e Flip binexpr works for lhs binexpr 2023-12-08 11:36:30 +01:00
Lukas Wirth
71337f6682 fix: Fix concat_bytes! expansion 2023-12-08 11:34:03 +01:00
Nicholas Nethercote
5d16c5423c Extend tidy alphabetical checking to tests/.
This is desired for #118702.
2023-12-08 21:02:22 +11:00
bors
c27fc0c945 Auto merge of #15896 - minestarks:run-quickpick, r=Veykril
Show placeholder while run command gets runnables from server

This PR fixes a UI annoyance in the VS Code extension when working in large codebases where rust-analyzer can take a few moments to interact with the server. Scenario:

1. Invoke "rust-analyzer: Run" from the command palette or hotkey
2. Quickly start typing to filter the list (or press Enter to accept the last runnable)

We often do this quickly from muscle memory without waiting to see the picker. The picker often takes several seconds to come up, causing us to type garbage into the currently open editor.

Fix:

Show a placeholder item before we call out to the server.

![image](https://github.com/rust-lang/rust-analyzer/assets/16928427/09de6a1c-6f3c-4d29-8031-ba4baeb43282)

Selecting this item does nothing so if the user accidentally hits Enter nothing happens.

The list is populated and the placeholder dismissed when the actual runnables are retrieved. From here the behavior is the same as before.

![image](https://github.com/rust-lang/rust-analyzer/assets/16928427/837c7dfc-c060-4d68-bbf6-df8aa3101b78)
2023-12-08 10:00:37 +00:00
Lukas Wirth
143203b713 Make TraitEnvironment's constructor private 2023-12-08 10:47:36 +01:00
bors
5ea62560f2 Auto merge of #118668 - fmease:resolve-assoc-item-bindings-by-namespace, r=compiler-errors
Resolve associated item bindings by namespace

This is the 3rd commit split off from #118360 with tests reblessed (they no longer contain duplicated diags which were caused by 4c0addc80a) & slightly adapted (removed supertraits from a UI test, cc #118040).

> * Resolve all assoc item bindings (type, const, fn (feature `return_type_notation`)) by namespace instead of trying to resolve a type first (in the non-RTN case) and falling back to consts afterwards. This is consistent with RTN. E.g., for `Tr<K = {…}>` we now always try to look up assoc consts (this extends to supertrait bounds). This gets rid of assoc tys shadowing assoc consts in assoc item bindings which is undesirable & inconsistent (types and consts live in different namespaces after all)
> * Consolidate the resolution of assoc {ty, const} bindings and RTN (dedup, better diags for RTN)
> * Fix assoc consts being labeled as assoc *types* in several diagnostics
> * Make a bunch of diagnostics translatable

Fixes #112560 (error → pass).

As discussed
r? `@compiler-errors`

---

**Addendum**: What I call “associated item bindings” are commonly referred to as “type bindings” for historical reasons. Nowadays, “type bindings” include assoc type bindings, assoc const bindings and RTN (return type notation) which is why I prefer not to use this outdated term.
2023-12-08 09:30:52 +00:00
Ali MJ Al-Nasrawy
5fdb648fc3 temporarily revert "ice on ambguity in mir typeck"
Reverts #116530
2023-12-08 07:49:06 +00:00
bors
8043f62258 Auto merge of #118732 - matthiaskrgr:rollup-ub9pgjm, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #118505 (Elaborate on ip_addr bit conversion endianness)
 - #118581 (OnceLock: Add note about drop and statics)
 - #118677 ([rustdoc] Fix display of features)
 - #118690 (coverage: Avoid unnecessary macros in unit tests)
 - #118693 (Tell MirUsedCollector that the pointer alignment checks calls its panic symbol)
 - #118695 (coverage: Merge refined spans in a separate final pass)
 - #118709 (fix jobserver GLOBAL_CLIENT_CHECKED uninitialized before use)
 - #118722 (rustdoc: remove unused parameter `reversed` from onEach(Lazy))

r? `@ghost`
`@rustbot` modify labels: rollup
2023-12-08 07:12:26 +00:00
Matthias Krüger
9dd34d5945
Rollup merge of #118722 - notriddle:notriddle/dom-opt-3, r=GuillaumeGomez
rustdoc: remove unused parameter `reversed` from onEach(Lazy)

This feature was added in edec5807ac to support JavaScript-based toggles that were later replaced with HTML `<details>`.
2023-12-08 06:44:44 +01:00
Matthias Krüger
beabb5e2e3
Rollup merge of #118709 - oksbsb:fix-job-server, r=SparrowLii
fix jobserver GLOBAL_CLIENT_CHECKED uninitialized before use

override #118589, resolve merge conflict

`@petrochenkov` `@SparrowLii`

Thanks!
2023-12-08 06:44:43 +01:00