Commit Graph

214590 Commits

Author SHA1 Message Date
Mateusz Guzik
b49aa8d53e Stop probing for statx unless necessary
As is the current toy program:
fn main() -> std::io::Result<()> {
    use std::fs;

    let metadata = fs::metadata("foo.txt")?;

    assert!(!metadata.is_dir());
    Ok(())
}

... observed under strace will issue:
[snip]
statx(0, NULL, AT_STATX_SYNC_AS_STAT, STATX_ALL, NULL) = -1 EFAULT (Bad address)
statx(AT_FDCWD, "foo.txt", AT_STATX_SYNC_AS_STAT, STATX_ALL, {stx_mask=STATX_ALL|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFREG|0644, stx_size=0, ...}) = 0

While statx is not necessarily always present, checking for it can be
delayed to the first error condition. Said condition may very well never
happen, in which case the check got avoided altogether.

Note this is still suboptimal as there still will be programs issuing
it, but bulk of the problem is removed.

Tested by forbidding the syscall for the binary and observing it
correctly falls back to newfstatat.

While here tidy up the commentary, in particular by denoting some
problems with the current approach.
2023-01-11 17:10:08 +00:00
Mateusz Guzik
753e576722 Fix up stat test in libc-fs-with-isolation
The test relied on Error::last_os_error() coming from the stat call on
the passed file, but there is no guarantee this will be the case.

Instead extract errno from the error returned by the routine.

Patch de facto written by joboet.

Co-authored-by:	joboet <jonasboettiger@icloud.com>
2023-01-11 17:09:12 +00:00
bors
3254bef9a7 Auto merge of #105855 - arcnmx:rust-analyzer-2022-12, r=lnicola
⬆️ rust-analyzer

Updates rust-analyzer to 368e0bb32f

This is a continuation/replacement of #105834, close that if this is chosen instead.
2023-01-09 21:14:32 +00:00
arcnmx
06e705f13d ⬆️ rust-analyzer
Merge commit '368e0bb32f1178cf162c2ce5f7e10b7ae211eb26'
2023-01-09 10:36:22 -08:00
bors
3020239de9 Auto merge of #106637 - fee1-dead-contrib:rollup-ticvmsd, r=fee1-dead
Rollup of 10 pull requests

Successful merges:

 - #105292 (Change a commit_if_ok call to probe)
 - #105655 (Remove invalid case for mutable borrow suggestion)
 - #106047 (Fix ui constant tests for big-endian platforms)
 - #106061 (Enable Shadow Call Stack for Fuchsia on AArch64)
 - #106164 (Move `check_region_obligations_and_report_errors` to `TypeErrCtxt`)
 - #106291 (Fix incorrect suggestion for extra `&` in pattern)
 - #106389 (Simplify some canonical type alias names)
 - #106468 (Use FxIndexSet when updating obligation causes in `adjust_fulfillment_errors_for_expr_obligation`)
 - #106549 (Use fmt named parameters in rustc_borrowck)
 - #106614 (error-code docs improvements (No. 2))

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-01-09 18:20:00 +00:00
bors
368e0bb32f Auto merge of #13848 - ian-h-chamberlain:feature/color-compiler-diagnostics, r=ian-h-chamberlain
Colorize `cargo check` diagnostics in VSCode via text decorations

Fixes #13648

