Commit Graph

243346 Commits

Author SHA1 Message Date
Nicholas Nethercote beeaee9785 Rename consuming chaining methods on `DiagnosticBuilder`.
In #119606 I added them and used a `_mv` suffix, but that wasn't great.

A `with_` prefix has three different existing uses.
- Constructors, e.g. `Vec::with_capacity`.
- Wrappers that provide an environment to execute some code, e.g.
  `with_session_globals`.
- Consuming chaining methods, e.g. `Span::with_{lo,hi,ctxt}`.

The third case is exactly what we want, so this commit changes
`DiagnosticBuilder::foo_mv` to `DiagnosticBuilder::with_foo`.

Thanks to @compiler-errors for the suggestion.
2024-01-10 07:40:00 +11:00
Nicholas Nethercote ed76b0b882 Rename consuming chaining methods on `DiagnosticBuilder`.
In #119606 I added them and used a `_mv` suffix, but that wasn't great.

A `with_` prefix has three different existing uses.
- Constructors, e.g. `Vec::with_capacity`.
- Wrappers that provide an environment to execute some code, e.g.
  `with_session_globals`.
- Consuming chaining methods, e.g. `Span::with_{lo,hi,ctxt}`.

The third case is exactly what we want, so this commit changes
`DiagnosticBuilder::foo_mv` to `DiagnosticBuilder::with_foo`.

Thanks to @compiler-errors for the suggestion.
2024-01-10 07:40:00 +11:00
Nicholas Nethercote 2ea7a37e11 Add `DiagCtxt::delayed_bug`.
We have `span_delayed_bug` and often pass it a `DUMMY_SP`. This commit
adds `delayed_bug`, which matches pairs like `err`/`span_err` and
`warn`/`span_warn`.
2024-01-10 07:33:07 +11:00
Nicholas Nethercote 3c4f1d85af Rename `{create,emit}_warning` as `{create,emit}_warn`.
For consistency with `warn`/`struct_warn`, and also `{create,emit}_err`,
all of which use an abbreviated form.
2024-01-10 07:33:06 +11:00
Nicholas Nethercote ff40ad4107 Shorten some error invocations.
- `struct_foo` + `emit` -> `foo`
- `create_foo` + `emit` -> `emit_foo`

I have made recent commits in other PRs that have removed some of these
shortcuts for combinations with few uses, e.g.
`struct_span_err_with_code`. But for the remaining combinations that
have high levels of use, we might as well use them wherever possible.
2024-01-10 07:33:06 +11:00
Nicholas Nethercote 4864cb8aef Rename `struct_span_err!` as `struct_span_code_err!`.
Because it takes an error code after the span. This avoids the confusing
overlap with the `DiagCtxt::struct_span_err` method, which doesn't take
an error code.
2024-01-10 07:33:04 +11:00
Nicholas Nethercote 99b1b0f85c Fix incorrect comment. 2024-01-10 07:17:55 +11:00
clubby789 f1b8b7d7ae Add error code for missing base expression in struct update syntax 2024-01-09 19:25:54 +00:00
Urgau 15078c25d6 Add explicit none() value variant in check-cfg 2024-01-09 19:03:06 +01:00
bors ae9d24de80 Auto merge of #119777 - GuillaumeGomez:rollup-mf82vow, r=GuillaumeGomez
Rollup of 5 pull requests

Successful merges:

 - #118241 (Making `User<T>` and `User<[T]>` `Send`)
 - #118645 (chore: Bump compiler_builtins)
 - #118680 (Add support for shell argfiles)
 - #119721 (`~const` trait and projection bounds do not imply their non-const counterparts)
 - #119768 (core: panic: fix broken link)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-01-09 17:19:52 +00:00
Guillaume Gomez f7ef9a6f1f Fix dogfood and add code comments 2024-01-09 18:03:55 +01:00
Guillaume Gomez d61b92f154
Rollup merge of #119768 - ojeda:panic-link, r=Nilstrieb
core: panic: fix broken link
2024-01-09 17:52:22 +01:00
Guillaume Gomez f4d06256d8
Rollup merge of #119721 - compiler-errors:constness-implication, r=fee1-dead
`~const` trait and projection bounds do not imply their non-const counterparts

This PR removes the hack where we install a non-const trait and projection bound for every `const_trait` and `~const` projection bound we have in the AST. It ends up messing up more things than it fixes, see words below.

Fixes #119718

cc `@fmease` `@fee1-dead` `@oli-obk`
r? fee1-dead or one of y'all i don't care

---

My understanding is that this hack was added to support the following code:

```rust
pub trait Owo<X = <Self as Uwu>::T> {}

#[const_trait]
pub trait Uwu: Owo {}
```

