Commit Graph

11897 Commits

Author SHA1 Message Date
Ralf Jung
f887f5a9c6 std: add some missing repr(transparent) 2023-08-14 10:40:59 +02:00
Guillaume Gomez
99144c3f04
Rollup merge of #114069 - cuviper:profiler-path, r=Mark-Simulacrum
Allow using external builds of the compiler-rt profile lib

This changes the bootstrap config `target.*.profiler` from a plain bool
to also allow a string, which will be used as a path to the pre-built
profiling runtime for that target. Then `profiler_builtins/build.rs`
reads that in a `LLVM_PROFILER_RT_LIB` environment variable.
2023-08-13 21:00:45 +02:00
Guillaume Gomez
7f787e397c
Rollup merge of #94667 - frank-king:feature/iter_map_windows, r=Mark-Simulacrum
Add `Iterator::map_windows`

Tracking issue:  #87155.

This is inherited from the old PR  #82413.

Unlike #82413, this PR implements the `MapWindows` to be lazy: only when pulling from the outer iterator, `.next()` of the inner iterator will be called.

## Implementaion Steps
- [x] Implement `MapWindows` to keep the iterators' [*Laziness*](https://doc.rust-lang.org/std/iter/index.html#laziness) contract.
- [x] Fix the known bug of memory access error.
- [ ] Full specialization of iterator-related traits for `MapWindows`.
    - [x] `Iterator::size_hint`,
    - [x] ~`Iterator::count`~,
    - [x] `ExactSizeIterator` (when `I: ExactSizeIterator`),
    - [x] ~`TrustedLen` (when `I: TrustedLen`)~,
    - [x] `FusedIterator`,
    - [x] ~`Iterator::advance_by`~,
    - [x] ~`Iterator::nth`~,
    - [ ] ...
- [ ] More tests and docs.

## Unresolved Questions:
- [ ] Is there any more iterator-related traits should be specialized?
- [ ] Is the double-space buffer worth?
- [ ] Should there be `rmap_windows` or something else?
- [ ] Taking GAT for consideration, should the mapper function be `FnMut(&[I::Item; N]) -> R` or something like `FnMut(ArrayView<'_, I::Item, N>) -> R`? Where `ArrayView` is mentioned in https://github.com/rust-lang/generic-associated-types-initiative/issues/2.
    - It can save memory, only the same size as the array window is needed,
    - It is more efficient, which requires less data copies,
    - It is possibly compatible with the GATified version of `LendingIterator::windows`.
    - But it prevents the array pattern matching like `iter.map_windows(|_arr: [_; N]| ())`, unless we extend the array pattern to allow matching the `ArrayView`.
2023-08-13 21:00:44 +02:00
Matthias Krüger
8a997b159c
Rollup merge of #114132 - tamird:better-env-debug-impls, r=Amanieu
Better Debug for Vars and VarsOs

Display actual vars instead of two dots.

The same was done for Args and ArgsOs in 275f9a04af.
2023-08-12 12:06:35 +02:00
Jacob Pratt
62ca5aa8e4
Remove unnecessary feature gates 2023-08-12 00:21:04 -04:00
Jacob Pratt
7f08376964
Partially stabilize #![feature(int_roundings)] 2023-08-12 00:12:11 -04:00
bors
b08dd92552 Auto merge of #114720 - scottmcm:better-sub, r=workingjubilee
Tell LLVM that the negation in `<*const T>::sub` cannot overflow

Today it's just `sub` <https://rust.godbolt.org/z/8EzEPnMr5>; with this PR it's `sub nsw`.
2023-08-11 23:40:33 +00:00
bors
08691f0c92 Auto merge of #113432 - klensy:ms-cut-backtrace, r=ChrisDenton
reduce deps for windows-msvc targets for backtrace

(eventually) mirrors https://github.com/rust-lang/backtrace-rs/pull/543

Some dependencies of backtrace don't used on windows-msvc targets, so exclude them:

    miniz_oxide (+ adler)
    addr2line (+ gimli)
    object (+ memchr)

