Commit Graph

272032 Commits

Author SHA1 Message Date
Jacob Pratt
5880752b9a
Rollup merge of #131784 - Urgau:stabilize-midpoint, r=dtolnay
Stabilize unsigned and float variants of `num_midpoint` feature

This PR proposes that we stabilize the unsigned variants of the [`num_midpoint`](https://github.com/rust-lang/rust/issues/110840#issue-1684506201) feature as well as the floats variants, since they are not subject to any unresolved questions, which is equivalent to doing `(a + b) / 2` (and `(a + b) >> 1`) in a sufficiently large number.

The stabilized API surface would be:

```rust
/// Calculates the middle point of `self` and `rhs`.
///
/// `midpoint(a, b)` is `(a + b) / 2` as if it were performed in a sufficiently-large unsigned integral type.
/// This implies that the result is always rounded towards negative infinity and that no overflow will ever occur.

impl u{8,16,32,64,128,size} {
    pub const fn midpoint(self, rhs: Self) -> Self;
}

impl NonZeroU{8,16,32,64,size} {
    pub const fn midpoint(self, rhs: Self) -> Self;
}

impl f{32,64} {
    pub const fn midpoint(self, rhs: Self) -> Self;
}
```

The signed variants `u{8,16,32,64,128,size}` would remain gated, until a decision is made about the rounding mode, in other words that the [unresolved questions](https://github.com/rust-lang/rust/issues/110840#issue-1684506201) are resolved.

cc `@rust-lang/libs-api`
cc `@scottmcm`
r? libs-api
2024-12-01 21:38:24 -05:00
Jacob Pratt
cb67512784
Rollup merge of #131416 - okaneco:const_copy, r=RalfJung
Mark `slice::copy_from_slice` unstably const

Tracking issue #131415

I used `const_eval_select` for runtime and const panic functions because const formatting isn't available yet.
2024-12-01 21:38:23 -05:00
bors
a522d78598 Auto merge of #133345 - GuillaumeGomez:stop-cloning-context, r=notriddle,aDotInTheVoid
Stop cloning `Context` so much

This is a first step for https://github.com/rust-lang/rust/issues/82381.

It's already big enough so I'll continue in a follow-up once this PR is merged. Next step will be to get rid of `SharedContext` by inlining it directly into `Context`.

cc `@camelid`
r? `@notriddle`
2024-12-01 22:32:36 +00:00
okaneco
7f011a894f Mark slice::copy_from_slice unstably const 2024-12-01 16:39:56 -05:00
Guillaume Gomez
69ed026f7e Fix link to FormatRenderer method 2024-12-01 21:54:55 +01:00
Guillaume Gomez
b4921706f0 Rename FormatRenderer::InfoType into ModuleData and rename FormatRenderer::make_child_renderer into save_module_data 2024-12-01 21:54:55 +01:00
Guillaume Gomez
e60a7a4c24 Add unreachable! in new FormatRenderer methods for JsonRenderer implementation 2024-12-01 21:54:55 +01:00
Guillaume Gomez
5f9e71627c Add documentation for new FormatRenderer trait items 2024-12-01 21:54:55 +01:00
Guillaume Gomez
5fa1653c5c Move SharedContext out of Rc 2024-12-01 21:54:55 +01:00
Guillaume Gomez
2e242f8af3 Store default ID map in a static 2024-12-01 21:54:55 +01:00
Guillaume Gomez
46afbc0588 Split ID maps in two parts: the constant one and the updated one 2024-12-01 21:54:55 +01:00
Guillaume Gomez
8047340599 Stop cloning Context so much 2024-12-01 21:54:54 +01:00
bors
5e1440ae51 Auto merge of #133703 - matthiaskrgr:rollup-fwlw0mc, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #132974 (Properly pass linker arguments that contain commas)
 - #133403 (Make `adjust_fulfillment_errors` work with `HostEffectPredicate` and `const_conditions`)
 - #133482 (Only error raw lifetime followed by `\'` in edition 2021+)
 - #133595 (Do not emit `missing_doc_code_examples` rustdoc lint on module and a few other items)
 - #133669 (Move some functions out of const_swap feature gate)
 - #133674 (Fix chaining `carrying_add`s)
 - #133691 (Check let source before suggesting annotation)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-12-01 19:49:19 +00:00
bors
1555074ca9 Auto merge of #133532 - rami3l:ci/bump-ubuntu, r=Kobzol
Bump unsupported `ubuntu` CI images to 24.04 LTS

Closes #133531.

try-job: arm-android
try-job: dist-android
try-job: dist-ohos
2024-12-01 16:57:16 +00:00
Matthias Krüger
78dad1ee56
Rollup merge of #133691 - compiler-errors:let-source, r=lqd
Check let source before suggesting annotation

Make sure we don't annotate nonsense type annotations on locals that come from desugarings.

fixes #133688
2024-12-01 14:30:11 +01:00
Matthias Krüger
2f00feb616
Rollup merge of #133674 - scottmcm:chain-carrying-add, r=Amanieu
Fix chaining `carrying_add`s

Something about the MIR lowering for `||` ended up breaking this, but it's fixed by changing the code to use `|` instead.

I also added an assembly test to ensure it *keeps* being [`adc`](https://www.felixcloutier.com/x86/adc).

cc https://github.com/rust-lang/rust/issues/85532#issuecomment-2495119815, which noticed this.
2024-12-01 14:30:11 +01:00
Matthias Krüger
3d18c3c414
Rollup merge of #133669 - RalfJung:const_swap_splitup, r=dtolnay
Move some functions out of const_swap feature gate

- `swap_unchecked` is still unstable as a regular fn, so that feature gate can also cover its constness.
- `swap_nonoverlapping` isn't ready to be stabilized yet, so make it a different feature gate.

Part of https://github.com/rust-lang/rust/issues/83163, https://github.com/rust-lang/rust/issues/88539, https://github.com/rust-lang/rust/issues/133668
2024-12-01 14:30:10 +01:00
Matthias Krüger
2713dc2641
Rollup merge of #133595 - GuillaumeGomez:missing_doc_code_examples, r=notriddle
Do not emit `missing_doc_code_examples` rustdoc lint on module and a few other items

It doesn't make sense to expect modules to have code examples. Same goes for:

 * Trait aliases
 * Foreign items
 * Associated types and constants

Should make the use of this lint a bit nicer.

r? ``@notriddle``
2024-12-01 14:30:09 +01:00
Matthias Krüger
337c48cec5
Rollup merge of #133482 - compiler-errors:raw-lt-tick, r=estebank
Only error raw lifetime followed by `\'` in edition 2021+

Fixes #133479
cc #132341

I think this fixes a purely theoretical regression since it only affects edition 2015 (who is using that?) and only in the very rare case of a raw lifetime followed immediately by a lifetime like `'r#a'r`.
2024-12-01 14:30:08 +01:00
Matthias Krüger
b574158394
Rollup merge of #133403 - compiler-errors:adjust-host-effect-preds, r=fee1-dead,lcnr
Make `adjust_fulfillment_errors` work with `HostEffectPredicate` and `const_conditions`

Greatly improves the spans for reporting unsatisfied `~const` bounds :)

r? project-const-traits or maybe ``@lcnr`` (if you want to deal with a diagnostics PR lmao)
2024-12-01 14:30:07 +01:00
Matthias Krüger
ae6a7dba2a
Rollup merge of #132974 - madsmtm:linker-arguments-with-commas, r=petrochenkov
Properly pass linker arguments that contain commas

When linking with the system C compiler, we sometimes want to forward certain arguments unchanged to the linker. This can be done with `-Wl,arg1,arg2` or `-Xlinker arg1 -Xlinker arg2`. `-Wl` is used when possible, since it is more compact, but it does not support commas in the argument itself - in those cases, we need to use `-Xlinker`, and that is what this PR implements.

This also fixes using sanitizers on macOS with `-Clinker-flavor=ld`, as those were previously manually using `-Wl`/`-Xlinker` (probably since the support wasn't present in the `link_args` function).

Note that there has been [a previous PR for this](https://github.com/rust-lang/rust/pull/38798), but it only implemented this in certain cases when passing `-rpath`.

r? compiler
2024-12-01 14:30:07 +01:00
bors
ca4e54f032 Auto merge of #132390 - RalfJung:diagnostics-root-dir, r=albertlarsan68,weihanglo
bootstrap: show diagnostics relative to rustc src dir

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

Depends on https://github.com/rust-lang/cargo/pull/14752 propagating to bootstrap cargo
2024-12-01 13:09:56 +00:00
Urgau
b88478f707 Stabilize unsigned num_midpoint feature 2024-12-01 11:28:53 +01:00
Ralf Jung
dd2ac08cfe fix cargo path logic 2024-12-01 11:21:41 +01:00
bors
6c76ed5503 Auto merge of #133694 - matthiaskrgr:rollup-s6xj4rf, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #128184 (std: refactor `pthread`-based synchronization)
 - #132047 (Robustify and genericize return-type-notation resolution in `resolve_bound_vars`)
 - #133515 (fix: hurd build, stat64.st_fsid was renamed to st_dev)
 - #133602 (fix: fix codeblocks in `PathBuf` example)
 - #133622 (update link to "C++ Exceptions under the hood" blog)
 - #133660 (Do not create trait object type if missing associated types)
 - #133686 (Add diagnostic item for `std::ops::ControlFlow`)
 - #133689 (Fixed typos by changing `happend` to `happened`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-12-01 07:53:58 +00:00
Matthias Krüger
c0fa0ec7b5
Rollup merge of #133689 - HomelikeBrick42:master, r=jieyouxu
Fixed typos by changing `happend` to `happened`

I just noticed this typo before and decided to fix it :3
2024-12-01 08:15:26 +01:00
Matthias Krüger
3d365795fa
Rollup merge of #133686 - samueltardieu:push-xkxwxzxqokuu, r=compiler-errors
Add diagnostic item for `std::ops::ControlFlow`

This will be used in Clippy to detect useless conversions done through `ControlFlow::map_break()` and `ControlFlow::map_continue()`.
2024-12-01 08:15:25 +01:00
Matthias Krüger
4d5ad194d5
Rollup merge of #133660 - compiler-errors:trait-obj-missing-assoc, r=lcnr
Do not create trait object type if missing associated types

r? lcnr
2024-12-01 08:15:25 +01:00
Matthias Krüger
5d87be3b3c
Rollup merge of #133622 - mkroening:exception-blog, r=cuviper
update link to "C++ Exceptions under the hood" blog

The link was introduced in 0ec321f7b5. For the old link, see https://web.archive.org/web/20170409223244/https://monoinfinito.wordpress.com/series/exception-handling-in-c/. The blog has migrated from WordPress to Blogger in 2021 and to GitHub pages in 2024.
2024-12-01 08:15:24 +01:00
Matthias Krüger
61d50fd0ac
Rollup merge of #133602 - SanchithHegde:fix-pathbuf-example-codeblocks, r=cuviper
fix: fix codeblocks in `PathBuf` example

This PR adds missing codeblocks around an example included in the `PathBuf` documentation.
2024-12-01 08:15:23 +01:00
Matthias Krüger
ec7caabe97
Rollup merge of #133515 - SteveLauC:fix/hurd, r=ChrisDenton
fix: hurd build, stat64.st_fsid was renamed to st_dev

On hurd, `stat64.st_fsid` was renamed to `st_dev` in https://github.com/rust-lang/libc/pull/3785, so if you have a new libc with this patch included, and you build std from source, you get this error:

```sh
error[E0609]: no field `st_fsid` on type `&stat64`
   --> /home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/os/hurd/fs.rs:301:36
    |
301 |         self.as_inner().as_inner().st_fsid as u64
    |                                    ^^^^^^^ unknown field
    |
help: a field with a similar name exists
    |
301 |         self.as_inner().as_inner().st_uid as u64
    |                                    ~~~~~~
```

Full CI log: https://github.com/nix-rust/nix/actions/runs/12033180710/job/33546728266?pr=2544
2024-12-01 08:15:22 +01:00
Matthias Krüger
20af878588
Rollup merge of #132047 - compiler-errors:rbv-rtn-cleanup, r=cjgillot
Robustify and genericize return-type-notation resolution in `resolve_bound_vars`

#129629 implemented return-type-notation (RTN) in its path form, like `where T::method(..): Bound`. As part of lowering, we must record the late-bound vars for the where clause introduced by the method (namely, its early- and late-bound lifetime arguments, since `where T::method(..)` turns into a higher-ranked where clause over all of the lifetimes according to [RFC 3654](https://rust-lang.github.io/rfcs/3654-return-type-notation.html#converting-to-higher-ranked-trait-bounds)).

However, this logic was only looking at the where clauses of the parent item that the `T::method(..)` bound was written on, and not any parent items. This PR generalizes that logic to look at the parent item (i.e. the outer impl or trait) instead and fixes a (debug only) assertion as an effect.

This logic is also more general and likely easier to adapt to more interesting (though likely very far off) cases like non-lifetime binder `for<T: Trait> T::method(..): Send` bounds.

Tracking:

- https://github.com/rust-lang/rust/issues/109417
2024-12-01 08:15:21 +01:00
Matthias Krüger
fe4c6e8657
Rollup merge of #128184 - joboet:refactor_pthread_sync, r=workingjubilee
std: refactor `pthread`-based synchronization

The non-trivial code for `pthread_condvar` is duplicated across the thread parking and the `Mutex`/`Condvar` implementations. This PR moves that code into `sys::pal`, which now exposes an `unsafe` wrapper type for `pthread_mutex_t` and `pthread_condvar_t`.
2024-12-01 08:15:21 +01:00
Michael Goulet
d878fd8877 Only error raw lifetime followed by \' in edition 2021+ 2024-12-01 05:23:16 +00:00
Michael Goulet
b87e935407 Revert "Reject raw lifetime followed by \' as well"
This reverts commit 1990f15608.
2024-12-01 05:22:16 +00:00
Michael Goulet
d5c5d58a37 Pull out expr handling 2024-12-01 05:11:42 +00:00
Michael Goulet
30afeb0357 Adjust HostEffect error spans correctly to point at args 2024-12-01 05:11:42 +00:00
Michael Goulet
17c6efa978 Disentangle hir node match logic in adjust_fulfillment_errors 2024-12-01 05:11:42 +00:00
bors
8ac313bdbe Auto merge of #133499 - nikic:no-backend-verify, r=Mark-Simulacrum
Respect verify-llvm-ir option in the backend

We are currently unconditionally verifying the LLVM IR in the backend (twice), ignoring the value of the verify-llvm-ir option. This has substantial compile-time impact for debug builds.
2024-12-01 04:54:02 +00:00
Michael Goulet
805649b648 Check let source before suggesting annotation 2024-12-01 03:01:05 +00:00
bors
4af7fa79a0 Auto merge of #133365 - compiler-errors:compare-impl-item, r=lcnr
Make `compare_impl_item` into a query

Turns `compare_impl_item` into a query (generalizing the existing query for `compare_impl_const`), and uses that in `Instance::resolve` to fail resolution when an implementation is incompatible with the trait it comes from.

Fixes #119701
Fixes #121127
Fixes #121411
Fixes #129075
Fixes #129127
Fixes #129214
Fixes #131294
2024-12-01 01:59:24 +00:00
HomelikeBrick42
4cb158278c Fixed typos by changing happend to happened 2024-12-01 11:31:09 +13:00
bors
7442931d49 Auto merge of #133684 - RalfJung:rollup-j2tmrg7, r=RalfJung
Rollup of 6 pull requests

Successful merges:

 - #131698 (use stores of the correct size to set discriminants)
 - #133571 (Mark visionOS as supporting `std`)
 - #133655 (Eliminate print_expr_maybe_paren function from pretty printers)
 - #133667 (Remove unused code)
 - #133670 (bump hashbrown version)
 - #133673 (replace hard coded error id with `ErrorKind::DirectoryNotEmpty`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-11-30 21:08:45 +00:00
Guillaume Gomez
b118d05f57 Extend documentation for missing_doc_code_examples rustdoc lint in the rustdoc book 2024-11-30 20:22:56 +01:00
Samuel Tardieu
484c561d78 Add diagnostic item for std::ops::ControlFlow
This will be used in Clippy to detect useless conversions done through
`ControlFlow::map_break()` and `ControlFlow::map_continue()`.
2024-11-30 19:53:36 +01:00
Ralf Jung
bdb44d0227
Rollup merge of #133673 - onur-ozkan:windows-fixme, r=Kobzol
replace hard coded error id with `ErrorKind::DirectoryNotEmpty`

Resolves an internal bootstrap FIXME.
2024-11-30 19:24:43 +01:00
Ralf Jung
ec000a7e85
Rollup merge of #133670 - RalfJung:hashbrown, r=Amanieu
bump hashbrown version

This pulls in https://github.com/rust-lang/hashbrown/pull/586, in preparation for https://github.com/rust-lang/rust/issues/102575.

Cc ``@Amanieu``
2024-11-30 19:24:43 +01:00
Ralf Jung
35e92ae025
Rollup merge of #133667 - sunwxg:xiaoguang/remove-unused-code, r=clubby789
Remove unused code
2024-11-30 19:24:42 +01:00
Ralf Jung
78fecaaec8
Rollup merge of #133655 - dtolnay:maybeparen, r=lcnr
Eliminate print_expr_maybe_paren function from pretty printers

This PR is part of backporting Syn's expression precedence design into rustc. (See #133603 for other work on this.)

In Syn, our version of `print_expr_cond_paren` is called `print_subexpression` and it is called from 19 places. Of those calls, 12 of them need a "custom" behavior for the `needs_paren` argument, whereas only 7 use a "standard" behavior resembling `print_subexpression($e, $e.precedence() < Precedence::$Variant, ...)`. In other words the behavior that rustc_ast_pretty's `print_expr_maybe_paren` implements is actually not what you want most of the time. The current usage you see in rustc is overuse.

<details>
<summary>Aside: am I confident about the correctness of Syn's parenthesization? Yes. Click for details.</summary>

---

The behavior is constrained by the following pair of tests which both run over every Rust source file of rustc and the standard library and tools and test suites:

- To rule out **false positives**: for every expression in every source file, print the expression, parse it back, and verify that not a single new parenthesis got added. Since these are expressions parsed from source code, not macro-generated syntax trees, we know they must never need automatic parenthesis insertion. Rustc's pretty printer does not pass this.

    Pseudocode: `assert(expr == parse(print(expr)))`

- To rule out **false negatives**: for every expression in every source file, replace every Expr::Paren node in the syntax tree with just its contents, i.e. stripping the parentheses but otherwise preserving the syntax tree structure. Then print the stripped expression performing parenthesis insertion wherever needed, and reparse it. Verify that the reparsed expression has identical structure to the original, despite there being no parentheses in the original prior to printing, i.e. all the right parentheses got re-inserted by the printer to preserve the expression's structure. Rustc's pretty printer does not pass this. See https://github.com/dtolnay/syn/pull/1788 which reveals multiple rustc_ast_pretty bugs.

    Pseudocode: `assert(unparenthesize(expr) == unparenthesize(parse(print(unparenthesize(expr)))))`

---
</details>

If `print_expr_maybe_paren` is usually not correct, is there harm in keeping it for the minority of cases where it is correct? I think the answer is yes and Syn doesn't use any equivalent of this helper function. The problems with it are:

- Having both `print_expr_maybe_paren` and `print_expr_cond_paren` applies counterproductive inertia against moving from the first to the second. When looking at a call site like `print_expr_maybe_paren(e, Precedence::$Variant, ...)` with parentheses not being inserted where they should be, anyone's first inclination would be to solve the bug by tweaking $Variant because that is the only knob that visibly appears in the function call. For example to pass "prec + 1", like tweaking the code to conditionally pass `Precedence::Prefix` instead of `Precedence::Cast`.

    Experience in Syn shows this is (almost?) never what you want the person to do. In a call `print_expr_cond_paren(e, e.precedence() < ExprPrecedence::$Variant, ...)` almost always the best fix involves one of:

    - Changing `e.precedence()`, e.g. to `fixup.leading_precedence(e)` and `fixup.trailing_precedence(e)` in cases of asymmetrical precedence (`(return 1) + 1` vs `1 + return 1`).

    - Changing `<` to `<=`, to handle associativity and other grammar restrictions like chained comparisons (which rustc gets wrong today).

    - Adding `||` and/or `&&` clauses to the condition.

    By using these 3 better knobs instead of $Variant, it upholds the property that any time we talk about precedence, it is always the precedence of some actual expression that our code is actively manipulating, instead of a value standing in for some imaginary precedence level that would exist between two consecutive [real levels](https://doc.rust-lang.org/1.83.0/reference/expressions.html#expression-precedence). For example consider that "`Cast` + 1" might be `Prefix` today, but only until some new Rust syntax ends up adding a level between those.

- The `print_expr_maybe_paren` call sites look shorter, but they are not clearer. For myself, a function argument that says "does this subexpression need parenthesization" is a concrete thing that is easy to think about, while a function argument that is "what is the effective precedence level associated with this subexpression's placement inside its parent expression" is abstract and tricky to even state a precise meaning for. I expect that for someone less familiar with the pretty printer working on adding a new expression kind (like postfix match, recently), having every subexpression consistently printed using `print_expr_cond_paren` will be more beneficial, for the same reason, than having `print_expr_maybe_paren` available.

r? ``@lcnr``
2024-11-30 19:24:42 +01:00
Ralf Jung
2aee158761
Rollup merge of #133571 - madsmtm:visionos-support-std, r=Noratrieb
Mark visionOS as supporting `std`

Cargo's -Zbuild-std has recently started checking this field, which causes it to fail to compile even though we have full support for the standard library on these targets.

[Example of failed build](https://github.com/rust-random/getrandom/actions/runs/12069033154/job/33655430622).

Affected targets: `aarch64-apple-visionos` and `aarch64-apple-visionos-sim`.

r? Noratrieb (because you've worked with `rustc` target metadata IIRC)
``@rustbot`` label O-visionos
2024-11-30 19:24:41 +01:00