Which is concretely lifted from in the `FromResidual` and `Try` traits. Since within the param-env of `trait Uwu`, we only know that `Self: ~const Uwu` and not `Self: Uwu`, the projection `<Self as Uwu>::T` is not satsifyable.

This causes problems such as #119718, since instantiations of `FnDef` types coming from `const fn` really do **only** implement one of `FnOnce` or `const FnOnce`!

---

In the long-term, I believe that such code should really look something more like:

```rust
#[const_trait]
pub trait Owo<X = <Self as ~const Uwu>::T> {}

#[const_trait]
pub trait Uwu: Owo {}
```

... and that we should introduce some sort of `<T as ~const Foo>::Bar` bound syntax, since due to the fact that `~const` bounds can be present in item bounds, e.g.

```rust
#[const_trait] trait Foo { type Bar: ~const Destruct; }
```

It's easy to see that `<T as Foo>::Bar` and `<T as ~const Foo>::Bar` (or `<T as const Foo>::Bar`) can be distinct types with distinct item bounds!

**Admission**: I know I've said before that I don't like `~const` projection syntax, I do at this point believe they're necessary to fully express bounds and types in a maybe-const world.
2024-01-09 17:52:21 +01:00
Guillaume Gomez 3da96aed94
Rollup merge of #118680 - djkoloski:shell_argfiles, r=compiler-errors
Add support for shell argfiles

Closes https://github.com/rust-lang/compiler-team/issues/684
2024-01-09 17:52:21 +01:00
Guillaume Gomez 87b0de6cb7
Rollup merge of #118645 - Patryk27:bump-compiler-builtins, r=Nilstrieb,dtolnay
chore: Bump compiler_builtins

Actually closes https://github.com/rust-lang/rust/issues/118079.
2024-01-09 17:52:20 +01:00
Guillaume Gomez 5e75d46b67
Rollup merge of #118241 - fortanix:raoul/gh-530-make_userspace_types_send, r=Nilstrieb,dtolnay
Making `User<T>` and `User<[T]>` `Send`

All `User` types in SGX point to owned memory in userspace. Special care is always needed when accessing this memory as it must be assumed that an attacker is always able to change its content. Therefore, we can also easily transfer this memory between thread boundaries.

cc: ``@mzohreva`` ``@vn971`` ``@belalH`` ``@jethrogb``
2024-01-09 17:52:19 +01:00
Guillaume Gomez 103e8881c6 Add tests to ensure that `map_clone` is not emitted if `as_ref().clone()` is present 2024-01-09 17:39:51 +01:00
Guillaume Gomez 83ae5edd50 Don't lint with `map_clone` if current type is `Option` or `Result` and method call is `as_ref`. 2024-01-09 17:39:51 +01:00
Guillaume Gomez e90eea7894 Clean up code in `map_clone` and `useless_asref` lints 2024-01-09 17:39:36 +01:00
León Orell Valerian Liehr 2d010bc634
Move variables closer to their usage sites 2024-01-09 17:30:52 +01:00
León Orell Valerian Liehr aa1a5e3b6f
Simplify elision of default generic arguments 2024-01-09 17:28:35 +01:00
León Orell Valerian Liehr 4b859e68aa
Don't arena-allocate extended generic args 2024-01-09 17:12:08 +01:00
Oli Scherer 4f0869ea89 Fix an ICE that occurs after an error has already been reported 2024-01-09 16:09:30 +00:00
León Orell Valerian Liehr 17ec134fa4
Update tests 2024-01-09 17:07:38 +01:00
León Orell Valerian Liehr 5b32681db1
Offset args of trait object types when cleaning 2024-01-09 17:07:33 +01:00
León Orell Valerian Liehr f141a524e8
Rename rustc_middle path cleaning functions
The new names are consistent with the other rustc_middle cleaning functions.
Regarding the local variable `ty_args`, it's used throughout the function and
personally speaking its name isn't very legible, I trip up on it.
2024-01-09 17:03:46 +01:00
Nadrieril f0511851bc
Don't mix combinators and `let else`
Co-authored-by: Michael Goulet <michael@errs.io>
2024-01-09 16:37:23 +01:00
Guillaume Gomez 8791a28c4a Also handle `Result` type for `map_clone` lint 2024-01-09 16:35:40 +01:00
Nadrieril 4a1889e3fd Document the new `expand_and_push` method 2024-01-09 16:32:17 +01:00
Nadrieril 5c65e9fdaf Avoid `PatOrWild` glob import 2024-01-09 16:22:11 +01:00
bors 5876c8cdfd Auto merge of #119767 - GuillaumeGomez:rollup-fbp26yb, r=GuillaumeGomez
Rollup of 9 pull requests