This saves about 30kb of std.dll + 17.5mb of rlibs
2023-08-11 12:07:04 +00:00
Scott McMurray
ab6e2bc3d0 Tell LLVM that the negation in <*const T>::sub cannot overflow
Today it's just `sub` <https://rust.godbolt.org/z/8EzEPnMr5>; with this PR it's `sub nsw`.
2023-08-10 23:00:39 -07:00
Michael Goulet
9546d7140e
Rollup merge of #114402 - tifv:tifv-fix-rc-doc, r=cuviper
Fix documentation of impl From<Vec<T>> for Rc<[T]>

The example in the documentation of `impl From<Vec<T>> for <Rc<[T]>` is irrelevant (likely was copied from `impl From<Box<T>> for <Rc<T>`). I suggest taking corresponding example from the documentation of `Arc` and replacing `Arc` with `Rc`.
2023-08-10 21:17:37 -07:00
Michael Goulet
5da7f36485
Rollup merge of #114359 - ttsugriy:barrier-simpl, r=cuviper
[library/std] Replace condv while loop with `cvar.wait_while`.

`wait_while` takes care of spurious wake-ups in centralized place, reducing chances for mistakes and potential future optimizations (who knows, maybe in future there will be no spurious wake-ups? :)
2023-08-10 21:17:37 -07:00
Michael Goulet
3791f6dded
Rollup merge of #114257 - rytheo:linked-list-avoid-unique, r=cuviper
Avoid using `ptr::Unique` in `LinkedList` code

