Commit Graph

236073 Commits

Author SHA1 Message Date
Guillaume Gomez d6056ecb0a Show enum discriminant if a compatible repr is used 2023-10-11 23:44:12 +02:00
Georg Semmler 232aaeba7c
Handle several `#[diagnostic::on_unimplemented]` attributes correctly
This PR fixes an issues where rustc would ignore subsequent
`#[diagnostic::on_unimplemented]` attributes. The [corresponding
RFC](https://rust-lang.github.io/rfcs/3368-diagnostic-attribute-namespace.html)
specifies that the first matching instance of each option is used.
Invalid attributes are linted and otherwise ignored.
2023-10-11 22:01:59 +02:00
bors 475c71da07 Auto merge of #116640 - matthiaskrgr:rollup-xt9r5ir, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #116219 (Relate alias ty with variance)
 - #116315 (Do not check for impossible predicates in const-prop lint.)
 - #116436 (Structurally normalize for closure)
 - #116597 (Prevent showing methods from blanket impls of not available foreign traits to show up in the search results)
 - #116627 (small cleanup)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-11 19:02:49 +00:00
Esteban Küber 9d2eb66e1a Use structured suggestion for #113174
When encountering a for loop that is rejected by the borrow checker
because it is being advanced within its body, provide a structured
suggestion for `while let Some(pat) = iter.next()`.
2023-10-11 18:26:44 +00:00
Matthias Krüger 8374805d67
Rollup merge of #116627 - fee1-dead-contrib:cleanup, r=spastorino
small cleanup

this is exactly the same as the `lower_param_bounds` function, so use that instead
2023-10-11 20:08:22 +02:00
Matthias Krüger d2139834be
Rollup merge of #116597 - GuillaumeGomez:foreign-blanket-impl, r=notriddle
Prevent showing methods from blanket impls of not available foreign traits to show up in the search results

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

In the case that the blanket impl trait is not available in the current crate, we prevent adding its methods in the search index.

Now how I found how to fix the issue: the `equivalent` method is not generated in the documentation pages but was still added to the search index. To render impls, we iterate over `cache.impls` so I took a look at how this was generated. Inside `formats/cache.rs`, we have `CacheBuilder::populate` where we push impls into `impls` but with this condition:

```rust
if cx.cache.traits.contains_key(&trait_did) {
```

I re-used this condition in `CacheBuilder::fold_item` to prevent this method from being added in `cache.search_index` or `cache.orphan_impl_items`.

PS: If you want to double-check if the added test works, just comment the code I added in `cache.rs` and it should fail.

r? ``@notriddle``
2023-10-11 20:08:22 +02:00
Matthias Krüger 3712ea82f3
Rollup merge of #116436 - compiler-errors:structurally-normalize-for-closure, r=lcnr
Structurally normalize for closure

Fixes some signature deduction problems in the new trait solver (and in the case of async, an ICE).

r? lcnr
2023-10-11 20:08:21 +02:00
Matthias Krüger 9b7e0af80d
Rollup merge of #116315 - cjgillot:cpl-clean, r=petrochenkov
Do not check for impossible predicates in const-prop lint.

The enclosing query already checks for them, and replaces the body with a single `unreachable` if they are indeed impossible.
2023-10-11 20:08:20 +02:00
Matthias Krüger 8ddc0df1f1
Rollup merge of #116219 - compiler-errors:relate-alias-ty-with-variance, r=lcnr
Relate alias ty with variance

In the new solver, turns out that the subst-relate branch of the alias-relate predicate was relating args invariantly even for opaques, which have variance 💀.

This change is a bit more invasive, but I'd rather not special-case it [here](aeaa5c30e5/compiler/rustc_trait_selection/src/solve/alias_relate.rs (L171-L190)) and then have it break elsewhere. I'm doing a perf run to see if the extra call to `def_kind` is that expensive, if it is, I'll reconsider.

r? ``@lcnr``
2023-10-11 20:08:20 +02:00
bors c1691db366 Auto merge of #113218 - lqd:polonius-scopes, r=jackh726
Compute NLL loan scopes using the polonius model

For a *location-insensitive* analysis (that is, without expressiveness improvements for users yet), this PR implements loans going out of scope using reachability and liveness, rather than checking if the issuing region's values contain a given CFG point. This is equivalent to NLL scopes and computes the same data.

r? `@matthewjasper`

A couple of notes:
- there are some assumptions about SCC representatives, placeholders, free regions, and member constraints that I believe hold, and they're documented in the code
- this passes all the UI tests with `-Zpolonius=next` -- the perf is [not terrible](https://github.com/rust-lang/rust/pull/112432#issuecomment-1749685862) and there are a bunch of ways to improve it in the future.
- there's a fixme left, hopefully Matthew you know a clean way to get the information it mentions.
2023-10-11 16:46:03 +00:00
bors 3c23df4935 Auto merge of #115937 - oli-obk:spurious_unreachable_pattern, r=Nadrieril
Prevent spurious `unreachable pattern` lints

But it means we'll get more `non-exhaustive` patterns

fixes https://github.com/rust-lang/rust/issues/78057

r? `@Nadrieril` `@RalfJung`
2023-10-11 14:49:49 +00:00
Oli Scherer eca786cd14 Remember the `ErrorReported` used to silence follow up errors instead of recreating it with `delay_span_bug` 2023-10-11 12:49:57 +00:00
Oli Scherer e83467c3b8 Avoid emitting the non_exhaustive error if other errors already occurred 2023-10-11 12:49:57 +00:00
Oli Scherer d1fd11f3f9 Prevent spurious `unreachable pattern` lints
Means you'll get more `non-exhaustive` patterns
2023-10-11 12:49:57 +00:00
bors 5aa23be6b6 Auto merge of #116014 - lqd:mcp510-2-electric-boogaloo, r=petrochenkov
Implement `-Clink-self-contained=-linker` opt out

This implements the `-Clink-self-contained` opt out necessary to switch to lld by changing rustc's defaults instead of cargo's.

Components that are enabled and disabled on the CLI are recorded, for the purpose of being merged with the ones which the target spec will declare (I'll open another PR for that tomorrow, for easier review).

For MCP510, we now check whether using the self-contained linker is disabled on the CLI. Right now it would only be sensible to with `-Zgcc-ld=lld` (and I'll add some checks that we don't both enable and disable a component on the CLI in a future PR), but the goal is to simplify adding the check of the target's enabled components here in the follow-up PRs.

r? `@petrochenkov`
2023-10-11 12:11:39 +00:00
bors 71704c4f84 Auto merge of #116623 - Nadrieril:validate-range-endpoints, r=oli-obk
Fix overflow checking in range patterns

When a range pattern contains an overflowing literal, if we're not careful we might not notice the overflow and use the wrapped value. This makes for confusing error messages because linting against overflowing literals is only done in a later pass. So when a range is invalid we check for overflows to provide a better error.

This check didn't use to handle negative types; this PR fixes that. First commit adds tests, second cleans up without changing behavior, third does the fix.

EDIT: while I was at it, I fixed a small annoyance about the span of the overflow lint on negated literals.

Fixes https://github.com/rust-lang/rust/issues/94239
2023-10-11 10:07:19 +00:00
Guillaume Gomez 2d37b00e24 Handle private dep at the same level as masked crates 2023-10-11 11:43:45 +02:00
Guillaume Gomez efac0b9c02 Add regression test for #115480 2023-10-11 11:41:39 +02:00
Guillaume Gomez a314707867 Prevent showing methods from blanket impls of not available foreign traits to show up in the search results 2023-10-11 11:41:39 +02:00
Deadbeef 50b6f46f71 small cleanup 2023-10-11 08:25:43 +00:00
bors 156da98b29 Auto merge of #112818 - Benjamin-L:add-slice_split_once, r=cuviper
Implement `slice::split_once` and `slice::rsplit_once`

Feature gate is `slice_split_once` and tracking issue is #112811. These are equivalents to the existing `str::split_once` and `str::rsplit_once` methods.
2023-10-11 08:19:13 +00:00
bors 6d05c430d2 Auto merge of #115948 - notriddle:notriddle/logo-lockup, r=fmease
rustdoc: show crate name beside smaller logo

*Blocked on https://github.com/rust-lang/cargo/pull/12800*

## Summary

In this PR, the crate name and version are always shown in the sidebar, even in subpages, and the lateral navigation is always shown in the sidebar, even in modules.

Clicking the crate name does the same thing clicking the logo always did: take you to the crate root (the crate's home page, at least within Rustdoc).

The Rust logo is also no longer shown by default for non-Rust docs.

### Screenshots

<details><summary>Before</summary>

| | Macro | Module |
|--|-------|--------|
| In crate | ![image](https://github.com/rust-lang/rust/assets/1593513/d5db0a46-2bb6-44a2-a3aa-2d915ecb8595) |![image](https://github.com/rust-lang/rust/assets/1593513/61f8c1ee-c298-4e2c-b791-18ecb79ab83b)
| In module[^1] | ![image](https://github.com/rust-lang/rust/assets/1593513/73abca59-0b69-4650-a1e2-7278ca34795c) | ![image](https://github.com/rust-lang/rust/assets/1593513/0baf02c2-2ec7-4674-80e5-a6a74a973376)

[^1]: This PR also includes a bug fix for derive macros not showing up in the lateral navigation part of the sidebar

</details>

#### Whole sidebar screenshots

| | Macro | Module |
|--|-------|--------|
| In crate | ![image](https://github.com/rust-lang/rust/assets/1593513/75d1bd07-41f7-4f11-ba24-fd5476e0586a) | ![image](https://github.com/rust-lang/rust/assets/1593513/52960259-2b65-4131-b380-01826f0a0eb7)
| In module | ![image](https://github.com/rust-lang/rust/assets/1593513/06e57928-8cb0-41bd-b152-be16cc53e5ec) | ![image](https://github.com/rust-lang/rust/assets/1593513/37291c69-2a07-4467-a382-d9b029084a47)

#### Different logo configurations

|         | Short crate name | Long crate name |
|---------|------------------|-----------------|
| Root    | ![short-root]    | ![long-root]
| Subpage | ![short-subpage] | ![long-subpage]

[short-root]: https://github.com/rust-lang/rust/assets/1593513/9e2b4fa8-f581-4106-b562-1e0372c13f79
[short-subpage]: https://github.com/rust-lang/rust/assets/1593513/8331cdb8-fa13-4671-a1e2-dcc1cdca7451
[long-root]: https://github.com/rust-lang/rust/assets/1593513/7d377fec-0f1d-4343-9f82-0e35a8f58056
[long-subpage]: https://github.com/rust-lang/rust/assets/1593513/3b3094a4-63c9-477c-8c15-b6075837df30

##### Without a logo

![image](https://github.com/rust-lang/rust/assets/1593513/66672b79-6c59-4be8-a527-25ef6f0b04ab)

### Preview pages

https://notriddle.com/rustdoc-html-demo-5/sidebar-layout-rocket/rocket/index.html

https://notriddle.com/rustdoc-html-demo-5/sidebar-layout-rocket/rocket_sync_db_pools/index.html

https://notriddle.com/rustdoc-html-demo-5/sidebar-layout-rust-compiler/index.html

https://notriddle.com/rustdoc-html-demo-5/sidebar-layout-rust/std/index.html

https://notriddle.com/rustdoc-html-demo-5/sidebar-layout-rocket/tokio/index.html

## Motivation

This improves visual information density (the construct with the logo and crate name is *shorter* than the logo on its own, because it's not square) and navigation clarity (we can now see what clicking the Rust logo does, specifically).

Compare this with the layout at [Phoenix's Hexdocs] (which is what this proposal is closely based on), the old proposal on [Internals Discourse] (which always says "Rust standard library" in the sidebar, but doesn't do the side-by-side layout).

[Phoenix's Hexdocs]: https://hexdocs.pm/phoenix/1.7.7/overview.html
[Internals Discourse]: https://internals.rust-lang.org/t/poc-of-a-new-design-for-the-generated-rustdoc/11018

## Guide-level explanation

This PR cleans up some of the sidebar navigation.

It makes the logo in the desktop sidebar a bit smaller, and puts the crate name and version next to it (either beside it, or below it, depending on if there's space), making it clearer what clicking on it does: click the crate name to open the crate's home page. It also removes the Rust logo from non-official-Rust crates, again to make the navigation and supply chain clearer (since the crate name has been added, the logo is no longer necessary for navigation).

It adds a bit more clarifying information for lateral navigation. On items that don't add their own sidebar items, it just shows its siblings directly below the crate name and logo, but for other items, it shows "In crate alloc" instead of just "In alloc". It also shows the lateral navigation tools on module pages, making modules consistent with every other item.

## Drawbacks

While this actually takes up less screen real estate than the old layout on desktop, it takes up more HTML. It's also a bit more visually complex.

## Rationale and alternatives

I could do what the Internals POC did and keep the vertically stacked layout all the time, instead of doing a horizontal stack where possible. It would take up more screen real estate, though.

## Prior art

This design is lifted almost verbatim from Hexdocs. It seems to work for them. [`opentelemetry_process_propagator`], for example, has a long application name.

[`opentelemetry_process_propagator`]: https://hexdocs.pm/opentelemetry_process_propagator/OpentelemetryProcessPropagator.html

## Unresolved questions

Maybe we should encourage crate authors to include their own logo more often? It certainly helps give people a better sense of "place." This seems to be blocked on coming up with an API to do it without requiring them to host the file somewhere.

## Future possibilities

Beyond this, plenty of other changes could be made to improve the layout, like

* Fix things so that clicking an item in the sidebar doesn't cause it to scroll back to the top.
  * The [Internals demo](https://utherii.github.io/new.html) does this right: clicking an item in the sidebar changes the content area, but the sidebar itself does not change. This is nice, because clicking is cheap and I can skim the opening few paragraphs while browsing.
  * The layout of the docs sidebar causes trouble to implement this, because it's different on different pages, but at least fix this on the file browser.
* Come up with a less cluttered way to do disclosure. There's a lot of `[-]` on the page.
  * We don't lack ideas to fix this one. We have *too many*.
* Do a better job of separating local navigation (vec::Vec links to vec::IntoIter) and the table of contents (vec::Vec links to vec::Vec::new).
  * A possibility: add a Back arrow next to the "In [module]" header?
    ![image](https://github.com/rust-lang/rust/assets/1593513/e969faf7-7722-457a-b8c6-8d962e9e1e23)
* Give readers more control of how much rustdoc shows them, and giving doc authors more control of how much it generates. Basically, https://github.com/rust-lang/rust/pull/115660 is great, let's do it too.

But those are mostly orthogonal, not future possibilities unlocked by this change.
2023-10-11 06:28:36 +00:00
bors 2e7e0fb838 Auto merge of #116622 - weihanglo:update-cargo, r=weihanglo
Update cargo

5 commits in 794d0a82547f3081044c0aca7b6083733ce51344..6fa6fdc7606cfa664f9bee2fb33ee2ed904f4e88
2023-10-03 23:19:33 +0000 to 2023-10-10 23:06:08 +0000
- test(build): generalize test assertion for non-rustup env (rust-lang/cargo#12804)
- chore: Sort dependency tables (rust-lang/cargo#12803)
- fix(install): Suggest an alternative version on MSRV failure (rust-lang/cargo#12798)
- rustdoc: remove the word "Version" from test cases (rust-lang/cargo#12800)
- Add unsupported lowercase `-z` flag suggestion for `-Z` flag (rust-lang/cargo#12788)

r? ghost
2023-10-11 03:39:01 +00:00
Nadrieril dcdddb7a60 Fix span of overflow lint for negated literals 2023-10-11 04:55:55 +02:00
Nadrieril 1baf8bf54d Fix range overflow checking 2023-10-11 04:55:55 +02:00
Nadrieril 1e1174b034 Rework error handling when lowering range endpoints 2023-10-11 04:54:49 +02:00
Nadrieril c5e17021cc Add tests 2023-10-11 04:54:49 +02:00
bors 36cbf944b3 Auto merge of #116621 - aliemjay:rollup-0e2of3c, r=aliemjay
Rollup of 4 pull requests

Successful merges:

 - #95967 (Add explicit-endian String::from_utf16 variants)
 - #116530 (delay a bug when encountering an ambiguity in MIR typeck)
 - #116611 (Document `diagnostic_namespace` feature)
 - #116612 (Remove unused dominator iterator)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-11 01:49:27 +00:00
Ali MJ Al-Nasrawy 88a929ba32
Rollup merge of #116612 - tmiasko:rm-dom-iter, r=cjgillot
Remove unused dominator iterator
2023-10-11 03:53:18 +03:00
Ali MJ Al-Nasrawy 494e97174a
Rollup merge of #116611 - mejrs:diagnostic_namespace, r=ehuss
Document `diagnostic_namespace` feature

This adds it to the rust unstable book.

FWIW: I couldn't find a way to serve the book locally (please send help), so I can't check that this renders correctly.

cc `@weiznich`
2023-10-11 03:53:17 +03:00
Ali MJ Al-Nasrawy a7042a94a3
Rollup merge of #116530 - aliemjay:ice-on-ambiguity, r=compiler-errors
delay a bug when encountering an ambiguity in MIR typeck

We shouldn't have any trait selection ambiguities in MIR typeck.

See https://github.com/rust-lang/rust/pull/114586#issuecomment-1751967321

r? `@oli-obk` `@compiler-errors` `@lcnr`
2023-10-11 03:53:17 +03:00
Ali MJ Al-Nasrawy 38654ad741
Rollup merge of #95967 - CAD97:from-utf16, r=dtolnay
Add explicit-endian String::from_utf16 variants

This adds the following APIs under `feature(str_from_utf16_endian)`:

```rust
impl String {
    pub fn from_utf16le(v: &[u8]) -> Result<String, FromUtf16Error>;
    pub fn from_utf16le_lossy(v: &[u8]) -> String;
    pub fn from_utf16be(v: &[u8]) -> Result<String, FromUtf16Error>;
    pub fn from_utf16be_lossy(v: &[u8]) -> String;
}
```

These are versions of `String::from_utf16` that explicitly take [UTF-16LE and UTF-16BE](https://unicode.org/faq/utf_bom.html#gen7). Notably, we can do better than just the obvious `decode_utf16(v.array_chunks::<2>().copied().map(u16::from_le_bytes)).collect()` in that:

- We handle the case where the byte slice is not an even number of bytes, and
- In the case that the UTF-16 is native endian and the slice is aligned, we can forward to `String::from_utf16`.

If the Unicode Consortium actively defines how to handle character replacement when decoding a UTF-16 bytestream with a trailing odd byte, I was unable to find reference. However, the behavior implemented here is fairly self-evidently correct: replace the single errant byte with the replacement character.
2023-10-11 03:53:16 +03:00
Weihang Lo 7774141189
update cargo 2023-10-10 20:25:56 -04:00
bors dcf89f43a5 Auto merge of #116578 - antoyo:subtree-update_cg_gcc_2023-10-09, r=bjorn3
subtree update cg_gcc 2023/10/09
2023-10-11 00:04:04 +00:00
Nicholas Nethercote 7d35902c62 Fiddle with `State` functions.
Remove and inline `new_from_input`, because it has a single call site.
And move `attrs` into the earlier `impl` block.
2023-10-11 10:46:55 +11:00
Nicholas Nethercote 494bc8514a Tweak comments.
- Remove an out-of-date comment. (There is no `PpAnn` implementation for `hir::Crate`.)
- Remove a low-value comment.
- And break a very long comment.
2023-10-11 10:46:33 +11:00
Nicholas Nethercote 664b1858aa Remove many unneeded `pub`s. 2023-10-11 09:28:06 +11:00
mejrs ba02a9909b Document `diagnostic_namespace` feature 2023-10-11 00:02:06 +02:00
bors d627cf07ce Auto merge of #113915 - cjgillot:ssa-call, r=tmiasko
Also consider call and yield as MIR SSA.

The SSA analysis on MIR only considered `Assign` statements as defining a SSA local.
This PR adds assignments as part of a `Call` or `Yield` terminator in that category.

This mainly allows to perform CopyProp on a call return place.

The only subtlety is in the dominance property: the assignment is only complete at the beginning of the target block.
2023-10-10 20:37:55 +00:00
Tomasz Miąsko b61a6d59e4 Remove unused dominator iterator 2023-10-10 21:39:59 +02:00
bors c30b28bdc1 Auto merge of #116605 - GuillaumeGomez:rollup-12ba2o6, r=GuillaumeGomez
Rollup of 7 pull requests

Successful merges:

 - #109422 (rustdoc-search: add impl disambiguator to duplicate assoc items)
 - #116250 (On type error of closure call argument, point at earlier calls that affected inference)
 - #116444 (add test for const-eval error in dead code during monomorphization)
 - #116503 (Update docs for mips target tier demotion.)
 - #116559 (Mark `new_in` as `const` for BTree collections)
 - #116560 (In smir use `FxIndexMap` to store indexed ids)
 - #116574 (Update books)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-10 17:37:15 +00:00
Guillaume Gomez 49dd50bf93
Rollup merge of #116574 - rustbot:docs-update, r=ehuss
Update books

## rust-lang/reference

2 commits in 5262e1c3b43a2c489df8f6717683a44c7a2260fd..142b2ed77d33f37a9973772bd95e6144ed9dce43
2023-10-07 19:41:21 UTC to 2023-09-26 12:26:35 UTC

- replace 'UB on raw ptr deref' with UB on place projection/access (rust-lang/reference#1387)
- docs: Fix links to ECMA standards in `attributes.md` (rust-lang/reference#1408)

## rust-lang/rust-by-example

11 commits in c954202c1e1720cba5628f99543cc01188c7d6fc..8eb3a01ab74c567b7174784892fb807f2c632d6b
2023-09-26 12:38:17 UTC to 2023-09-26 12:29:10 UTC

- fixed a typo in the lifetime.md (rust-lang/rust-by-example#1737)
- Misleading textual statement in HOF (rust-lang/rust-by-example#1731)
- Equalize title from respective file with title in SUMMARY.md (rust-lang/rust-by-example#1738)
- Added explanation for compiling and executing match_args.rs. (rust-lang/rust-by-example#1739)
- Wrapped long lines and put #[doc] in backquotes. (rust-lang/rust-by-example#1740)
- Update read_lines example to flatten iterator (rust-lang/rust-by-example#1742)
- Update while_let.md: address inconsistent use of fn main between 2 co… (rust-lang/rust-by-example#1744)
- [TRIVIAL] Remove confusing `also` (rust-lang/rust-by-example#1746)
- Fix and extend the explanation of outer vs inner attributes. (rust-lang/rust-by-example#1748)
- Fix uncorresponded back quote (rust-lang/rust-by-example#1749)
- Fix format in constants.md (rust-lang/rust-by-example#1741)

## rust-lang/rustc-dev-guide

3 commits in a13b7c28ed705891c681ce5417b3d1cdb12cecd1..b98af7d661e4744baab81fb8dc7a049e44a4a998
2023-10-05 19:48:35 UTC to 2023-09-27 22:57:27 UTC

- update new trait solver docs (rust-lang/rustc-dev-guide#1802)
- update rustc_driver examples (rust-lang/rustc-dev-guide#1803)
- test headers: fix `compile-flags` example (rust-lang/rustc-dev-guide#1800)
2023-10-10 18:44:47 +02:00
Guillaume Gomez 100713ef08
Rollup merge of #116560 - ouz-a:efficient_ids, r=oli-obk
In smir use `FxIndexMap` to store indexed ids

Previously we used `vec` for storing indexed types, which is fine for small cases but will lead to huge performance issues when we use `smir` for real world cases.

Addresses https://github.com/rust-lang/project-stable-mir/issues/35

r? ``@oli-obk``
2023-10-10 18:44:46 +02:00
Guillaume Gomez b72db84fd0
Rollup merge of #116559 - Kritzefitz:btree-new-in-const, r=Amanieu
Mark `new_in` as `const` for BTree collections

Discussed in and closes rust-lang/wg-allocators#118
2023-10-10 18:44:46 +02:00
Guillaume Gomez fccf9ec224
Rollup merge of #116503 - ehuss:fix-mips-tier, r=Amanieu
Update docs for mips target tier demotion.

These mips targets were demoted in #113274, but the documentation was not updated. I have also elected to document this in the release notes for 1.72 because I think that should have been included.
2023-10-10 18:44:45 +02:00
Guillaume Gomez bbaf6bd136
Rollup merge of #116444 - RalfJung:broken-unused-const, r=oli-obk
add test for const-eval error in dead code during monomorphization
2023-10-10 18:44:45 +02:00
Guillaume Gomez 0e5e04b89a
Rollup merge of #116250 - estebank:closure-arg-inference-span, r=petrochenkov
On type error of closure call argument, point at earlier calls that affected inference

Mitigate part of  https://github.com/rust-lang/rust/issues/71209.

When we encounter a type error on a specific argument of a closure call argument, where the closure's definition doesn't have a type specified, look for other calls of the closure to try and find the specific call that cased that argument to be inferred of the expected type.

```
error[E0308]: mismatched types
  --> $DIR/unboxed-closures-type-mismatch.rs:30:18
   |
LL |         identity(1u16);
   |         -------- ^^^^ expected `u8`, found `u16`
   |         |
   |         arguments to this function are incorrect
   |
note: expected because the closure was earlier called with an argument of type `u8`
  --> $DIR/unboxed-closures-type-mismatch.rs:29:18
   |
LL |         identity(1u8);
   |         -------- ^^^ expected because this argument is of type `u8`
   |         |
   |         in this closure call
note: closure parameter defined here
  --> $DIR/unboxed-closures-type-mismatch.rs:28:25
   |
LL |         let identity = |x| x;
   |                         ^
help: change the type of the numeric literal from `u16` to `u8`
   |
LL |         identity(1u8);
   |                   ~~
```
2023-10-10 18:44:44 +02:00
Guillaume Gomez 4be9cfabf2
Rollup merge of #109422 - notriddle:notriddle/impl-disambiguate-search, r=GuillaumeGomez
rustdoc-search: add impl disambiguator to duplicate assoc items

Preview (to see the difference, click the link and pay attention to the specific function that comes up):

| Before | After |
|--|--|
| [`simd<i64>, simd<i64> -> simd<i64>`](https://doc.rust-lang.org/nightly/std/?search=simd%3Ci64%3E%2C%20simd%3Ci64%3E%20-%3E%20simd%3Ci64%3E) | [`simd<i64>, simd<i64> -> simd<i64>`](https://notriddle.com/rustdoc-demo-html-3/impl-disambiguate-search/std/index.html?search=simd%3Ci64%3E%2C%20simd%3Ci64%3E%20-%3E%20simd%3Ci64%3E) |
| [`cow, vec -> bool`](https://doc.rust-lang.org/nightly/std/?search=cow%2C%20vec%20-%3E%20bool) | [`cow, vec -> bool`](https://notriddle.com/rustdoc-demo-html-3/impl-disambiguate-search/std/index.html?search=cow%2C%20vec%20-%3E%20bool)

Helps with #90929

This changes the search results, specifically, when there's more than one impl with an associated item with the same name. For example, the search queries `simd<i8> -> simd<i8>` and `simd<i64> -> simd<i64>` don't link to the same function, but most of the functions have the same names.

This change should probably be FCP-ed, especially since it adds a new anchor link format for `main.js` to handle, so that URLs like `struct.Vec.html#impl-AsMut<[T]>-for-Vec<T,+A>/method.as_mut` redirect to `struct.Vec.html#method.as_mut-2`. It's a strange design, but there are a few reasons for it:

* I'd like to avoid making the HTML bigger. Obviously, fixing this bug is going to add at least a little more data to the search index, but adding more HTML penalises viewers for the benefit of searchers.

* Breaking `struct.Vec.html#method.len` would also be a disappointment.

On the other hand:

* The path-style anchors might be less prone to link rot than the numbered anchors. It's definitely less likely to have URLs that appear to "work", but silently point at the wrong thing.

* This commit arranges the path-style anchor to redirect to the numbered anchor. Nothing stops rustdoc from doing the opposite, making path-style anchors the default and redirecting the "legacy" numbered ones.

### The bug

On the "Before" links, this example search calls for `i64`:

![image](https://github.com/rust-lang/rust/assets/1593513/9431d89d-41dc-4f68-bbb1-3e2704a973d2)

But if I click any of the results, I get `f64` instead.

![image](https://github.com/rust-lang/rust/assets/1593513/6d89c692-1847-421a-84d9-22e359d9cf82)

The PR fixes this problem by adding enough information to the search result `href` to disambiguate methods with different types but the same name.

More detailed description of the problem at:
https://github.com/rust-lang/rust/pull/109422#issuecomment-1491089293

> When a struct/enum/union has multiple impls with different type parameters, it can have multiple methods that have the same name, but which are on different impls. Besides Simd, [Any](https://doc.rust-lang.org/nightly/std/any/trait.Any.html?search=any%3A%3Adowncast) also demonstrates this pattern. It has three methods named `downcast`, on three different impls.
>
> When that happens, it presents a challenge in linking to the method. Normally we link like `#method.foo`. When there are multiple `foo`, we number them like `#method.foo`, `#method.foo-1`, `#method.foo-2`, etc.
>
> It also presents a challenge for our search code. Currently we store all the variants in the index, but don’t have any way to generate unambiguous URLs in the results page, or to distinguish them in the SERP.
>
> To fix this, we need three things:
>
> 1. A fragment format that fully specifies the impl type parameters when needed to disambiguate (`#impl-SimdOrd-for-Simd<i64,+LANES>/method.simd_max`)
> 2. A search index that stores methods with enough information to disambiguate the impl they were on.
> 3. A search results interface that can display multiple methods on the same type with the same name, when appropriate OR a disambiguation landing section on item pages?
>
> For reviewers: it can be hard to see the new fragment format in action since it immediately gets rewritten to the numbered form.
2023-10-10 18:44:43 +02:00
bors 5b88d659f8 Auto merge of #116598 - matthiaskrgr:rollup-6xra4jx, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #116586 (use env variable to control thread ids in rustc_log)
 - #116589 (coverage: Unbox and simplify `bcb_filtered_successors`)
 - #116595 (-Zmir-enable-passes: document that this may enable unsound passes)
 - #116596 (reorder files in solve)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-10 13:29:09 +00:00
Matthias Krüger da42858b14
Rollup merge of #116596 - lcnr:normalize-subdir, r=compiler-errors
reorder files in solve

r? `@compiler-errors`
2023-10-10 14:07:48 +02:00