Successful merges:

 - #117556 (Disallow reference to `static mut` and adding `static_mut_ref` lint)
 - #118748 (std: getrandom simplification for freebsd.)
 - #119282 (Rework and improve the unstable documentation of check-cfg)
 - #119527 (don't reexport atomic::ordering via rustc_data_structures, use std import)
 - #119668 (Simplify implementation of MIR promotion)
 - #119699 (Merge dead bb pruning and unreachable bb deduplication.)
 - #119723 (Remove `-Zdont-buffer-diagnostics`.)
 - #119756 (rustdoc-search: reuse individual types in function signatures)
 - #119758 (GNU/Hurd: unconditionally use inline stack probes)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-01-09 14:50:14 +00:00
Miguel Ojeda 18a1ca6a17 core: panic: fix broken link
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2024-01-09 14:15:45 +01:00
Guillaume Gomez cdd96bc662 Update ui tests for `useless_asref` lint extension 2024-01-09 14:14:29 +01:00
Guillaume Gomez 4ab6924bca Extend `useless_asref` lint on `map(clone)` 2024-01-09 14:09:00 +01:00
Guillaume Gomez f41d773988
Rollup merge of #119758 - erikdesjardins:hurd, r=petrochenkov
GNU/Hurd: unconditionally use inline stack probes

LLVM 11 has been unsupported since 45591408b1, so this doesn't need to be conditional on the LLVM version.

cc `@sthibaul`
2024-01-09 13:23:19 +01:00
Guillaume Gomez f9cadb915f
Rollup merge of #119756 - notriddle:notriddle/reuse-map, r=GuillaumeGomez
rustdoc-search: reuse individual types in function signatures

Because `search.js` never mutates the function signature after loading it,
they can be safely and easily reused across functions.

This change doesn't change the format of the search index.
It only changes `search.js`.

Profiler output: https://notriddle.com/rustdoc-html-demo-9/fn-signature-opti2/index.html

<table><tr><th>benchmark<th>before<th>after

<tr><th>arti<td>

```
user: 002.228 s
sys:  000.315 s
wall: 001.663 s
child_RSS_high:     315668 KiB
group_mem_high:     285948 KiB
```

<td>

```
user: 001.805 s
sys:  000.231 s
wall: 001.398 s
child_RSS_high:     235864 KiB
group_mem_high:     203056 KiB
```

<tr><th>cortex-m<td>

```
user: 000.143 s
sys:  000.035 s
wall: 000.140 s
child_RSS_high:      59168 KiB
group_mem_high:      23000 KiB
```

<td>

```
user: 000.138 s
sys:  000.031 s
wall: 000.133 s
child_RSS_high:      58944 KiB
group_mem_high:      22220 KiB
```

<tr><th>sqlx<td>

```
user: 000.792 s
sys:  000.115 s
wall: 000.536 s
child_RSS_high:     156716 KiB
group_mem_high:     122948 KiB
```

<td>

```
user: 000.824 s
sys:  000.084 s
wall: 000.535 s
child_RSS_high:     136668 KiB
group_mem_high:     101792 KiB
```

<tr><th>stm32f4<td>

```
user: 006.665 s
sys:  003.533 s
wall: 008.624 s
child_RSS_high:    1037660 KiB
group_mem_high:    1022516 KiB
```

<td>

```
user: 005.997 s
sys:  003.185 s
wall: 007.987 s
child_RSS_high:     832068 KiB
group_mem_high:     810908 KiB
```

<tr><th>stm32f4xx-hal<td>

```
user: 000.317 s
sys:  000.051 s
wall: 000.203 s
child_RSS_high:      77060 KiB
group_mem_high:      41776 KiB
```

<td>

```
user: 000.287 s
sys:  000.046 s
wall: 000.180 s
child_RSS_high:      75216 KiB
group_mem_high:      39200 KiB
```

<tr><th>ripgrep<td>

```
user: 000.463 s
sys:  000.063 s
wall: 000.295 s
child_RSS_high:     101288 KiB
group_mem_high:      66364 KiB
```

<td>

```
user: 000.472 s
sys:  000.036 s
wall: 000.247 s
child_RSS_high:      82708 KiB
group_mem_high:      47056 KiB
```

</tr></table>
2024-01-09 13:23:19 +01:00
Guillaume Gomez b0aa3d8198
Rollup merge of #119723 - nnethercote:rm-Zdont-buffer-diagnostics, r=compiler-errors
Remove `-Zdont-buffer-diagnostics`.

It was added in #54232. It seems like it was aimed at NLL development, which is well in the past. Also, it looks like `-Ztreat-err-as-bug` can be used to achieve the same effect. So it doesn't seem necessary.