Addresses a [comment](https://github.com/rust-lang/rust/pull/103093#discussion_r1268506747) by `@RalfJung` about avoiding use of `core::ptr::Unique` in the standard library.
2023-08-10 21:17:36 -07:00
Michael Goulet
0c241e6bdb
Rollup merge of #114194 - thomcc:flushinline, r=cuviper
Inline trivial (noop) flush calls

At work I noticed that `writer.flush()?` didn't get optimized away in cases where the flush is obviously a no-op, which I had expected (well, desired).

I went through and added `#[inline]` to a bunch of cases that were obviously noops, or delegated to ones that were obviously noops. I omitted platforms I don't have access to (some tier3). I didn't do this very scientifically, in cases where it was non-obvious I left `#[inline]` off.
2023-08-10 21:17:36 -07:00
Frank King
97c953f561 Add Iterator::map_windows
This is inherited from the old PR.

This method returns an iterator over mapped windows of the starting
iterator. Adding the more straight-forward `Iterator::windows` is not
easily possible right now as the items are stored in the iterator type,
meaning the `next` call would return references to `self`. This is not
allowed by the current `Iterator` trait design. This might change once
GATs have landed.

The idea has been brought up by @m-ou-se here:
https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Iterator.3A.3A.7Bpairwise.2C.20windows.7D/near/224587771

Co-authored-by: Lukas Kalbertodt <lukas.kalbertodt@gmail.com>
2023-08-11 07:26:51 +08:00
Matthias Krüger
128cc06515
Rollup merge of #114377 - Enselic:test_get_dbpath_for_term-utf-8, r=thomcc
test_get_dbpath_for_term(): handle non-utf8 paths (fix FIXME)

Removes a FIXME for #9639

Part of #44366 which is E-help-wanted

The remaining two FIXMEs for #9639 are considerably more complicated, so I will create separate PRs for them.
2023-08-09 22:59:58 +02:00
Esteban Kuber
9de1a472b6 Suggest using Arc on !Send/!Sync types 2023-08-09 14:04:10 +00:00
bors
19a647d6d8 Auto merge of #114646 - matthiaskrgr:rollup-xf7qnmn, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #113939 (open pidfd in child process and send to the parent via SOCK_SEQPACKET+CMSG)
 - #114548 (Migrate a trait selection error to use diagnostic translation)
 - #114606 (fix: not insert missing lifetime for `ConstParamTy`)
 - #114634 (Mention riscv64-linux-android support in Android documentation)
 - #114638 (Remove old RPITIT tests (revisions were removed))
 - #114641 (Rename copying `ascii::Char` methods from `as_` to `to_`)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-08-09 05:50:12 +00:00
Matthias Krüger
83da317e07
Rollup merge of #114641 - kupiakos:ascii-char-to-not-as, r=scottmcm
Rename copying `ascii::Char` methods from `as_` to `to_`

Tracking issue: #110998.

The [API guidelines][naming] describe `as_` as used for borrowed -> borrowed operations, and `to_` for
owned -> owned operations on `Copy` types.

[naming]: https://rust-lang.github.io/api-guidelines/naming.html
2023-08-09 06:32:27 +02:00
Matthias Krüger
3feab00093
Rollup merge of #113939 - the8472:pidfd-from-child, r=Mark-Simulacrum
open pidfd in child process and send to the parent via SOCK_SEQPACKET+CMSG

This avoids using `clone3` when a pidfd is requested while still getting it in a 100% race-free manner by passing it up from the child process.
This should solve most concerns in #82971
2023-08-09 06:32:24 +02:00
bors
8838c73e86 Auto merge of #99747 - ankane:float_gamma, r=workingjubilee
Add gamma function to f32 and f64

Adds the [gamma function](https://en.wikipedia.org/wiki/Gamma_function) to `f32` and `f64` (`tgamma` and `tgammaf` from C).

Refs:
- https://github.com/rust-lang/rfcs/issues/864
- https://github.com/rust-lang/rust/issues/18271
2023-08-09 03:14:31 +00:00
Alyssa Haroldsen
a22b9bf2e6 Rename copying ascii::Char methods from as_ to to_
Tracking issue: #110998.

The [API guidelines][naming] describe `as` as used for
borrowed -> borrowed operations, and `to_` for
owned -> owned operations on `Copy` types.

[naming]: https://rust-lang.github.io/api-guidelines/naming.html
2023-08-08 16:03:47 -07:00
The 8472
8d349c1598 open pidfd in child process and send to the parent via SOCK_SEQPACKET+CMSG
This is a 100% race-free way to obtain a child's pidfd while
avoiding `clone3`.
2023-08-08 22:05:32 +02:00
Matthias Krüger
b3550891e8
Rollup merge of #106425 - ijackson:exit-status-default, r=dtolnay
Make ExitStatus implement Default

And, necessarily, make it inhabited even on platforms without processes.

I noticed while preparing https://github.com/rust-lang/rfcs/pull/3362 that there was no way for anyone to construct an `ExitStatus`.

This would be insta-stable so needs an FCP.
2023-08-08 21:44:41 +02:00
Andrew Kane
a75e2284fb Bump compiler_builtins to 0.1.100 2023-08-07 16:38:09 -07:00
Arthur Cohen
f1776250eb core: Remove #[macro_export] from debug_assert_matches
The `debug_assert_matches` macro was marked with the `#[macro_export]` attribute,
despite being a declarative macro/macro 2.0, for which the exporting rules are similar
to items. In fact, `#[macro_export]` on a decl macro has no effect on its visibility.
2023-08-07 21:13:55 +02:00
Tamir Duberstein
35c0c03a3c
Better Debug for Vars and VarsOs
Display actual vars instead of two dots.

The same was done for Args and ArgsOs in 275f9a04af.
2023-08-07 12:18:27 -04:00
Matthias Krüger
06daa9e263
Rollup merge of #114562 - Trolldemorted:thiscall, r=oli-obk
stabilize abi_thiscall

Closes https://github.com/rust-lang/rust/issues/42202, stabilizing the use of the "thiscall" ABI.

FCP was substituted by a poll, and the poll has been accepted.
2023-08-07 16:47:57 +02:00
Ian Jackson
1f1d49a2b7 impl Default for ExitStatus 2023-08-07 15:24:55 +01:00
Benedikt Radtke
3f3262e592 stabilize abi_thiscall 2023-08-07 14:11:03 +02:00
Matthias Krüger
cbe2522652
Rollup merge of #114382 - scottmcm:compare-bytes-intrinsic, r=cjgillot
Add a new `compare_bytes` intrinsic instead of calling `memcmp` directly

As discussed in #113435, this lets the backends be the place that can have the "don't call the function if n == 0" logic, if it's needed for the target.  (I didn't actually *add* those checks, though, since as I understood it we didn't actually need them on known targets?)

Doing this also let me make it `const` (unstable), which I don't think `extern "C" fn memcmp` can be.

cc `@RalfJung` `@Amanieu`
2023-08-07 05:29:12 +02:00
Matthias Krüger
f5df519fe7
Rollup merge of #114365 - tshepang:patch-6, r=Mark-Simulacrum
str.rs: remove "Basic usage" text

Only one example is given
2023-08-07 05:29:12 +02:00
Matthias Krüger
59d2a4b1e5
Rollup merge of #114362 - tshepang:patch-1, r=Mark-Simulacrum
string.rs: remove "Basic usage" text

Only a single example is given
2023-08-07 05:29:11 +02:00
Matthias Krüger
bab20b410e
Rollup merge of #98935 - kellerkindt:option_retain, r=Mark-Simulacrum
Implement `Option::take_if`

Tracking issue: #98934
ACP: rust-lang/libs-team#70 [accepted]
2023-08-07 05:29:09 +02:00
Scott McMurray
502af03445 Add a new compare_bytes intrinsic instead of calling memcmp directly 2023-08-06 15:47:40 -07:00
Matthias Krüger
3d1c36e917
Rollup merge of #114519 - the8472:dirent-offset-of, r=dtolnay
use offset_of! to calculate dirent64 field offsets

r? `@dtolnay`
2023-08-06 17:26:30 +02:00
bors
eb088b8b9d Auto merge of #111200 - a1phyr:spec_sized_iterators, r=the8472
Optimize `Iterator` implementation for `&mut impl Iterator + Sized`

This adds a specialization trait to forward `fold`, `try_fold`,... to the inner iterator where possible
2023-08-05 17:38:26 +00:00
The 8472
20c25d6c31 use offset_of! to calculate dirent64 field offsets 2023-08-05 15:53:09 +02:00
Matthias Krüger
bedadffe60
Rollup merge of #114029 - Enselic:clone-doc, r=scottmcm
Explain more clearly why `fn() -> T` can't be `#[derive(Clone)]`

Closes #73480

The derived impls were generated with `rustc -Z unpretty=expanded main.rs` and the raw output is:

```rust
struct Generate<T>(fn() -> T);
#[automatically_derived]
impl<T: ::core::marker::Copy> ::core::marker::Copy for Generate<T> { }
#[automatically_derived]
impl<T: ::core::clone::Clone> ::core::clone::Clone for Generate<T> {
    #[inline]
    fn clone(&self) -> Generate<T> {
        Generate(::core::clone::Clone::clone(&self.0))
    }
}
```
2023-08-05 14:00:16 +02:00
Matthias Krüger
539fecb882
Rollup merge of #114373 - xstaticxgpx:dev, r=the8472
unix/kernel_copy.rs: copy_file_range_candidate allows empty output files

This is for https://github.com/rust-lang/rust/issues/114341

The `meta.len() > 0` condition here is intended for inputs only, ie. when input is in the `/proc` filesystem as documented.

That inaccurately included empty output files which are then shunted to the sendfile() routine leading to higher than nescessary IO util in some cases, specifically with CoW filesystems like btrfs.

Simply, determine what is input or output given the passed boolean.
2023-08-04 07:25:46 +02:00
xstaticxgpx
2232fe8da3 unix/kernel_copy.rs: copy_file_range_candidate allows empty output files
This is for https://github.com/rust-lang/rust/issues/114341

The `meta.len() > 0` condition here is intended for inputs only,
ie. when input is in the `/proc` filesystem as documented.

That inaccurately included empty output files which are then shunted to
the sendfile() routine leading to higher than nescessary IO util in some
cases, specifically with CoW filesystems like btrfs.

Further, `NoneObtained` is not relevant in this context, so remove it.

Simply, determine what is input or output given the passed enum Unit.
2023-08-03 19:27:45 -04:00
bors
1fe384649a Auto merge of #108955 - Nilstrieb:dont-use-me-pls, r=oli-obk
Add `internal_features` lint

Implements https://github.com/rust-lang/compiler-team/issues/596

Also requires some more test blessing for codegen tests etc

`@jyn514` had the idea of just `allow`ing the lint by default in the test suite. I'm not sure whether this is a good idea, but it's definitely one worth considering. Additional input encouraged.
2023-08-03 22:58:02 +00:00
Matthias Krüger
7518ae566e
Rollup merge of #113657 - Urgau:expand-incorrect_fn_null_check-lint, r=cjgillot
Expand, rename and improve `incorrect_fn_null_checks` lint

This PR,

 - firstly, expand the lint by now linting on references
 - secondly, it renames the lint `incorrect_fn_null_checks` -> `useless_ptr_null_checks`
 - and thirdly it improves the lint by catching `ptr::from_mut`, `ptr::from_ref`, as well as `<*mut _>::cast` and `<*const _>::cast_mut`

Fixes https://github.com/rust-lang/rust/issues/113601
cc ```@est31```
2023-08-03 17:29:06 +02:00
Nilstrieb
5830ca216d Add internal_features lint
It lints against features that are inteded to be internal to the
compiler and standard library. Implements MCP #596.

We allow `internal_features` in the standard library and compiler as those
use many features and this _is_ the standard library from the "internal to the compiler and
standard library" after all.

Marking some features as internal wasn't exactly the most scientific approach, I just marked some
mostly obvious features. While there is a categorization in the macro,
it's not very well upheld (should probably be fixed in another PR).

We always pass `-Ainternal_features` in the testsuite
About 400 UI tests and several other tests use internal features.
Instead of throwing the attribute on each one, just always allow them.
There's nothing wrong with testing internal features^^
2023-08-03 14:50:50 +02:00
July Tikhonov
f1fc871ce6
Fix documentation of Rc as From<Vec<T>> 2023-08-03 10:44:23 +03:00
Michael Watzko
5419abd400 Implement Option::take_if 2023-08-03 09:34:18 +02:00
bors
d8bbef50bb Auto merge of #113220 - tgross35:cstr-bytes-docs, r=workingjubilee
Clarify documentation for `CStr`

* Better differentiate summaries for `from_bytes_until_nul` and `from_bytes_with_nul`
* Add some links where they may be helpful
2023-08-03 02:40:19 +00:00
Martin Nordholts
d1940912e5 test_get_dbpath_for_term(): handle non-utf8 paths 2023-08-02 20:57:05 +02:00
Martin Nordholts
54a6bb7f0d test_get_dbpath_for_term(): Use assert_eq!()
For better failure messages.
2023-08-02 20:57:05 +02:00
bors
d170833431 Auto merge of #112431 - Urgau:cast_ref_to_mut_improvments, r=Nilstrieb
Improve `invalid_reference_casting` lint

This PR is a follow-up to https://github.com/rust-lang/rust/pull/111567 and https://github.com/rust-lang/rust/pull/113422.

This PR does multiple things:
 - First it adds support for deferred de-reference, the goal is to support code like this, where the casting and de-reference are not done on the same expression
    ```rust
    let myself = self as *const Self as *mut Self;
    *myself = Self::Ready(value);
    ```
 - Second it does not lint anymore on SB/TB UB code by only checking assignments (`=`, `+=`, ...) and creation of mutable references `&mut *`
 - Thirdly it greatly improves the diagnostics in particular for cast from `&mut` to `&mut` or assignments
 - ~~And lastly it renames the lint from `cast_ref_to_mut` to `invalid_reference_casting` which is more consistent with the ["rules"](https://github.com/rust-lang/rust-clippy/issues/2845) and also more consistent with what the lint checks~~ *https://github.com/rust-lang/rust/pull/113422*

This PR is best reviewed commit by commit.

r? compiler
2023-08-02 11:25:13 +00:00
Tshepang Mbambo
60e43bcf57
str.rs: remove "Basic usage" text
Only one example is given
2023-08-02 12:14:43 +02:00