![colored-rustc-diagnostics](https://user-images.githubusercontent.com/11131775/209479884-10eef8ca-37b4-4aae-88f7-3591ac01b25e.gif)

Use ANSI control characters to display text decorations matching the VScode terminal theme, and strip them out when providing text content for rustc diagnostics.

This adds the small [`anser`](https://www.npmjs.com/package/anser) library (MIT license, no dependencies) to parse the control codes, and it also supports HTML output so it should be fairly easy to switch to a rendered HTML/webview implementation in the future

I also updated the default `cargo check` command to use the rendered ANSI diagnostics, although I'm not sure if it makes sense to put this kind of thing behind a feature flag, or whether it might have any issues on Windows (as I believe ANSI codes are not used for colorization there)?
2023-01-09 17:07:35 +00:00
Ian Chamberlain
283dfc45dd
Add docs for colorDiagnosticOutput capability 2023-01-09 11:50:37 -05:00
Ian Chamberlain
65cf7abbe2
Use experimental capability to enable color codes 2023-01-09 11:50:35 -05:00
Ian Chamberlain
738ce83d85
Strip colors before matching preview diagnostics 2023-01-09 11:49:59 -05:00
Ian Chamberlain
c3e4bc3136
Update docs to include note about ANSI diagnostics 2023-01-09 11:49:58 -05:00
Ian Chamberlain
40207906f4
Default to use colored ANSI diagnostics 2023-01-09 11:46:29 -05:00
Ian Chamberlain
1b8141b54c
Parse + decorate rendered ANSI cargo output
Use ANSI control characters to display text decorations matching the
VScode terminal theme, and strip them out when providing text content
for rustc diagnostics.

This adds the small `anser` library to parse the control codes, and it
also supports HTML output so it should be fairly easy to switch to a
rendered HTML/webview implementation if desired.
2023-01-09 11:46:29 -05:00
bors
f32e20edb9 Auto merge of #13915 - Veykril:lsp-server-msg, r=Veykril
Make it clearer when the server expects an initialized notification
2023-01-09 16:04:04 +00:00
Lukas Wirth
9eb50d3cde Make it clearer when the server expects an initialized notification 2023-01-09 17:03:36 +01:00
bors
fd300eebc9 Auto merge of #13799 - Veykril:flycheck, r=Veykril
Rename `checkOnSave` settings to `check`

Now that flychecks can be triggered without saving the setting name doesn't make that much sense anymore. This PR renames it to just `check`, but keeps `checkOnSave` as the enabling setting.
2023-01-09 15:35:38 +00:00
fee1-dead
77f529bb0a
Rollup merge of #106614 - Ezrashaw:ui-test-fixups-2, r=GuillaumeGomez
error-code docs improvements (No. 2)

- Added empty error-code docs for `E0208`, `E0640` and `E0717` with the "internal" header as discussed on Discord.
- Wrote docs and UI test for `E0711`, again with the header.
- `tidy` changes are common-sense and make everything pass, `style.rs` hack is annoying though.

r? ```@GuillaumeGomez```
2023-01-09 23:35:32 +08:00
fee1-dead
99529b0cd2
Rollup merge of #106549 - wcampbell0x2a:use-fmt-named-parameters-borrowck, r=estebank
Use fmt named parameters in rustc_borrowck
2023-01-09 23:35:31 +08:00
fee1-dead
357128ad23
Rollup merge of #106468 - compiler-errors:err-instability, r=lcnr
Use FxIndexSet when updating obligation causes in `adjust_fulfillment_errors_for_expr_obligation`

I have no idea how to test this reliably, but I've **manually** verified it fixes the instability in #106417 that isn't due to dtolnay/trybuild#212.

Fixes #106417
2023-01-09 23:35:31 +08:00
fee1-dead
f8319bb403
Rollup merge of #106389 - compiler-errors:no-canonicalized, r=lcnr
Simplify some canonical type alias names

* delete the `Canonicalized<'tcx>` type alias in favor for `Canonical<'tcx>`
* `CanonicalizedQueryResponse` -> `CanonicalQueryResponse`

I don't particularly care about the latter, but it should be consistent. We could alternatively delete the first alias and rename the struct to `Canonicalized`, and then keep the name of `CanonicalizedQueryResponse` untouched.
2023-01-09 23:35:30 +08:00
fee1-dead
37c1d6dc09
Rollup merge of #106291 - obeis:issue-106182, r=oli-obk
Fix incorrect suggestion for extra `&` in pattern

Closes #106182
2023-01-09 23:35:29 +08:00
fee1-dead
7779386a3a
Rollup merge of #106164 - compiler-errors:check-region-tweak, r=oli-obk
Move `check_region_obligations_and_report_errors` to `TypeErrCtxt`

Makes sense for this function to live with its sibling `resolve_regions_and_report_errors`, around which it's basically just a wrapper.
2023-01-09 23:35:29 +08:00
fee1-dead
fd75cfef66
Rollup merge of #106061 - ilovepi:fuchsia-scs, r=oli-obk
Enable Shadow Call Stack for Fuchsia on AArch64

Fuchsia already uses SCS by default for C/C++ code on ARM hardware. This patch allows SCS to be used for Rust code as well.
2023-01-09 23:35:28 +08:00
fee1-dead
63f2a13855
Rollup merge of #106047 - uweigand:s390x-test-bigendian-ui, r=oli-obk
Fix ui constant tests for big-endian platforms

A number of tests under ui/const-ptr and ui/consts are currently failing on big-endian platforms as the binary encoding of some constants is hard-coded in the stderr test files.

Fix this by a combination of two types of changes:

- Where possible (i.e. where the particular value of a constant does not affect the purpose of the test), choose constant values that have the same encoding on big- and little-endian platforms.

- Where this is not possible, provide a normalize-stderr-test rule that transforms the printed big-endian encoding of such constants into the corresponding little-endian form.

Fixes part of https://github.com/rust-lang/rust/issues/105383.
2023-01-09 23:35:27 +08:00
fee1-dead
c1f8a3ffb2
Rollup merge of #105655 - RedDocMD:bug-105645, r=oli-obk
Remove invalid case for mutable borrow suggestion

If we have a call such as `foo(&mut buf)` and after reference
collapsing the type is inferred as `&T` where-as the required type is
`&mut T`, don't suggest `foo(&mut mut buf)`. This is wrong syntactically
and the issue lies elsewhere, not in the borrow.

Fixes #105645
2023-01-09 23:35:27 +08:00
fee1-dead
b7587f1867
Rollup merge of #105292 - JulianKnodt:no_eager_commit, r=BoxyUwU
Change a commit_if_ok call to probe

Removes an over-eager `commit_if_ok` which makes inference worse.

I'm not entirely sure whether it's ok to remove the check that types are the same, because casting seems to cause equality checks with incorrect types?

Fixes #105037

r? ```@BoxyUwU```
2023-01-09 23:35:26 +08:00
bors
af58fc8699 Auto merge of #101947 - aliemjay:astconv-normalize, r=lcnr
Don't normalize in AstConv

See individual commits.

Fixes #101350
Fixes #54940
2023-01-09 15:29:59 +00:00
bors
f920b03c6c Auto merge of #13914 - WaffleLapkin:qualify_method_call_rewrite, r=lnicola
minor: Make `qualify_method_call` `RefactorRewrite`

See https://github.com/rust-lang/rust-analyzer/pull/13825#issuecomment-1363289767
2023-01-09 15:22:51 +00:00
bors
e125bee055 Auto merge of #13890 - lowr:fix/unescape-inline-mod-name, r=Veykril
fix: unescape inline module names in module resolution

Fixes #13884
2023-01-09 15:07:06 +00:00
bors
ba204ef07b Auto merge of #13863 - danieleades:approx-constant, r=Veykril
minor: suppress 'clippy::approx_constant' lint in test case

suppresses a false positive clippy lint
2023-01-09 14:53:46 +00:00
bors
d33fa38cc9 Auto merge of #13825 - WaffleLapkin:ufcs_to_method_call_and_back, r=Veykril
feat: Add `unqualify_method_call` assist

...which is the inverse of `qualify_method_call` assist.

![Peek 2022-12-22 22-47](https://user-images.githubusercontent.com/38225716/209206554-8f067206-6fa6-48f8-849e-f6d36ee2e5a1.gif)

Optional future work:
- import the trait if needed
- remove excess references when auto-ref is possible
2023-01-09 14:37:40 +00:00
Maybe Waffle
bdaad9eb15 Make qualify_method_call RefactorRewrite 2023-01-09 14:26:48 +00:00
bors
336608aa92 Auto merge of #13810 - tfpk:tfpk/macro-inline, r=Veykril
Add action to expand a declarative macro once, inline. Fixes #13598

This commit adds a new r-a method, `expandMacroInline`, which expands the macro that's currently selected. See  #13598 for the most applicable issue; though I suspect it'll resolve part of #5949 and make #11888 significantly easier).

The macro works like this:

![rust-analyser-feature](https://user-images.githubusercontent.com/10906982/208813167-3123e379-8fd5-4206-a4f4-5af1129565f9.gif)

I have 2 questions before this PR can be merged:

1. **Should we rustfmt the output?** The advantage of doing this is neater code. The disadvantages are we'd have to format the whole expr/stmt/block (since there's no point just formatting one part, especially over multiple lines), and maybe it moves the code around more in weird ways. My suggestion here is to start off by not doing any formatting; and if it appears useful we can decide to do formatting in a later release.
2.   **Is it worth solving the `$crate` hygiene issue now?** -- I think this PR is usable as of right now for some use-cases; but it is annoying that many common macros (i.e. `println!()`, `format!()`) can't be expanded further unless the user guesses the correct `$crate` value. The trouble with solving that issue is that I think it's complicated and imperfect. If we do solve it; we'd also need to either change the existing `expandMacro`/`expandMacroInline` commands; provide some option to allow/disallow `$crate` expanding; or come to some other compromise.
2023-01-09 14:24:41 +00:00
Maybe Waffle
c782353a90 Rename assist: convert_ufcs_to_method => unqualify_method_call 2023-01-09 14:23:30 +00:00
bors
938a39ab89 Auto merge of #13891 - bvanjoi:reverse-whitespace-in-assists, r=Veykril
fix: keep whitespace in extract function handler

Fixed #13874
2023-01-09 14:11:40 +00:00
Tom Kunc
769273ca4c Simplify code with @Veykril's suggestion. 2023-01-09 07:01:41 -07:00
Maybe Waffle
44c84a8d28 Add convert_ufcs_to_method assist 2023-01-09 13:50:00 +00:00
bors
ec968198b9 Auto merge of #13816 - WaffleLapkin:postfix_adjustment_hints, r=Veykril
Postfix adjustment hints

# Basic Description

This PR implements "postfix" adjustment hints:
![2022-12-21_19-27](https://user-images.githubusercontent.com/38225716/208941721-d48d316f-a918-408a-9757-8d4e2b402a66.png)

They are identical to normal adjustment hints, but are rendered _after_ the expression. E.g. `expr.*` instead of `*expr`. ~~This mirrors "postfix deref" feature that I'm planning to eventually propose to the compiler.~~

# Motivation

The advantage of being postfix is that you need to add parentheses less often:

![2022-12-21_19-38](https://user-images.githubusercontent.com/38225716/208944302-16718112-14a4-4438-8aed-797766391c63.png)
![2022-12-21_19-37](https://user-images.githubusercontent.com/38225716/208944281-d9614888-6597-41ee-bf5d-a081d8048f94.png)

This is because a lot of "reborrow" hints are caused by field access or method calls, both of which are postfix and have higher "precedence" than prefix `&` and `*`.

Also IMHO it just looks nicer and it's more clear what is happening (order of operations).

# Modes

However, there are some cases where postfix hints need parentheses but prefix don't (for example `&x` being turned into `(&x).*.*.&` or `&**&x`).

This PR allows users to choose which look they like more. There are 4 options (`rust-analyzer.inlayHints.expressionAdjustmentHints.mode` setting):
- `prefix` — always use prefix hints (default, what was used before that PR)
- `postfix` — always use postfix hints
- `prefer_prefix` — try to minimize number of parentheses, breaking ties in favor of prefix
- `prefer_postfix` — try to minimize number of parentheses, breaking ties in favor of postfix

Comparison of all modes:

![2022-12-21_19-53](https://user-images.githubusercontent.com/38225716/208947482-26357c82-2b42-47d9-acec-835f5f03f6b4.png)
![2022-12-21_19-49](https://user-images.githubusercontent.com/38225716/208946731-fe566d3b-52b2-4846-994d-c2cecc769e0f.png)
![2022-12-21_19-48](https://user-images.githubusercontent.com/38225716/208946742-6e237f44-805e-469a-a3db-03d8f76e1317.png)
![2022-12-21_19-47](https://user-images.githubusercontent.com/38225716/208946747-79f25fae-e3ea-47d2-8d27-cb4eeac034fe.png)

# Edge cases

Where are some rare cases where chain hints weirdly interact with adjustment hints, for example (note `SourceAnalyzer.&`):

![image](https://user-images.githubusercontent.com/38225716/208947958-41c12971-f1f0-4a41-a930-47939cce9f58.png)

This is pre-existing, you can get the same effect with prefix hints (`SourceAnalyzer)`).

----

Another weird thing is this:

![2022-12-21_20-00](https://user-images.githubusercontent.com/38225716/208948590-ea26d325-2108-4b35-abaa-716a65a1ae99.png)

Here `.&` is a hint and `?` is written in the source code. It looks like `?` is part of the hint because `?.` is ligature in my font. IMO this is a bug in vscode, but still worth mentioning (I'm also too lazy to report it there...).

# Fixed bugs

I've used the "needs parens" API and this accidentally fixed a bug with parens around `as`, see the test diff:
```diff,rust
     let _: *const u32  = &mut 0u32 as *mut u32;
                        //^^^^^^^^^^^^^^^^^^^^^<mut-ptr-to-const-ptr>
+                       //^^^^^^^^^^^^^^^^^^^^^(
+                       //^^^^^^^^^^^^^^^^^^^^^)
...
     let _: *const u32  = &mut 0u32 as *mut u32;
                        //^^^^^^^^^^^^^^^^^^^^^<mut-ptr-to-const-ptr>
+                       //^^^^^^^^^^^^^^^^^^^^^(
+                       //^^^^^^^^^^^^^^^^^^^^^)
```

# Changelog

changelog feature Add an option to make adjustment hints (aka reborrow hints) postfix
changelog fix Fix placement of parentheses around `as` casts for adjustment hints
2023-01-09 13:47:46 +00:00
Maybe Waffle
b6169c2a2e Add a fixme to remove hacks 2023-01-09 13:37:37 +00:00
Maybe Waffle
a9676cfbe3 Add a "bug" test for adjustment hints to check for status quo 2023-01-09 13:35:21 +00:00
Maybe Waffle
12b7f9f7bf Add an option to minimize parentheses for adjustment hints 2023-01-09 13:35:17 +00:00
bors
b0214d81e8 Auto merge of #13843 - Overpeek:master, r=Veykril
fix: generate async delegate methods

Fixes a bug where the generated async method doesn't await the result before returning it.

This is an example of what the output looked like:
```rust
struct Age<T>(T);
impl<T> Age<T> {
    pub(crate) async fn age<J, 'a>(&'a mut self, ty: T, arg: J) -> T {
        self.0
    }
}
struct Person<T> {
    age: Age<T>,
}
impl<T> Person<T> {
    pub(crate) async fn age<J, 'a>(&'a mut self, ty: T, arg: J) -> T {
        self.age.age(ty, arg) // .await is missing
    }
}
```
The `.await` is missing, so the return type is `impl Future<Output = T>` instead of `T`
2023-01-09 13:34:51 +00:00
Maybe Waffle
b89c4f0a05 Implement postfix adjustment hints
I'd say "First stab at implementing..." but I've been working on this
for a month already lol
2023-01-09 13:27:59 +00:00
Lukas Wirth
d2bb62b6a8 Rename checkOnSave settings to check 2023-01-09 14:17:13 +01:00
Lukas Wirth
87d57f51bc Rename checkOnSave settings to flycheck 2023-01-09 14:17:13 +01:00
bors
ae659125a5 Auto merge of #13763 - rami3l:fix/gen-partial-eq-generic, r=Veykril
fix: add generic `TypeBoundList` in generated derivable impl

Potentially fixes #13727.

Continuing with the work in #13732, this fix tries to add correct type bounds in the generated `impl` block:

```diff
  enum Either<T, U> {
      Left(T),
      Right(U),
  }

- impl<T, U> PartialEq for Either<T, U> {
+ impl<T: PartialEq, U: PartialEq> PartialEq for Either<T, U> {
      fn eq(&self, other: &Self) -> bool {
          match (self, other) {
              (Self::Left(l0), Self::Left(r0)) => l0 == r0,
              (Self::Right(l0), Self::Right(r0)) => l0 == r0,
              _ => false,
          }
      }
  }
```
2023-01-09 13:02:09 +00:00
bors
89e0576bd3 Auto merge of #106340 - saethlin:propagate-operands, r=oli-obk
Always permit ConstProp to exploit arithmetic identities

Fixes https://github.com/rust-lang/rust/issues/72751

Initially, I thought I would need to enable operand propagation then do something else, but actually https://github.com/rust-lang/rust/pull/74491 already has the fix for the issue in question! It looks like this optimization was put under MIR opt level 3 due to possible soundness/stability implications, then demoted further to MIR opt level 4 when MIR opt level 2 became associated with `--release`.

Perhaps in the past we were doing CTFE on optimized MIR? We aren't anymore, so this optimization has no stability implications.

r? `@oli-obk`
2023-01-09 11:59:51 +00:00
bors
fe8ee9c43a Auto merge of #13744 - vtta:numthreads, r=Veykril
feat: add the ability to limit the number of threads launched by `main_loop`

## Motivation
`main_loop` defaults to launch as many threads as cpus in one machine. When developing on multi-core remote servers on multiple projects, this will lead to thousands of idle threads being created. This is very annoying when one wants check whether his program under developing is running correctly via `htop`.

<img width="756" alt="image" src="https://user-images.githubusercontent.com/41831480/206656419-fa3f0dd2-e554-4f36-be1b-29d54739930c.png">

## Contribution
This patch introduce the configuration option `rust-analyzer.numThreads` to set the desired thread number used by the main thread pool.
This should have no effects on the performance as not all threads are actually used.
<img width="1325" alt="image" src="https://user-images.githubusercontent.com/41831480/206656834-fe625c4c-b993-4771-8a82-7427c297fd41.png">

## Demonstration
The following is a snippet of `lunarvim` configuration using my own build.
```lua
vim.list_extend(lvim.lsp.automatic_configuration.skipped_servers, { "rust_analyzer" })
require("lvim.lsp.manager").setup("rust_analyzer", {
  cmd = { "env", "RA_LOG=debug", "RA_LOG_FILE=/tmp/ra-test.log",
    "/home/jlhu/Projects/rust-analyzer/target/debug/rust-analyzer",
  },
  init_options = {
    numThreads = 4,
  },
  settings = {
    cachePriming = {
      numThreads = 8,
    },
  },
})

```

## Limitations
The `numThreads` can only be modified via `initializationOptions` in early initialisation because everything has to wait until the thread pool starts including the dynamic settings modification support.
The `numThreads` also does not reflect the end results of how many threads is actually created, because I have not yet tracked down everything that spawns threads.
2023-01-09 11:53:23 +00:00
bors
1e20bf38b2 Auto merge of #13684 - unvalley:extract-expressions-from-format-string, r=Veykril
feat: extract_expressions_from_format_string

closes #13640
- rename to `extract_expressions_from_format_string`
- leave identifier from format string
	- but this is from rustc version 1.65.0
	- Should I add flag or something?

Note: the assist behaves below cases for now. I'll create an issue for these.
```rs
let var = 1 + 1;
// ok
format!("{var} {1+1}");   // → format!("{var} {}", 1+1);
format!("{var:?} {1+1}"); // → format!("{var:?} {}", 1 + 1);
format!("{var} {var} {1+1}"); // → format!("{var} {var} {}", 1 + 1);

// breaks (need to handle minimum width by postfix`$`)
format!("{var:width$} {1+1}"); // → format!("{var:width\$} {}", 1+1);
format!("{var:.prec$} {1+1}"); // → format!("{var:.prec\$} {}", 1+1);
format!("Hello {:1$}! {1+1}", "x" 5); // → format("Hello {:1\$}! {}", "x", 1+1);
format!("Hello {:width$}! {1+1}", "x", width = 5); // → println!("Hello {:width\$}! {}", "x", 1+1);
```

https://user-images.githubusercontent.com/38400669/204344911-f1f8fbd2-706d-414e-b1ab-d309376efb9b.mov
2023-01-09 11:40:48 +00:00
bors
814ff01620 Auto merge of #13458 - cameron1024:suggest-checked-wrapping-saturating, r=Veykril
add wrapping/checked/saturating assist

This addresses #13452

I'm not sure about the structure of the code. I'm not sure if it needs to be 3 separate assists, and if that means it needs to be in 3 separate files as well.

Most of the logic is in `util.rs`, which feels funny to me, but there seems to be a pattern of 1 assist per file, and this seems better than duplicating the logic.

Let me know if anything needs changes 😁
2023-01-09 11:24:44 +00:00
unvalley
9eabc2cde8 fix: add_format_like_completions to handle no exprs 2023-01-09 12:23:59 +01:00