Commit graph

30749 commits

Author SHA1 Message Date
bors
78d5f05e70 Auto merge of #17508 - jjoeldaniel:landing-page, r=Veykril
feat: Add landing/faq walkthrough pages

This is a basic implementation of a landing and FAQ page; I've included the bare-bones information as well as a [recommended section on inlay hints](https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/Landing.20Page/near/446135321).

I've also added `rust-analyzer: Open Walkthrough` and `rust-analyzer: Open FAQ` commands for ease of access.

I am hoping to create a small list of FAQ to include that might be useful as well as any other information I may have missed in the landing page. Feel free to share any suggestions!

![landing/faq page demo](https://github.com/rust-lang/rust-analyzer/assets/100006388/4644e4f0-4555-4b29-83c1-b048084ad63d)

cc #13351
2024-07-06 13:59:36 +00:00
bors
39d7962c69 Auto merge of #17546 - Veykril:unresolved-self, r=Veykril
internal: Diagnose unresolved self value in path expression
2024-07-06 13:46:01 +00:00
Lukas Wirth
4420e7148f Diagnose unresolved self value in path expression 2024-07-06 15:44:12 +02:00
bors
4c20cebd7c Auto merge of #127403 - compiler-errors:rollup-x2yb5t0, r=compiler-errors
Rollup of 8 pull requests

Successful merges:

 - #123600 (impl PathBuf::add_extension and Path::with_added_extension)
 - #127107 (Improve dead code analysis)
 - #127221 (Improve well known value check-cfg diagnostic for the standard library)
 - #127333 (Split `SolverDelegate` back out from `InferCtxtLike`)
 - #127363 (Improve readability of some fmt code examples)
 - #127366 (Use `ControlFlow` results for visitors that are only looking for a single value)
 - #127368 (Added dots at the sentence ends of rustc AST doc)
 - #127393 (Remove clubby789 from review rotation)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-07-06 02:48:17 +00:00
Michael Goulet
fe3b63aa82
Rollup merge of #127393 - clubby789:unreview, r=workingjubilee
Remove clubby789 from review rotation

These days I'm unfortunately too busy to be able to take up reviews, and it looks like some PRs have been blocked on this 😓
2024-07-05 20:49:35 -04:00
Michael Goulet
1e5a2e84c6
Rollup merge of #127368 - YohDeadfall:dots-in-docs, r=fmease
Added dots at the sentence ends of rustc AST doc

Just a tiny improvement for the AST documentation by bringing consistency to sentence ends. I intentionally didn't terminate every sentence, there are still some members not having them, but at least there's no mixing style on the type level.
2024-07-05 20:49:34 -04:00
Michael Goulet
aca9551e08
Rollup merge of #127366 - oli-obk:falliblevisitor, r=compiler-errors
Use `ControlFlow` results for visitors that are only looking for a single value

These visitors all had a `Option<Value>` or `bool` field, that, once set, was never unset or modified again. They have been refactored by removing the field and returning `ControlFlow` directly from the visitor
2024-07-05 20:49:34 -04:00
Michael Goulet
a5651179f7
Rollup merge of #127363 - GuillaumeGomez:improve-fmt-code-readability, r=Amanieu
Improve readability of some fmt code examples

Some indent was weird. Some examples were too long (overall better to keep it to maximum 80 columns, but only changed the most outstanding ones).

r? ```@Amanieu```
2024-07-05 20:49:33 -04:00
Michael Goulet
4468715e50
Rollup merge of #127333 - compiler-errors:infer_ctxt_like-again, r=lcnr
Split `SolverDelegate` back out from `InferCtxtLike`

This is because in order to uplift things like the `Generalizer` and other `TypeRelation`s, we want to be able to interface with `InferCtxtLike` (and `InferCtxt` as its implementation), rather that `SolverDelegate`, which only really exists as a hack to be able to define some downstream methods in `rustc_type_ir`.

r? lcnr
2024-07-05 20:49:32 -04:00
Michael Goulet
200ca5430e
Rollup merge of #127221 - Urgau:check-cfg-std-diag, r=pnkfelix
Improve well known value check-cfg diagnostic for the standard library

This PR adjust the current logic for hidding the rustc/Cargo suggestion to add a value to a well-known name to exclude the standard library and rustc crates.

This is done in order to improve the contributor experience, in particular when adding a new target, which often requires adding some cfgs like `target_os` which may not be available yet in stage0.

<details>

The diagnostic code would look like this.

```text
error: unexpected `cfg` condition value: `blable`
   --> library/core/src/lib.rs:369:7
    |
369 | #[cfg(target_os = "blable")]
    |       ^^^^^^^^^^^^^^^^^^^^
    |
    = note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `teeos`, `tvos`, `uefi`, `unknown`, `visionos`, `vita`, `vxworks`, `wasi`, `watchos`, and `windows` and 2 more
    = help: consider using a Cargo feature instead
    = help: or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:
             [lints.rust]
             unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("blable"))'] }
    = help: or consider adding `println!("cargo::rustc-check-cfg=cfg(target_os, values(\"blable\"))");` to the top of the `build.rs`
    = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration
    = note: `-D unexpected-cfgs` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(unexpected_cfgs)]`
```

</details>
2024-07-05 20:49:32 -04:00
Michael Goulet
68ea9f82cb
Rollup merge of #127107 - mu001999-contrib:dead/enhance-2, r=pnkfelix
Improve dead code analysis

Fixes #120770

1. check impl items later if self ty is private although the trait method is public, cause we must use the ty firstly if it's private
2. mark the adt live if it appears in pattern, like generic argument, this implies the use of the adt
3. based on the above, we can handle the case that private adts impl Default, so that we don't need adding rustc_trivial_field_reads on Default, and the logic in should_ignore_item

r? ``@pnkfelix``
2024-07-05 20:49:31 -04:00
bors
f2afcb874e Auto merge of #17541 - ShoyuVanilla:nested-impl-traits, r=Veykril
Disallow nested impl traits

Fixes #17498

The above issue is due to formatting self referencing, recursive bound like `Implemented(^0.0: TraitId(0)<[?0 := ^0.0]>)` on the codes like;

```rust
trait Foo<T> {}

trait Bar {}

fn test(foo: impl Foo<impl Bar>) { ... }
```

When lowering predicate `impl Foo<impl Bar>` in `trait_environment_query`, the outer `impl Foo<...>` is treated as predicates, so the first `TypeRef` that passes the following code is `impl Bar`;

cae997e338/crates/hir-ty/src/lower.rs (L376-L400)

and thus the `idx` is `0` in the above context.

But the following code sets `self_ty` as the `BoundVar` with `idx = 0` because the target param id for predicate  `impl Foo<...>` is `0` since `impl Foo` is the first generic-like parameter of `fn test`;

cae997e338/crates/hir-ty/src/lower.rs (L998-L1025)

For the codes like;

```rust
trait Foo {
    type Assoc;
}

trait Bar {}

fn test(foo: impl Foo<Assoc = impl Bar>) { ... }
```

similar recursive bound doesn't happen because the following codes ***"count the number of `impl Trait` things that appear before the target of our `bound`."***

cae997e338/crates/hir-ty/src/lower.rs (L1168-L1199)

Instead of doing similar thing like nested `impl Foo<impl Bar>` thing, this PR lowers such nested impl traits into error types in the similar manner as the rustc does in the following lines (and of course, allows lowering and inferencing nested impl traits for the cases that rustc permits);

- e2cf31a614/compiler/rustc_ast_passes/src/ast_validation.rs (L802-L813)
- 7b21c18fe4/compiler/rustc_ast_passes/src/ast_validation.rs (L1299-L1314)

(Though rustc emits [E0666😈](https://doc.rust-lang.org/error_codes/E0666.html), I skipped diagnostics since gathering diagnostics in `hir-def` has no conventions so far 😅)
2024-07-05 10:28:30 +00:00
bors
75dd842900 Auto merge of #127008 - Jules-Bertholet:tc-ergonomics, r=Nadrieril
Match ergonomics 2024: Implement TC's match ergonomics proposal

Under gate `ref_pat_eat_one_layer_2024_structural`. Enabling `ref_pat_eat_one_layer_2024` at the same time allows the union of what the individual gates allow. `@traviscross`

r? `@Nadrieril`

cc https://github.com/rust-lang/rust/issues/123076

`@rustbot` label A-edition-2024 A-patterns
2024-07-05 09:10:17 +00:00
bors
9b5b4cbc99 Auto merge of #126171 - RalfJung:simd_bitmask_multibyte, r=workingjubilee
simd_bitmask intrinsic: add a non-power-of-2 multi-byte example

r? `@calebzulawski` `@workingjubilee`
2024-07-05 01:58:22 +00:00
Maybe Lapkin
0cea755154 Delete CloneAny from rust-analyzer's fork of AnyMap
...because it's very sketchy and causes FCWs.
In this case it *is* actually sound, but still.

I should write a better fork of anymap...
2024-07-04 17:57:31 +02:00
Shoyu Vanilla
4bb623decb Disallow nested impl traits 2024-07-04 23:31:55 +09:00
bors
3c58b3f279 Auto merge of #127170 - bjorn3:no_specialize_index_borrowck, r=michaelwoerister
Stop using specialization in rustc_index and rustc_borrowck

For rustc_borrowck the version with specialization isn't much more readable anyway IMO. For rustc_index it probably doesn't affect perf in any noticeable way anyway.
2024-07-04 14:24:43 +00:00
mu001999
2ec3a7dd6a Improve dead code analysis 2024-07-04 22:05:00 +08:00
bors
d59314800b Auto merge of #127036 - cjgillot:sparse-state, r=oli-obk
Make jump threading state sparse

Continuation of https://github.com/rust-lang/rust/pull/127024

Both dataflow const-prop and jump threading involve cloning the state vector a lot. This PR replaces the data structure by a sparse vector, considering:
- that jump threading state is typically very sparse (at most 1 or 2 set entries);
- that dataflow const-prop is disabled by default;
- that place/value map is very eager, and prone to creating an overly large state.

The first commit is shared with the previous PR to avoid needless conflicts.

r? `@oli-obk`
2024-07-03 18:52:04 +00:00
bors
cae997e338 Auto merge of #17536 - Veykril:syntax-diags, r=Veykril
fix: Don't emit semantic diagnostics in files with a lot of syntax errors

These will only add to the noise when something very unexpected breaks or where parser recovery fails to kick in.
2024-07-03 09:01:48 +00:00
Lukas Wirth
cbcb9779f5 fix: Don't emit semantic diagnostics in files with a lot of syntax errors 2024-07-03 10:59:46 +02:00
bors
39e6a8ea36 Auto merge of #17535 - Veykril:macro-def-syn, r=Veykril
fix: Fix up the syntax tree for macro 2.0

Fixes https://github.com/rust-lang/rust-analyzer/issues/10266

This change is trivial now that we don't have a token map anymore
2024-07-03 08:46:16 +00:00
Lukas Wirth
013b6a883f Fix up the syntax tree for macro 2.0 2024-07-03 10:41:19 +02:00
bors
848e0c4040 Auto merge of #17534 - Veykril:skip-unknown-match-check, r=Veykril
fix: Skip match exhaustiveness checking if pattern type contains errors

Should fix https://github.com/rust-lang/rust-analyzer/issues/17509, checking when errors are involved is generally a bad idea as the algorithm doesn't really expect error types in the first place I believe
2024-07-03 06:34:39 +00:00
Lukas Wirth
26c7bfd0b4 Skip match exhaustiveness checking if pattern type contains errors 2024-07-03 08:31:40 +02:00
bors
4c47fa085b Auto merge of #123737 - compiler-errors:alias-wf, r=lcnr
Check alias args for WF even if they have escaping bound vars

#### What

This PR stops skipping arguments of aliases if they have escaping bound vars, instead recursing into them and only discarding the resulting obligations referencing bounds vars.

#### An example:

From the test:
```
trait Trait {
    type Gat<U: ?Sized>;
}

fn test<T>(f: for<'a> fn(<&'a T as Trait>::Gat<&'a [str]>)) where for<'a> &'a T: Trait {}
//~^ ERROR the size for values of type `[()]` cannot be known at compilation time

fn main() {}
```

We now prove that `str: Sized` in order for `&'a [str]` to be well-formed. We were previously unconditionally skipping over `&'a [str]` as it referenced a buond variable. We now recurse into it and instead only discard the `[str]: 'a` obligation because of the escaping bound vars.

#### Why?

This is a change that improves consistency about proving well-formedness earlier in the pipeline, which is necessary for future work on where-bounds in binders and correctly handling higher-ranked implied bounds. I don't expect this to fix any unsoundness.

#### What doesn't it fix?

Specifically, this doesn't check projection predicates' components are well-formed, because there are too many regressions: https://github.com/rust-lang/rust/pull/123737#issuecomment-2052198478
2024-07-03 03:48:06 +00:00
bors
171f29d081 Auto merge of #127152 - ChrisDenton:rename, r=onur-ozkan
Bootstrap: Try renaming the file if removing fails

Second attempt at working around https://github.com/rust-lang/rust/issues/127126

If we can't remove the file, then try renaming it. This will leave the destination path free to use.

try-job: x86_64-msvc-ext
2024-07-02 17:53:03 +00:00
bors
4981f00bb6 Auto merge of #17530 - Veykril:lifetime-order, r=Veykril
Move lifetimes in front of type and const params but after self
2024-07-02 12:20:54 +00:00
Lukas Wirth
baa959fa99 Move lifetimes in front of type and const params but after self 2024-07-02 14:17:34 +02:00
Lukas Wirth
966798b7ba Make GenericParams::lifetimes private 2024-07-02 13:45:53 +02:00
Lukas Wirth
be1ea4028b Make GenericParams::where_predicates private 2024-07-02 13:45:50 +02:00
Lukas Wirth
372e2d22e6 Make GenericParams::type_or_consts private 2024-07-02 13:45:48 +02:00
bors
73c97e3fe0 Auto merge of #17529 - Veykril:fix-17065, r=Veykril
fix: Fix lifetime parameters moving parameter defaults

Fixes https://github.com/rust-lang/rust-analyzer/issues/17075, https://github.com/rust-lang/rust-analyzer/issues/17515

We were incorrectly filling the default params due to our odd order of lifetime parameters vs type/const params. So this needs some special handling so that we don't shift the defaults around.
2024-07-02 10:35:44 +00:00
Lukas Wirth
1a929d6485 Fix lifetime parameters moving paramter defaults 2024-07-02 12:34:32 +02:00
Shohei Wada
3725ab3146 squash. 2024-07-02 01:52:34 +09:00
bors
1b283db47f Auto merge of #17526 - Veykril:proc-server-errors, r=Veykril
internal: Improve error message when the proc-macro server unexpectedly exits
2024-07-01 13:57:24 +00:00
Lukas Wirth
c6709ffe05 Improve error message when the proc-macro server unexpectedly exits 2024-07-01 14:30:21 +02:00
bors
e6fd485683 Auto merge of #17495 - listochkin:pass-cargo-extra-args-for-debugger, r=Veykril
pass cargo extra args when debugging

fixes #17128
2024-07-01 10:34:09 +00:00
bors
becf5d31f7 Auto merge of #17494 - harrysarson:harry/keep-braces, r=Veykril
do not normalize `use foo::{self}` to `use foo`

It changes behaviour and can cause collisions. E.g. for the following snippet

```rs
mod foo {

    pub mod bar {}

    pub const bar: i32 = 8;
}

// transforming the below to `use foo::bar;` causes the error:
//
//   the name `bar` is defined multiple times
use foo::bar::{self};

const bar: u32 = 99;

fn main() {
    let local_bar = bar;
}
```

we still normalize

```rs
use foo::bar;
use foo::bar::{self};
```

to `use foo::bar;` because this cannot cause collisions.

See: https://github.com/rust-lang/rust-analyzer/pull/17140#issuecomment-2079189725
2024-07-01 10:20:01 +00:00
bors
72f278b5be Auto merge of #17522 - Veykril:comptimes, r=Veykril
internal: Cut compiletimes slightly
2024-07-01 08:43:11 +00:00
bors
6e0a82f978 Auto merge of #126996 - oli-obk:do_not_count_errors, r=nnethercote
Automatically taint InferCtxt when errors are emitted

r? `@nnethercote`

Basically `InferCtxt::dcx` now returns a `DiagCtxt` that refers back to the `Cell<Option<ErrorGuaranteed>>` of the `InferCtxt` and thus when invoking `Diag::emit`, and the diagnostic is an error, we taint the `InferCtxt` directly.

That change on its own has no effect at all, because `InferCtxt` already tracks whether errors have been emitted by recording the global error count when it gets opened, and checking at the end whether the count changed. So I removed that error count check, which had a bit of fallout that I immediately fixed by invoking `InferCtxt::dcx` instead of `TyCtxt::dcx` in a bunch of places.

The remaining new errors are because an error was reported in another query, and never bubbled up. I think they are minor enough for this to be ok, and sometimes it actually improves diagnostics, by not silencing useful diagnostics anymore.

fixes #126485 (cc `@olafes)`

There are more improvements we can do (like tainting in hir ty lowering), but I would rather do that in follow up PRs, because it requires some refactorings.
2024-07-01 06:35:58 +00:00
bors
aecd03f2f8 Auto merge of #127176 - fee1-dead-contrib:fx-requires-next-solver, r=compiler-errors
Make `feature(effects)` require `-Znext-solver`

Per https://github.com/rust-lang/rust/pull/120639#pullrequestreview-2144804638

I made this a hard error because otherwise it should be a lint and that seemed more complicated. Not sure if this is the best place to put the error though.

r? project-const-traits
2024-07-01 04:21:13 +00:00
bors
c458863547 Auto merge of #127082 - GuillaumeGomez:help-gui-test, r=notriddle
Add back `help-page.goml` rustdoc GUI test

Since https://github.com/rust-lang/rust/pull/127010 was merged, let's see if we can revert https://github.com/rust-lang/rust/pull/126445...

r? `@notriddle`
2024-07-01 00:52:41 +00:00
bors
35ba91b5af Auto merge of #127026 - Urgau:cleanup-bootstrap-check-cfg, r=Kobzol
Cleanup bootstrap check-cfg

This PR cleanup many custom `check-cfg` in bootstrap that have been accumulated over the years.

As well as updating some outdated comments.
2024-06-30 22:27:29 +00:00
bors
ef8a2b3209 Auto merge of #127174 - matthiaskrgr:rollup-q87j6cn, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #126018 (Remove the `box_pointers` lint.)
 - #126895 (Fix simd_gather documentation)
 - #126981 (Replace some magic booleans in match-lowering with enums)
 - #127038 (Update test comment)
 - #127053 (Update the LoongArch target documentation)
 - #127069 (small correction to fmt::Pointer impl)
 - #127157 (coverage: Avoid getting extra unexpansion info when we don't need it)
 - #127160 (Add a regression test for #123630)
 - #127161 (Improve `run-make-support` library `args` API)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-06-30 20:14:40 +00:00
Lukas Wirth
d859e40db9 Bump rustc_pattern_analysis 2024-06-30 18:41:55 +02:00
Matthias Krüger
05ed0f810c
Rollup merge of #127161 - GuillaumeGomez:improve-run-make-args, r=Kobzol
Improve `run-make-support` library `args` API

It allows to pass both `Vec` and slices, which makes it much better (for me at least 😉).

r? ``@Kobzol``
2024-06-30 18:25:35 +02:00
Matthias Krüger
0d97b23809
Rollup merge of #127160 - pacak:123630-test, r=Nadrieril
Add a regression test for #123630

Fixes #123630

compiler should not suggest nonsensical signatures, original suggestion was

```
error[E0308]: mismatched types
 --> src/lib.rs:3:31
  |
3 | fn select<F, I>(filter: F) -> Select<F, I> {
  |    ------                     ^^^^^^^^^^^^ expected `Select<F, I>`, found `()`
  |    |
  |    implicitly returns `()` as its body has no tail or `return` expression
  |
  = note: expected struct `Select<F, I>`
          found unit type `()`

error[E0282]: type annotations needed for `Select<{closure@src/lib.rs:8:22: 8:25}, I>`
 --> src/lib.rs:8:9
  |
8 |     let lit = select(|x| match x {
  |         ^^^
  |
help: consider giving `lit` an explicit type, where the type for type parameter `I` is specified
  |
8 |     let lit: Select<{closure@src/lib.rs:8:22: 8:25}, I> = select(|x| match x {
  |            ++++++++++++++++++++++++++++++++++++++++++++

Some errors have detailed explanations: E0282, E0308. For more information about an error, try `rustc --explain E0282`.
```
2024-06-30 18:25:35 +02:00
Matthias Krüger
a8d7036bdc
Rollup merge of #127157 - Zalathar:unexpand, r=cjgillot
coverage: Avoid getting extra unexpansion info when we don't need it

Several callers of `unexpand_into_body_span_with_visible_macro` would immediately discard the additional macro-related information, which is wasteful. We can avoid this by having them instead call a simpler method that just returns the span they care about.

This PR also moves the relevant functions out of `coverage::spans::from_mir` and into a new submodule `coverage::unexpand`, so that calling them from `coverage::mappings` is less awkward.

There should be no actual changes to coverage-instrumentation output, as demonstrated by the absence of test updates.
2024-06-30 18:25:34 +02:00
Matthias Krüger
b5df53c9ea
Rollup merge of #127069 - Sky9x:fmt-pointer-use-addr, r=Nilstrieb
small correction to fmt::Pointer impl

~~The `addr` method does not require `T: Sized`, and is preferred for use over `expose_provenance`.~~
`expose_provenance` does not require `T: Sized`.
2024-06-30 18:25:34 +02:00