Commit Graph

283436 Commits

Author SHA1 Message Date
Matthias Krüger
f5a143f796
Rollup merge of - spastorino:ergonomic-ref-counting-1, r=nikomatsakis
Ergonomic ref counting

This is an experimental first version of ergonomic ref counting.

This first version implements most of the RFC but doesn't implement any of the optimizations. This was left for following iterations.

RFC: https://github.com/rust-lang/rfcs/pull/3680
Tracking issue: https://github.com/rust-lang/rust/issues/132290
Project goal: https://github.com/rust-lang/rust-project-goals/issues/107

r? ```@nikomatsakis```
2025-03-07 19:15:33 +01:00
bors
03eb454523 Auto merge of - matthiaskrgr:rollup-xq5buio, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 -  (Enable `f16` for LoongArch)
 -  (library: Use `size_of` from the prelude instead of imported)
 -  (Revert  after further discussion about how hir-pretty printing should work)
 -  (Break critical edges in inline asm before code generation)
 -  (`librustdoc`: clippy fixes)
 -  (Use `default_field_values` for `rustc_errors::Context`, `rustc_session::config::NextSolverConfig` and `rustc_session::config::ErrorOutputType`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-07 13:47:27 +00:00
bors
59a9b9e9d7 Auto merge of - matthiaskrgr:rollup-j0p6ed1, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 -  (Revert vita's c_char back to i8)
 -  (Override default `Write` methods for cursor-like types)
 -  (Specialize `OsString::push` and `OsString as From` for UTF-8)
 -  (Fix crash in BufReader::peek())
 -  (Improve the generic MIR in the default `PartialOrd::le` and friends)
 -  (Suggest typo fix for static lifetime)
 -  (Simplify `printf` and shell format suggestions)
 -  (Stabilize const_char_classify, const_sockaddr_setters)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-07 10:40:12 +00:00
Matthias Krüger
acc7de6c77
Rollup merge of - estebank:use-dfv, r=nnethercote
Use `default_field_values` for `rustc_errors::Context`, `rustc_session::config::NextSolverConfig` and `rustc_session::config::ErrorOutputType`

Wanted to see  where `#![feature(default_field_values)]` could be used in the codebase. These three seemed like no-brainers. There are a bunch of more places where we could remove manual `Default` impls, but they `derive` other traits that rely on `syn`, which [doesn't yet support `default_field_values`](https://github.com/dtolnay/syn/issues/1774).
2025-03-07 10:12:48 +01:00
Matthias Krüger
4b6a22d05c
Rollup merge of - yotamofek:pr/rustdoc/clippy, r=GuillaumeGomez
`librustdoc`: clippy fixes

First commit is all machine-generated fixes,
next two are some more lints fixed by hand/misc. cleanups

Inspired by the redundant `.and_then()` added in https://github.com/rust-lang/rust/pull/137320 , and [this comment](https://github.com/rust-lang/rust/pull/138090#discussion_r1983111856)

r? ```@GuillaumeGomez```
2025-03-07 10:12:47 +01:00
Matthias Krüger
1155f01c5a
Rollup merge of - tmiasko:inline-asm-critical-edges, r=bjorn3
Break critical edges in inline asm before code generation

An inline asm terminator defines outputs along its target edges -- a
fallthrough target and labeled targets. Code generation implements this
by inserting code directly into the target blocks. This approach works
only if the target blocks don't have other predecessors.

Establish required invariant by extending existing code that breaks
critical edges before code generation.

Fixes .

r? ``@bjorn3``
2025-03-07 10:12:46 +01:00
Matthias Krüger
f42c933c29
Rollup merge of - jdonszelmann:revert-138019, r=compiler-errors
Revert  after further discussion about how hir-pretty printing should work

After some more discussion,  was probably merged a little fast. Though there probably is a real bug in pretty printing, it is not feasible to add similar pretty printing routines for all attributes, and making this specific exception is likely not desired either. For more context, see post-merge comments on 

I kept the tests around, but reverted the hir-pretty change.

r? ```@compiler-errors```
2025-03-07 10:12:45 +01:00
Matthias Krüger
b834632071
Rollup merge of - thaliaarchi:use-prelude-size-of, r=tgross35
library: Use `size_of` from the prelude instead of imported

Use `std::mem::{size_of, size_of_val, align_of, align_of_val}` from the prelude instead of importing or qualifying them.

These functions were added to all preludes in Rust 1.80.

try-job: test-various
try-job: x86_64-gnu
try-job: x86_64-msvc-1
2025-03-07 10:12:44 +01:00
Matthias Krüger
6e7d1353d1
Rollup merge of - heiher:enable-f16-loong, r=tgross35
Enable `f16` for LoongArch

Blocked on https://github.com/rust-lang/compiler-builtins/pull/770

r? ```@tgross35```

Tracking issue for f16: https://github.com/rust-lang/rust/issues/116909

try-job: dist-loongarch64-linux
try-job: dist-loongarch64-musl
2025-03-07 10:12:43 +01:00
Matthias Krüger
c33e9d6844
Rollup merge of - RalfJung:stabilize-const-things, r=tgross35
Stabilize const_char_classify, const_sockaddr_setters

FCP for const_char_classify: 
FCP for const_sockaddr_setters: 

Fixes 
Fixes 

Cc ``@rust-lang/wg-const-eval``
2025-03-07 10:02:30 +01:00
Matthias Krüger
a928c15066
Rollup merge of - thaliaarchi:defer-alloc-printf-suggestion, r=compiler-errors
Simplify `printf` and shell format suggestions

Simplify tracking `printf` and shell format suggestions. Although allocations could be deferred until after checking that they aren't already in the map, this style is simpler.
2025-03-07 10:02:28 +01:00
Matthias Krüger
79a8c6da42
Rollup merge of - compiler-errors:static-typo, r=BoxyUwU
Suggest typo fix for static lifetime

...and don't try to introduce a new lifetime param named something like `'statoc`.
2025-03-07 10:02:27 +01:00
Matthias Krüger
9e16082e63
Rollup merge of - scottmcm:ordering-is, r=workingjubilee
Improve the generic MIR in the default `PartialOrd::le` and friends

It looks like I regressed this accidentally in  due to 

So this PR does two things:
1. Tweaks the way we're calling `is_some_and` so that it optimizes in the generic MIR (rather than needing to optimize it in every monomorphization) -- the first commit adds a MIR test, so you can see the difference in the second commit.
2. Updates the implementations of `is_le` and friends to be slightly simpler, and parallel how clang does them.
2025-03-07 10:02:26 +01:00
Matthias Krüger
a98df54bdc
Rollup merge of - wgwoods:fix-bufreader-peek, r=joboet
Fix crash in BufReader::peek()

`bufreader_peek` tracking issue: 

This fixes a logic error in `Buffer::read_more()` that would make `BufReader::peek()` expose uninitialized data and/or segfault if `read_more()` was called with a partially-full buffer and a non-empty inner reader.
2025-03-07 10:02:22 +01:00
Matthias Krüger
d9860276b8
Rollup merge of - thaliaarchi:os_string-push-str, r=joboet
Specialize `OsString::push` and `OsString as From` for UTF-8

When concatenating two WTF-8 strings, surrogate pairs at the boundaries need to be joined. However, since UTF-8 strings cannot contain surrogate halves, this check can be skipped when one string is UTF-8. Specialize `OsString::push` to use a more efficient concatenation in this case.

The WTF-8 version of `OsString` tracks whether it is known to be valid UTF-8 with its `is_known_utf8` field. Specialize `From<AsRef<OsStr>>` so this can be set for UTF-8 string types.

Unfortunately, a specialization for `T: AsRef<str>` conflicts with `T: AsRef<OsStr>`, so stamp out string types with a macro.

r? ``@ChrisDenton``
2025-03-07 10:02:20 +01:00
Matthias Krüger
458095aa17
Rollup merge of - thaliaarchi:io-optional-methods/cursors, r=joboet
Override default `Write` methods for cursor-like types

Override the default `io::Write` methods for cursor-like types to provide more efficient versions.

Writes to resizable containers already write everything, so implement `write_all` and `write_all_vectored` in terms of those. For fixed-sized containers, cut out unnecessary error checking and looping for those same methods.

| `impl Write for T`              | `vectored` | `all` | `all_vectored` | `fmt`   |
| ------------------------------- | ---------- | ----- | -------------- | ------- |
| `&mut [u8]`                     | Y          | Y     | new            |         |
| `Vec<u8>`                       | Y          | Y     | new            |  |
| `VecDeque<u8>`                  | Y          | Y     | new            |  |
| `std::io::Cursor<&mut [u8]>`    | Y          | new   | new            |         |
| `std::io::Cursor<&mut Vec<u8>>` | Y          | new   | new            |  |
| `std::io::Cursor<Vec<u8>>`      | Y          | new   | new            |  |
| `std::io::Cursor<Box<[u8]>>`    | Y          | new   | new            |         |
| `std::io::Cursor<[u8; N]>`      | Y          | new   | new            |         |
| `core::io::BorrowedCursor<'_>`  | new        | new   | new            |         |

Tracked in https://github.com/rust-lang/rust/issues/136756.

# Open questions

Is it guaranteed by `Write::write_all` that the maximal write is performed when not everything can be written? Its documentation describes the behavior of the default implementation, which writes until a 0-length write is encountered, thus implying that a maximal write is expected. In contrast, `Read::read_exact` declares that the contents of the buffer are unspecified for short reads. If it were allowed, these cursor-like types could bail on the write altogether if it has insufficient capacity.
2025-03-07 10:02:20 +01:00
Matthias Krüger
0b151c6c4f
Rollup merge of - vita-rust:revert-vita-c-char, r=cuviper
Revert vita's c_char back to i8

# Description

Hi!

https://github.com/rust-lang/rust/pull/132975 changed the definition of `c_char` from i8 to u8 for most ARM targets. While that would usually be correct, [VITASDK uses signed chars by default](https://github.com/vitasdk/buildscripts/blob/master/patches/gcc/0001-gcc-10.patch#L33-L34). The Clang definitions are incorrect because Clang is not (yet?) supported by the vita commmunity / `VITADSK`, On the Rust side, the pre-compiled libraries the user can link to are all compiled using vita's `gcc` and [we set `TARGET_CC` and `TARGET_CXX`](d564a132cb/src/commands/build.rs (L230)) in `cargo vita` for build scripts using `cc`.

I'm creating it as a draft PR so that we can discuss it and possibly get it approved here, but wait to merge the [libc side](https://github.com/rust-lang/libc/pull/4258) and get a libc version first, as having the definitions out of sync breaks std. As a nightly-only target it can be confusing/frustrating for new users when the latest nightly, which is the default, is broken.
2025-03-07 10:02:19 +01:00
Thalia Archibald
5dfa2f5fd0 Use turbofish for size_of<T> and align_of<T> in docs 2025-03-06 20:20:38 -08:00
Thalia Archibald
988eb19970 library: Use size_of from the prelude instead of imported
Use `std::mem::{size_of, size_of_val, align_of, align_of_val}` from the
prelude instead of importing or qualifying them.

These functions were added to all preludes in Rust 1.80.
2025-03-06 20:20:38 -08:00
bors
91a0e1604f Auto merge of - compiler-errors:rollup-kcarqrz, r=compiler-errors
Rollup of 17 pull requests

Successful merges:

 -  (Add timestamp to unstable feature usage metrics)
 -  (bootstrap and compiletest: Use `size_of_val` from the prelude instead of imported)
 -  (trim channel value in `get_closest_merge_commit`)
 -  (Increase the max. custom try jobs requested to `20`)
 -  (triagebot: add a `compiler_leads` ad-hoc group)
 -  (Remove - from xtensa targets cpu names)
 -  (Use final path segment for diagnostic)
 -  (Reduce the noise of bootstrap changelog warnings in --dry-run mode)
 -  (Move `yield` expressions behind their own feature gate)
 -  (`librustdoc`: flatten nested ifs)
 -  (Re-add `DynSend` and `DynSync` impls for `TyCtxt`)
 -  (a small borrowck cleanup)
 -  (Stabilize feature `const_copy_from_slice`)
 -  (Git ignore citool's target directory)
 -  (Fix broken link to Miri intrinsics in documentation)
 -  (Mention me (WaffleLapkin) when changes to `rustc_codegen_ssa` occur)
 -  ([llvm/PassWrapper] use `size_t` when building arg strings)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-07 02:56:46 +00:00
Santiago Pastorino
d2bde63b7a
Add slight variation to feature-gate ergonomic clones test 2025-03-06 22:36:07 -03:00
bors
98a48781fe Auto merge of - compiler-errors:rollup-7xr4b69, r=compiler-errors
Rollup of 25 pull requests

Successful merges:

 -  (Implement `&pin const self` and `&pin mut self` sugars)
 -  (Document workings of successors more clearly)
 -  (Pattern types: Avoid having to handle an Option for range ends in the type system or the HIR)
 -  (Remove `MaybeForgetReturn` suggestion)
 -  (Undeprecate env::home_dir)
 -  (Match Ergonomics 2024: add context and examples to the unstable book)
 -  ([rustdoc] hide item that is not marked as doc(inline) and whose src is doc(hidden))
 -  (Try to point of macro expansion from resolver and method errors if it involves macro var)
 -  (Check dyn flavor before registering upcast goal on wide pointer cast in MIR typeck)
 -  (Add DWARF test case for non-C-like `repr128` enums)
 -  (Re-add `Clone`-derive on `Thir`)
 -  (fix usage of ty decl macro fragments in attributes)
 -  (Ensure that negative auto impls are always applicable)
 -  (Fix char count in `Display` for `ByteStr`)
 -  (ci: use ubuntu 24 on arm large runner)
 -  (miri native-call support: all previously exposed provenance is accessible to the callee)
 -  (adjust Layout debug printing to match the internal field name)
 -  (Do not require that unsafe fields lack drop glue)
 -  (Clarify why InhabitedPredicate::instantiate_opt exists)
 -  (Provide more context on resolve error caused from incorrect RTN)
 -  (rustc_fluent_macro: use CARGO_CRATE_NAME instead of CARGO_PKG_NAME)
 -  (Add minimal platform support documentation for powerpc-unknown-linux-gnuspe)
 -  (Improve error message for `AsyncFn` trait failure for RPIT)
 -  (interpret/provenance_map: consistently use range_is_empty)
 -  (Update `compiler-builtins` to 0.1.151)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-06 23:39:38 +00:00
Thalia Archibald
2458ccd1f9 Simplify printf and shell format suggestions 2025-03-06 13:55:05 -08:00
Ralf Jung
8f8c7fcb8b stabilize const_sockaddr_setters 2025-03-06 22:29:07 +01:00
Ralf Jung
98dc15fb0f stabilize const_char_classify 2025-03-06 22:28:48 +01:00
Santiago Pastorino
d7104dc3f5
Make feature flag incomplete 2025-03-06 18:06:48 -03:00
Santiago Pastorino
5a6d00c05d
Add allow(incomplete_features) to alloc 2025-03-06 17:58:35 -03:00
Santiago Pastorino
42b8b13b22
Add some code comments 2025-03-06 17:58:35 -03:00
Santiago Pastorino
a68db7e3a8
Add examples in stdlib demonstrating the use syntax 2025-03-06 17:58:34 -03:00
Santiago Pastorino
1702c00056
Make captures in ByUse context be always ty::UpvarCapture::ByUse 2025-03-06 17:58:34 -03:00
Santiago Pastorino
65d65e5e7e
Parse and allow const use closures 2025-03-06 17:58:34 -03:00
Santiago Pastorino
4e6407ab94
Give a better error message on async use in edition 2015 2025-03-06 17:58:34 -03:00
Santiago Pastorino
2f48fcec63
Change feature flag error to be ergonomic clones are experimental 2025-03-06 17:58:34 -03:00
Santiago Pastorino
b43b700250
Account for UseCloned on expr_use_visitor 2025-03-06 17:58:34 -03:00
Santiago Pastorino
edcbc9b535
Add a code example as comment in init_capture_kind_for_place 2025-03-06 17:58:34 -03:00
Santiago Pastorino
18d689c085
Add more tests 2025-03-06 17:58:34 -03:00
Santiago Pastorino
aa58439f87
Fail gracefully if mutating on a use closure and the closure it not declared mut 2025-03-06 17:58:33 -03:00
Santiago Pastorino
6eb6ff62f7
Allow to mutate use captures 2025-03-06 17:58:33 -03:00
Santiago Pastorino
292aa87049
Fix use closure parsing error message 2025-03-06 17:58:33 -03:00
Santiago Pastorino
7c17bf8e82
Add tests 2025-03-06 17:58:33 -03:00
Santiago Pastorino
38b4746d82
Support nested use closures 2025-03-06 17:58:33 -03:00
Santiago Pastorino
4cbca777ea
Separate closures, async and dotuse tests in directories 2025-03-06 17:58:33 -03:00
Santiago Pastorino
8c456cbf5f
Fix rustfmt 2025-03-06 17:58:33 -03:00
Santiago Pastorino
60b6470104
Fix clippy 2025-03-06 17:58:32 -03:00
Santiago Pastorino
dcdfd551f0
Add UseCloned trait related code 2025-03-06 17:58:32 -03:00
Santiago Pastorino
57cb498989
Generate the right MIR for by use closures 2025-03-06 17:58:32 -03:00
Santiago Pastorino
81a926cc2a
Use closure parse code 2025-03-06 17:58:32 -03:00
Santiago Pastorino
05c516446a
Implement .use keyword as an alias of clone 2025-03-06 17:58:32 -03:00
Santiago Pastorino
0cf8dbc96c
Add ergonomic_clones feature flag 2025-03-06 17:58:30 -03:00
Michael Goulet
e6d18561aa
Rollup merge of - cuviper:passwrapper-size_t, r=Urgau
[llvm/PassWrapper] use `size_t` when building arg strings

While we're unlikely to ever overflow `int` in this case, it's still more proper to use `size_t` consistently when dealing with buffer lengths. If nothing else, this fixes a few `-Wsign-compare` warnings.
2025-03-06 15:40:11 -05:00