r? ``@pnkfelix``
2024-01-09 13:23:18 +01:00
Guillaume Gomez 9b905417f5
Rollup merge of #119699 - cjgillot:simplify-unreachable, r=oli-obk
Merge dead bb pruning and unreachable bb deduplication.

Both routines share the same basic structure: iterate on all bbs to identify work, and then renumber bbs.

We can do both at once.
2024-01-09 13:23:18 +01:00
Guillaume Gomez 72fdaf52e0
Rollup merge of #119668 - cjgillot:transform-promote, r=oli-obk
Simplify implementation of MIR promotion

Non-functional changes.
Best read ignoring whitespace.
2024-01-09 13:23:17 +01:00
Guillaume Gomez d3574beb5d
Rollup merge of #119527 - klensy:ordering, r=compiler-errors
don't reexport atomic::ordering via rustc_data_structures, use std import

This looks simpler.
2024-01-09 13:23:17 +01:00
Guillaume Gomez 5c9a8d7bb5
Rollup merge of #119282 - Urgau:check-cfg-rework-unstable-doc, r=JohnTitor
Rework and improve the unstable documentation of check-cfg

This PR rework and improve the unstable documentation of the check-cfg feature.

The goal is to have a simpler to understand documentation with examples that are more practical and less theoretical. As well as making the documentation more explicit about the whereabouts of the feature.

`@rustbot` label +T-compiler +F-check-cfg
2024-01-09 13:23:16 +01:00
Guillaume Gomez df2f4ae4ac
Rollup merge of #118748 - devnexen:fbsd_getrandom_simpl, r=Nilstrieb,dtolnay
std: getrandom simplification for freebsd.

it is in the libcs' crate too now.
2024-01-09 13:23:16 +01:00
Guillaume Gomez 4a24b5bc05
Rollup merge of #117556 - obeis:static-mut-ref-lint, r=davidtwco
Disallow reference to `static mut` and adding `static_mut_ref` lint

Closes #114447

r? `@scottmcm`
2024-01-09 13:23:15 +01:00
lcnr 13aa90042f this is not a rust code snippet 2024-01-09 13:10:37 +01:00
lcnr 242633fe52 add comments and tests 2024-01-09 11:53:50 +01:00
lcnr 88271deac2 avoid always rerunning in case of a cycle 2024-01-09 11:19:34 +01:00
Urgau 3611014722 Rework and improve unstable documentation of check-cfg 2024-01-09 10:51:32 +01:00
bors be00c5a9b8 Auto merge of #118968 - aliemjay:canon-static, r=lcnr
unify query canonicalization mode

Exclude from canonicalization only the static lifetimes that appear in the param env because of #118965 . Any other occurrence can be canonicalized safely AFAICT.

r? `@lcnr`
2024-01-09 09:20:33 +00:00
lcnr 118453c7e1 readd the provisional cache 2024-01-09 09:15:56 +01:00
bors dc641039d2 Auto merge of #117703 - compiler-errors:recursive-async, r=lcnr
Support async recursive calls (as long as they have indirection)

Before #101692, we stored coroutine witness types directly inside of the coroutine. That means that a coroutine could not contain itself (as a witness field) without creating a cycle in the type representation of the coroutine, which we detected with the `OpaqueTypeExpander`, which is used to detect cycles when expanding opaque types after that are inferred to contain themselves.

After `-Zdrop-tracking-mir` was stabilized, we no longer store these generator witness fields directly, but instead behind a def-id based query. That means there is no technical obstacle in the compiler preventing coroutines from containing themselves per se, other than the fact that for a coroutine to have a non-infinite layout, it must contain itself wrapped in a layer of allocation indirection (like a `Box`).

This means that it should be valid for this code to work:

```
async fn async_fibonacci(i: u32) -> u32 {
    if i == 0 || i == 1 {
        i
    } else {
        Box::pin(async_fibonacci(i - 1)).await
          + Box::pin(async_fibonacci(i - 2)).await
    }
}
```

Whereas previously, you'd need to coerce the future to `Pin<Box<dyn Future<Output = ...>>` before `await`ing it, to prevent the async's desugared coroutine from containing itself across as await point.

This PR does two things:
1. Only report an error if an opaque expansion cycle is detected *not* through coroutine witness fields.
    * Instead, if we find an opaque cycle through coroutine witness fields, we compute the layout of the coroutine. If that results in a cycle error, we report it as a recursive async fn.
4. Reworks the way we report layout errors having to do with coroutines, to make up for the diagnostic regressions introduced by (1.). We actually do even better now, pointing out the call sites of the recursion!
2024-01-09 07:20:50 +00:00