Commit Graph

12931 Commits

Author SHA1 Message Date
Chris Denton b9fe367b99
x fmt library/std 2023-11-22 13:17:02 +00:00
Chris Denton 6c8ebf174c
redundant_slicing 2023-11-22 13:17:02 +00:00
Chris Denton 852c038393
cmp_null
comparing with null is better expressed by the `.is_null()` method
2023-11-22 13:17:02 +00:00
Chris Denton c15adf6557
manual_range_contains 2023-11-22 13:17:01 +00:00
Chris Denton d7e1f1cc08
op_ref
taken reference of right operand
2023-11-22 13:00:30 +00:00
Chris Denton 4c084c576a
manual_map
manual implementation of `Option::map`
2023-11-22 13:00:30 +00:00
Chris Denton 8c85c5b7f4
unnecessary_lazy_evaluations
unnecessary closure used with `bool::then`
2023-11-22 13:00:29 +00:00
Chris Denton 220217af13
redundant_closure 2023-11-22 13:00:29 +00:00
Chris Denton b962ae1324
duration_subsec
calling `subsec_micros()` is more concise than this calculation
2023-11-22 13:00:29 +00:00
Chris Denton 9e42456a0d
unnecessary_cast
casting to the same type is unnecessary
2023-11-22 13:00:29 +00:00
Chris Denton 24542639aa
needless_borrow
this expression creates a reference which is immediately dereferenced by the compiler
2023-11-22 13:00:29 +00:00
Chris Denton 42734599bd
needless_borrows_for_generic_args
the borrowed expression implements the required traits
2023-11-22 13:00:28 +00:00
Chris Denton fe255695f9
manual_slice_size_calculation 2023-11-22 13:00:28 +00:00
Chris Denton bfbeb3ebd9
unnecessary_mut_passed
This is where our Windows API bindings previously (and incorrectly) used `*mut` instead of `*const` pointers. Now that the bindings have been corrected, the mutable references (which auto-convert to `*mut`) are unnecessary and we can use shared references.
2023-11-22 13:00:28 +00:00
Chris Denton 6c22e57c39
useless_conversion 2023-11-22 13:00:28 +00:00
Chris Denton 533de2bc41
needless_return
unneeded `return` statement
2023-11-22 13:00:28 +00:00
Urgau 4c2d6de70e Stabilize RFC3324 dyn upcasting coercion
Aka trait_upcasting feature.

And also adjust the `deref_into_dyn_supertrait` lint.
2023-11-22 13:56:36 +01:00
Chris Denton ad12be3668
allow clippy style in windows/c.rs
We intentional use the Windows API style here.
2023-11-22 00:14:46 +00:00
roblabla 08803eb4c8 Update backtrace submodule 2023-11-21 16:33:42 +01:00
bors e24e5af787 Auto merge of #117619 - elomatreb:add-duration-abs-diff, r=thomcc
Add `Duration::abs_diff`

This adds a `Duration::abs_diff` method analogous to the existing one on the primitive integers.

ACP: https://github.com/rust-lang/libs-team/issues/291
Tracking Issue: https://github.com/rust-lang/rust/issues/117618
2023-11-21 13:09:49 +00:00
Nilstrieb bfc2675362
Rollup merge of #118094 - JarvisCraft:SpecFromElem-for-empty-tuple, r=thomcc
feat: specialize `SpecFromElem` for `()`

# Description

This PR adds a specialization `SpecFromElem for ()` which allows to significantly reduce `vec![(), N]` time in debug builds (specifically, tests) turning it from observable $O(n)$ to $O(1)$.

# Observing the change

The problem this PR aims to fix explicitly is slow `vec![(), N]` on big `N`s which may appear in tests (see [Background section](#Background) for more details).

The minimal example to see the problem:

```rust
#![feature(test)]

extern crate test;

#[cfg(test)]
mod tests {
    const HUGE_SIZE: usize = i32::MAX as usize + 1;

    #[bench]
    fn bench_vec_literal(b: &mut test::Bencher) {
        b.iter(|| vec![(); HUGE_SIZE]);
    }

    #[bench]
    fn bench_vec_repeat(b: &mut test::Bencher) {
        b.iter(|| [(); 1].repeat(HUGE_SIZE));
    }
}
```
<details><summary>Output</summary>
<p>

```bash
cargo +nightly test -- --report-time -Zunstable-options
   Compiling huge-zst-vec-literal-bench v0.1.0 (/home/progrm_jarvis/RustroverProjects/huge-zst-vec-literal-bench)
    Finished test [unoptimized + debuginfo] target(s) in 0.31s
     Running unittests src/lib.rs (target/debug/deps/huge_zst_vec_literal_bench-e43b1ef287ba8b36)

running 2 tests
test tests::bench_vec_repeat  ... ok <0.000s>
test tests::bench_vec_literal ... ok <14.382s>

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 14.38s

   Doc-tests huge-zst-vec-literal-bench

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
```
</p>
</details>

> [!IMPORTANT]
> This problem is only observable in Debug (unoptimized) builds, while Release (optimized) ones do not observe this problem. It still is worth fixing it, IMO, since the original scenario observes the problem in tests for which optimizations are disabled by default and it seems unreasonable to override this for the whole project while the problem is very local.

# Background

While working on a crate for a custom data format which has an `i32::MAX` limit on its list's sizes, I wrote the following test to ensure that this invariant is upheld:

```rust
#[test]
fn lists_should_have_i32_size() {
    assert!(
        RawNbtList::try_from(vec![(); i32::MAX as usize]).is_ok(),
        "lists should permit the size up to {}",
        i32::MAX
    );
    assert!(
        RawNbtList::try_from(vec![(); i32::MAX as usize + 1]).is_err(),
        "lists should have the size of at most {}",
        i32::MAX
    );
}
```

Soon I discovered that this takes $\approx 3--4s$ per assertion on my machine, almost all of which is spent on `vec![..]`.
While this would be logical for a non-ZST vector (which would require actual $O(n)$ allocation), here `()` was used intentionally considering that for ZSTs size-changing operations should anyway be $O(1)$ (at least from allocator perspective). Yet, this "overhead" is logical if we consider that in general case `clone()` (which is used by `Vec` literal) may have a non-trivial implementation and thus each element has to actually be visited (even if they occupy no space).

In my specific case, the following (contextual) equivalent solved the issue:

```rust
#[test]
fn lists_should_have_i32_size() {
    assert!(
        RawNbtList::try_from([(); 1].repeat(i32::MAX as usize)).is_ok(),
        "lists should permit the size up to {}",
        i32::MAX
    );
    assert!(
        RawNbtList::try_from([(); 1].repeat(i32::MAX as usize + 1)).is_err(),
        "lists should have the size of at most {}",
        i32::MAX
    );
}
```

which works since `repeat` explicitly uses `T: Copy` and so does not have to think about non-trivial `Clone`.

But it still may be counter-intuitive for users to observe such long time on the "canonical" vec literal thus the PR.

# Generic solution

This change is explicitly non-generic. Initially I considered it possible to implement in generically, but this would require the specialization to have the following type requirements:
-  the type must be a ZST: easily done via
  ```rust
  if core::mem::size_of::<T>() == 0 {
    todo!("specialization")
  }
  ```
  or
  ```rust
  use core::mem::SizedTypeProperties;
  if T::IS_ZST {
    todo!("specialization")
  }
  ```
- :white_check_mark`: the type must implement `Copy`: implementable non-conflictable via a separate specialization:
  ```rust
  trait IsCopyZst: Sized {
    fn is_copy_zst() -> bool;
  }
  impl<T> IsCopyZst for T {
    fn is_copy_zst() -> bool {
        false
    }
  }
  impl<T: Copy> IsCopyZst for T {
    fn is_copy_zst() -> bool {
        Self::IS_ZST
    }
  }
  ```
-  the type should have a trivial `Clone` implementation: since `vec![t; n]` is specified to use `clone()`, we can only use this "performance optimization" when we are guaranteed that `clone()` does nothing except for copying.

The latter is the real blocker for a generic fix since I am unaware of any way to get this information in a compiler-guaranteed way.

While there may be a fix for this (my friend `@CertainLach` has suggested a potential solution by an perma-unstable fn in `Clone` like `is_trivially_cloneable()` defaulting to `false` and only overridable by `rustc` on derive), this is surely out of this PRs scope.
2023-11-21 09:06:29 +01:00
Nilstrieb 6bb671e7e8
Rollup merge of #117790 - rcvalle:rust-cfi-fix-000000, r=workingjubilee
CFI: Add missing use core::ffi::c_int

Adds missing use core::ffi::c_int for when sanitizer_cfi_normalize_integers is defined.
2023-11-21 09:06:27 +01:00
Petr Portnov 72a8633ee8
docs(GH-118094): make docs a bit more explicit
Signed-off-by: Petr Portnov <me@progrm-jarvis.ru>
2023-11-20 18:35:04 +03:00
Petr Portnov 91fcdde51b
chore(GH-118094): explicitly mark `_elem` as unused
Signed-off-by: Petr Portnov <me@progrm-jarvis.ru>
2023-11-20 18:33:55 +03:00
Petr Portnov 2fd9442afc
feat: specialize `SpecFromElem` for `()`
While a better approach would be to implement it for all ZSTs
which are `Copy` and have trivial `Clone`,
the last property cannot be detected for now.

Signed-off-by: Petr Portnov <me@progrm-jarvis.ru>
2023-11-20 18:29:09 +03:00
Michael Goulet 6d33e900d8
Rollup merge of #117957 - the8472:pidfd-wait, r=Mark-Simulacrum
if available use a Child's pidfd for kill/wait

This should get us closer to stabilization of pidfds since they now do something useful. And they're `CLOEXEC` now.

```
$ strace -ffe clone,sendmsg,recvmsg,execve,kill,pidfd_open,pidfd_send_signal,waitpid,waitid ./x test std --no-doc -- pidfd

[...]
running 1 tests
strace: Process 816007 attached
[pid 816007] pidfd_open(816006, 0)      = 3
[pid 816007] clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f0c6b787990) = 816008
strace: Process 816008 attached
[pid 816007] recvmsg(3,  <unfinished ...>
[pid 816008] pidfd_open(816008, 0)      = 3
[pid 816008] sendmsg(4, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="", iov_len=0}], msg_iovlen=1, msg_control=[{cmsg_len=20, cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS, cmsg_data=[3]}], msg_controllen=24, msg_flags=0}, 0) = 0
[pid 816007] <... recvmsg resumed>{msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="", iov_len=0}], msg_iovlen=1, msg_control=[{cmsg_len=20, cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS, cmsg_data=[4]}], msg_controllen=24, msg_flags=MSG_CMSG_CLOEXEC}, MSG_CMSG_CLOEXEC) = 0
[pid 816008] execve("/usr/bin/false", ["false"], 0x7ffcf2100048 /* 105 vars */) = 0
[pid 816007] waitid(P_PIDFD, 4,  <unfinished ...>
[pid 816008] +++ exited with 1 +++
[pid 816007] <... waitid resumed>{si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=816008, si_uid=1001, si_status=1, si_utime=0, si_stime=0}, WEXITED, NULL) = 0
[pid 816007] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=816008, si_uid=1001, si_status=1, si_utime=0, si_stime=0} ---
[pid 816007] clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLDstrace: Process 816009 attached
, child_tidptr=0x7f0c6b787990) = 816009
[pid 816007] recvmsg(3,  <unfinished ...>
[pid 816009] pidfd_open(816009, 0)      = 3
[pid 816009] sendmsg(5, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="", iov_len=0}], msg_iovlen=1, msg_control=[{cmsg_len=20, cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS, cmsg_data=[3]}], msg_controllen=24, msg_flags=0}, 0) = 0
[pid 816007] <... recvmsg resumed>{msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="", iov_len=0}], msg_iovlen=1, msg_control=[{cmsg_len=20, cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS, cmsg_data=[5]}], msg_controllen=24, msg_flags=MSG_CMSG_CLOEXEC}, MSG_CMSG_CLOEXEC) = 0
[pid 816009] execve("/usr/bin/sleep", ["sleep", "1000"], 0x7ffcf2100048 /* 105 vars */) = 0
[pid 816007] waitid(P_PIDFD, 5, {}, WNOHANG|WEXITED, NULL) = 0
[pid 816007] pidfd_send_signal(5, SIGKILL, NULL, 0) = 0
[pid 816007] waitid(P_PIDFD, 5,  <unfinished ...>
[pid 816009] +++ killed by SIGKILL +++
[pid 816007] <... waitid resumed>{si_signo=SIGCHLD, si_code=CLD_KILLED, si_pid=816009, si_uid=1001, si_status=SIGKILL, si_utime=0, si_stime=0}, WEXITED, NULL) = 0
[pid 816007] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_KILLED, si_pid=816009, si_uid=1001, si_status=SIGKILL, si_utime=0, si_stime=0} ---
[pid 816007] +++ exited with 0 +++
```
2023-11-19 19:14:34 -08:00
Chris Denton 3a486c1feb
Use an absolute path to the NUL device
While a bare "NUL" *should* be redirected to the NUL device, especially in this simple case, let's be explicit that we aren't opening a file called "NUL" and instead open it directly.

This will also set a good example for people copying std code.
2023-11-19 16:24:39 +00:00
The 8472 f34e7f4768 Don't set cmsg fields in msghdr if we have no cmsg to send 2023-11-19 15:19:47 +01:00
bors d052f6fde6 Auto merge of #117895 - mzohreva:mz/fix-sgx-backtrace, r=Mark-Simulacrum
Adjust frame IP in backtraces relative to image base for SGX target

This is followup to https://github.com/rust-lang/backtrace-rs/pull/566.

The backtraces printed by `panic!` or generated by `std::backtrace::Backtrace` in SGX target are not usable. The frame addresses need to be relative to image base address so they can be used for symbol resolution. Here's an example panic backtrace generated before this change:

```
$ cargo r --target x86_64-fortanix-unknown-sgx
...
stack backtrace:
   0:     0x7f8fe401d3a5 - <unknown>
   1:     0x7f8fe4034780 - <unknown>
   2:     0x7f8fe401c5a3 - <unknown>
   3:     0x7f8fe401d1f5 - <unknown>
   4:     0x7f8fe401e6f6 - <unknown>
```
Here's the same panic after this change:
```
$ cargo +stage1 r --target x86_64-fortanix-unknown-sgx
stack backtrace:
   0:            0x198bf - <unknown>
   1:            0x3d181 - <unknown>
   2:            0x26164 - <unknown>
   3:            0x19705 - <unknown>
   4:            0x1ef36 - <unknown>
```
cc `@jethrogb` and `@workingjubilee`
2023-11-19 03:00:18 +00:00
Takayuki Maeda baf3059f4e
Rollup merge of #116750 - fintelia:seek_seek_relative, r=Mark-Simulacrum
Add Seek::seek_relative

The `BufReader` struct has a `seek_relative` method because its `Seek::seek` implementation involved dumping the internal buffer (https://github.com/rust-lang/rust/issues/31100).

Unfortunately, there isn't really a good way to take advantage of that method in generic code. This PR adds the same method to the main `Seek` trait with the straightforward default method, and an override for `BufReader` that calls its implementation.

_Also discussed in [this](https://internals.rust-lang.org/t/add-seek-seek-relative/19546) internals.rust-lang.org thread._
2023-11-19 04:14:40 +09:00
bors 33688d2467 Auto merge of #117525 - GKFX:remove_option_payload_ptr, r=petrochenkov
Remove option_payload_ptr; redundant to offset_of

The `option_payload_ptr` intrinsic is no longer required as `offset_of` supports traversing enums (#114208). This PR removes it in order to dogfood offset_of (as suggested at https://github.com/rust-lang/rust/issues/106655#issuecomment-1790907626). However, it will not build until those changes reach beta (which I think is within the next 8 days?) so I've opened it as a draft.
2023-11-18 12:45:42 +00:00
George Bateman 58ea02e872
Update based on petrochenkov's review 2023-11-18 10:50:47 +00:00
bors 6416e2e675 Auto merge of #115412 - eswartz:docs/total_cmp-test-result-in-docs, r=scottmcm
Expose tests for {f32,f64}.total_cmp in docs

Expose tests for {f32,f64}.total_cmp in docs

Uncomment the helpful `assert_eq!` line, which is stripped out completely in docs, and leaves the reader to mentally play through the algorithm, or go to the playground and add a println!, to see what the result will be.

(If these tests are known to fail on some platforms, is there some mechanism to conditionalize this or escape the test so the `assert_eq!` source will be visible on the web? I am a newbie, which is why I was reading docs ;)
2023-11-18 08:49:03 +00:00
Ralf Jung b4f3f2aeac guarantee that char and u32 are ABI-compatible 2023-11-18 08:24:02 +01:00
bors 61d3b263a7 Auto merge of #115249 - clarfonthey:alignment, r=scottmcm
impl more traits for ptr::Alignment, add mask method

Changes:

* Adds `rustc_const_unstable` attributes where missing
* Makes `log2` method const
* Adds `mask` method
* Implements `Default`, which is equivalent to `Alignment::MIN`

No longer included in PR:

* Removes indirection of `AlignmentEnum` type alias (this was intentional)
* Implements `Display`, `Binary`, `Octal`, `LowerHex`, and `UpperHex` (should go through libs-api instead)
* Controversially implements `LowerExp` and `UpperExp` using `p` instead of `e` to indicate a power of 2 (also should go through libs-api)

Tracking issue for `ptr::Alignment`: #102070
2023-11-18 06:51:15 +00:00
ltdk 114873dc19 impl more traits for ptr::Alignment, add mask method 2023-11-18 00:05:28 -05:00
bors e6dade96f4 Auto merge of #117825 - fee1-dead-contrib:corefx, r=petrochenkov
Reenable effects in libcore

With #116670, #117531, and #117171, I think we would be comfortable with re-enabling the effects feature for more testing in libcore.

r? `@oli-obk`
cc `@fmease`
cc #110395
2023-11-18 04:56:31 +00:00
bors 1a740c3816 Auto merge of #117138 - zachs18:rwlock_guard_debug_unsized, r=dtolnay
Add T: ?Sized to `RwLockReadGuard` and `RwLockWriteGuard`'s Debug impls.

For context, `MutexGuard` has `+ ?Sized` on its `Debug` impl, and all three have `+ ?Sized` on their `Display` impls.

It looks like the `?Sized` was just missed when the impls were added (the impl for `MutexGuard` was added in the same PR (https://github.com/rust-lang/rust/pull/38006) with support for `T: Debug + ?Sized`, and `RwLock*Guard`s did allow `T: ?Sized` types already); the `Display` impls were added later (https://github.com/rust-lang/rust/pull/42822) with support for `T: Debug + ?Sized` types.

I think this needs a T-libs-api FCP? I'm not sure if this also needs an ACP. If so I can make one.

These are changes to (stable) trait impls on stable types so will be insta-stable.

`@rustbot` label +T-libs-api
2023-11-18 00:59:19 +00:00
Jules Bertholet db62921159
Document behavior of `<dyn Any as Any>::type_id()`
See also #57893
2023-11-17 19:54:37 -05:00
Matthias Krüger e06a6d3ebe
Rollup merge of #118006 - lcnr:discriminant-docs, r=compiler-errors
clarify `fn discriminant` guarantees: only free lifetimes may get erased

cc https://github.com/rust-lang/rust/pull/104299/files#r1397082347

don't think this necessitates a backport by itself, but should imo be included if one were to exist.

r? types
2023-11-17 23:04:24 +01:00
Matthias Krüger aa2289d3bc
Rollup merge of #117549 - DaniPopes:more-copied, r=b-naber
Use `copied` instead of manual `map`
2023-11-17 23:04:22 +01:00
Matthias Krüger ca3a02836e
Rollup merge of #117338 - workingjubilee:asmjs-meets-thanatos, r=b-naber
Remove asmjs

Fulfills [MCP 668](https://github.com/rust-lang/compiler-team/issues/668).

`asmjs-unknown-emscripten` does not work as-specified, and lacks essential upstream support for generating asm.js, so it should not exist at all.
2023-11-17 23:04:21 +01:00
Mohsen Zohrevandi b576dd2b3c Use ptr::invalid_mut for SGX image base 2023-11-17 11:49:23 -08:00
bors f6dcaee23f Auto merge of #111922 - vaporoxx:feat-searcher, r=dtolnay
feat: implement `DoubleEndedSearcher` for `CharArray[Ref]Searcher`

This PR implements `DoubleEndedSearcher` for both `CharArraySearcher` and `CharArrayRefSearcher`. I'm not sure whether this was just overlooked or if there is a reason for it, but since it behaves exactly like `CharSliceSearcher`, I think the implementations should be appropriate.
2023-11-17 18:47:34 +00:00
Chris Denton 00a12af3ca
Update windows-bindgen 2023-11-17 12:18:04 +00:00
Chris Denton df58704701
Define `INVALID_HANDLE_VALUE` ourselves 2023-11-17 12:03:41 +00:00
lcnr 3b0e1d23b7 only free lifetimes may get erased 2023-11-17 11:03:52 +00:00
Matthias Krüger 1cabedc256
Rollup merge of #115476 - RalfJung:abi-compat-docs, r=Mark-Simulacrum
document ABI compatibility

I don't think we have any central place where we document our ABI compatibility rules, so let's create one. The `fn()` pointer type seems like a good place since ABI questions can only become relevant when invoking a function through a function pointer.

This will likely need T-lang FCP.
2023-11-17 08:10:26 +01:00
Ralf Jung 8f03a55566 linking in general has more pitfalls than just call ABI 2023-11-17 08:02:28 +01:00
Takayuki Maeda c77cb7a3f6
Rollup merge of #117946 - RalfJung:miri-libcore-test, r=Mark-Simulacrum
avoid exhaustive i16 test in Miri

https://github.com/rust-lang/rust/pull/116301 added a test that is way too slow to be running in Miri. So let's only test a few hopefully representative cases.
2023-11-17 12:56:31 +09:00
George Bateman 661df4fd55
Remove option_payload_ptr; redundant to offset_of 2023-11-16 22:56:25 +00:00
Urgau 8d91d6662f Stabilize ptr_addr_eq library feature 2023-11-16 11:35:59 +01:00
Sean Cross 1828cf8c1c std: personality: support gcc personality on Xous
Xous as an operating system is compiled with gcc-type personalities when
it comes to unwinding. This enables unwinding inside panics on Xous,
which enables Rust tests.

Signed-off-by: Sean Cross <sean@xobs.io>
2023-11-16 15:23:09 +08:00
Sean Cross 28203172de panic_unwind: support unwinding on xous
Now that `unwind` supports Xous, enable unwinding panics on Xous.

Signed-off-by: Sean Cross <sean@xobs.io>
2023-11-16 15:23:09 +08:00
Sean Cross ee870d6c82 unwind: add support for using `unwinding` crate
The `unwinding` crate supports processing unwinding data, and is written
entirely in Rust. This allows it to be ported to new platforms more
easily than using the llvm-based `libunwind`.

While `libunwind` is very well supported on major targets, it is
difficult to use on other targets. SGX is an example of this where Rust
carries custom patches in order to enable backtrace support.

This adds an alternative for supported architectures. Rather than
providing a custom target, `unwinding` allows for a solution that is
completely written in Rust.

This adds `xous` as the first consumer, and forthcoming patches will
modify libstd to take advantage of this.

Signed-off-by: Sean Cross <sean@xobs.io>
2023-11-16 15:23:09 +08:00
Mark Rousskov 917f6540ed Re-format code with new rustfmt 2023-11-15 21:45:48 -05:00
The 8472 12efa53b19 if available use a Child's pidfd for kill/wait 2023-11-16 02:05:37 +01:00
Mark Rousskov db3e2bacb6 Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
Mark Rousskov efe54e24aa Substitute version placeholders 2023-11-15 19:40:51 -05:00
The 8472 3ffbb4899e update comment, we're currently using a different syscall 2023-11-16 01:38:59 +01:00
The 8472 10127d9eb5 set CLOEXEC on pidfd received from child process 2023-11-16 01:36:54 +01:00
Ralf Jung 1c1b7897d8 avoid exhaustive i16 test in Miri 2023-11-15 19:23:04 +01:00
zhiqiangxu a355df4432
remove unnecessary drop 2023-11-16 00:01:57 +08:00
Mohsen Zohrevandi ec8c3d9992 Move SGX-specific image base logic to sys_common 2023-11-14 13:27:57 -08:00
Mohsen Zohrevandi 6e7ea03c26 Adjust frame IP in backtraces relative to image base for SGX target 2023-11-14 10:27:12 -08:00
bors 5526682702 Auto merge of #117330 - tmiasko:custom-mir-cleanup-blocks, r=cjgillot
Custom MIR: Support cleanup blocks

Cleanup blocks are declared with `bb (cleanup) = { ... }`.

`Call` and `Drop` terminators take an additional argument describing the unwind action, which is one of the following:

* `UnwindContinue()`
* `UnwindUnreachable()`
* `UnwindTerminate(reason)`, where reason is `ReasonAbi` or `ReasonInCleanup`
* `UnwindCleanup(block)`

Also support unwind resume and unwind terminate terminators:

* `UnwindResume()`
* `UnwindTerminate(reason)`
2023-11-14 08:53:25 +00:00
Tomasz Miąsko 78da577650 Custom MIR: Support cleanup blocks
Cleanup blocks are declared with `bb (cleanup) = { ... }`.

`Call` and `Drop` terminators take an additional argument describing the
unwind action, which is one of the following:

* `UnwindContinue()`
* `UnwindUnreachable()`
* `UnwindTerminate(reason)`, where reason is `ReasonAbi` or `ReasonInCleanup`
* `UnwindCleanup(block)`

Also support unwind resume and unwind terminate terminators:

* `UnwindResume()`
* `UnwindTerminate(reason)`
2023-11-14 08:23:58 +01:00
bors b9175240ea Auto merge of #116301 - mj10021:issue-115737-fix, r=cuviper
fix rounding issue with exponents in fmt

fixes issue #115737 , where the decimal places are rounded incorrectly when formatting scientific notation
2023-11-14 00:04:05 +00:00
bors 85b8450466 Auto merge of #116866 - slanterns:inspect-stabilize, r=BurntSushi
Stabilize `result_option_inspect`

This PR stabilizes `result_option_inspect`:

```rust
// core::option

impl Option<T> {
    pub fn inspect<F: FnOnce(&T)>(self, f: F) -> Self;
}

// core::result

impl Result<T, E> {
    pub fn inspect<F: FnOnce(&T)>(self, f: F) -> Self;
    pub fn inspect_err<F: FnOnce(&E)>(self, f: F) -> Self;
}
```

<br>

Tracking issue: https://github.com/rust-lang/rust/issues/91345.
Implementation PR: https://github.com/rust-lang/rust/pull/91346.

Closes https://github.com/rust-lang/rust/issues/91345.
2023-11-13 19:46:18 +00:00
Deadbeef da28b30896 Reenable effects in libcore 2023-11-12 04:33:19 +00:00
James Dietz 3f0908f47c round to even 2023-11-11 17:22:07 -05:00
James Dietz e81964e6f9 fix rounding issue with exponents in fmt 2023-11-11 16:40:22 -05:00
bors 2c1b65ee14 Auto merge of #115694 - clarfonthey:std-hash-private, r=dtolnay
Add `std:#️⃣:{DefaultHasher, RandomState}` exports (needs FCP)

This implements rust-lang/libs-team#267 to move the libstd hasher types to `std::hash` where they belong, instead of `std::collections::hash_map`.

<details><summary>The below no longer applies, but is kept for clarity.</summary>
This is a small refactor for #27242, which moves the definitions of `RandomState` and `DefaultHasher` into `std::hash`, but in a way that won't be noticed in the public API.

I've opened rust-lang/libs-team#267 as a formal ACP to move these directly into the root of `std::hash`, but for now, they're at least separated out from the collections code in a way that will make moving that around easier.

I decided to simply copy the rustdoc for `std::hash` from `core::hash` since I think it would be ideal for the two to diverge longer-term, especially if the ACP is accepted. However, I would be willing to factor them out into a common markdown document if that's preferred.
</details>
2023-11-11 21:12:20 +00:00
Ralf Jung 52d22eaa23 clarify ABI compatibility of fn ptr types and ptr types
and add an and
2023-11-11 13:36:02 +01:00
Duo Wang ed87ecc4d0
Update variable name to fix `unused_variables` warning 2023-11-10 12:51:41 -08:00
Ralf Jung 044d05769b add 'import functions' to the list of situations where ABI compatibility comes up 2023-11-10 20:33:19 +01:00
Ramon de C Valle 55e3dc487f CFI: Add missing use core::ffi::c_int
Adds missing use core::ffi::c_int for when
sanitizer_cfi_normalize_integers is defined.
2023-11-10 08:20:04 -08:00
bors 17d0a45f5d Auto merge of #117572 - RalfJung:addr_of, r=cuviper
update and clarify addr_of docs

This updates the docs to match https://github.com/rust-lang/reference/pull/1387. Cc `@rust-lang/opsem`

`@chorman0773` not sure if you had anything else you wanted to say here, I'd be happy to get your feedback. :)

Fixes https://github.com/rust-lang/rust/issues/114902, so Cc `@joshlf`
2023-11-10 08:04:47 +00:00
Ralf Jung e30f8ae867
mention null explicitly
Co-authored-by: Josh Stone <cuviper@gmail.com>
2023-11-10 07:34:28 +01:00
Matthias Krüger 0f1da7e682
Rollup merge of #117730 - jmillikin:fmt-debug-helper-fns, r=cuviper
Closure-consuming helper functions for `fmt::Debug` helpers

ACP: https://github.com/rust-lang/libs-team/issues/288

Tracking issue: https://github.com/rust-lang/rust/issues/117729
2023-11-10 01:50:24 +01:00
Matthias Krüger 7096ec3e00
Rollup merge of #117039 - scottmcm:clarify-get-unchecked, r=cuviper
Clarify UB in `get_unchecked(_mut)`

Inspired by #116915, it was unclear to me what exactly "out-of-bounds index" means in `get_unchecked`.

One could [potentially](https://rust.godbolt.org/z/hxM764orW) interpret it that `get_unchecked` is just another way to write `offset`, but I think `get_unchecked(len)` is supposed to be UB even though `.offet(len)` is well-defined (as is `.get_unchecked(..len)`), so write that more directly in the docs.

**libs-api folks**: Can you confirm whether this is what you expect this to mean?  And is the situation any different for `<*const [T]>::get_unchecked`?
2023-11-10 01:50:24 +01:00
John Millikin 82a9f94de5 Closure-consuming helper functions for `fmt::Debug` helpers 2023-11-10 07:50:11 +09:00
Takayuki Maeda b4fa5b7004
Rollup merge of #117694 - jmillikin:core-io-borrowed-buf, r=m-ou-se
Move `BorrowedBuf` and `BorrowedCursor` from `std:io` to `core::io`

Tracking issue: https://github.com/rust-lang/rust/issues/117693

ACP: https://github.com/rust-lang/libs-team/issues/290
2023-11-09 11:36:52 +09:00
Takayuki Maeda a1a8d6fe9c
Rollup merge of #116762 - WaffleLapkin:fixup_fromptr_docs, r=RalfJung
Fixup `Atomic*::from_ptr` safety docs

See https://github.com/rust-lang/rust/pull/115719#issuecomment-1762725010
cc ``@RalfJung``
2023-11-09 11:36:51 +09:00
John Millikin 341c85648c Move `BorrowedBuf` and `BorrowedCursor` from `std:io` to `core::io`
Assigned new feature name `core_io_borrowed_buf` to distinguish from the
`Read::read_buf` functionality in `std::io`.
2023-11-09 07:10:11 +09:00
bors fdaaaf9f92 Auto merge of #116930 - RalfJung:raw-ptr-match, r=davidtwco
patterns: reject raw pointers that are not just integers

Matching against `0 as *const i32` is fine, matching against `&42 as *const i32` is not.

This extends the existing check against function pointers and wide pointers: we now uniformly reject all these pointer types during valtree construction, and then later lint because of that. See [here](https://github.com/rust-lang/rust/pull/116930#issuecomment-1784654073) for some more explanation and context.

Also fixes https://github.com/rust-lang/rust/issues/116929.

Cc `@oli-obk` `@lcnr`
2023-11-08 20:42:32 +00:00
okaneco d585eecb05 Refactor `binary_search_by` to use conditional moves
Refactor the if/else checking on cmp::Ordering variants to a
"branchless" reassignment of left and right. This change results
in fewer branches and instructions.
2023-11-08 14:53:49 -05:00
bors 28acba3c61 Auto merge of #115460 - zachs18:borrowedcursor_write_no_panic, r=dtolnay
Don't panic in `<BorrowedCursor as io::Write>::write`

Instead of panicking if the BorrowedCursor does not have enough capacity for the whole buffer, just return a short write, [like `<&mut [u8] as io::Write>::write` does](https://doc.rust-lang.org/src/std/io/impls.rs.html#349).

(cc `@ChayimFriedman2` https://github.com/rust-lang/rust/issues/78485#issuecomment-1493129588)

(I'm not sure if this needs an ACP? since it's not changing the "API", just what the function does)
2023-11-08 14:08:48 +00:00
scottmcm 545175ce87
Fix addition formatting 2023-11-07 18:39:09 -08:00
Tomoaki Kawada 52eb92de37 kmc-solid: Re-export `{As,Borrowed,Owned}Fd` in `std::os::solid::prelude` 2023-11-08 10:52:00 +09:00
Tomoaki Kawada c8c3339133 kmc-solid: Reimplement `AsFd` etc for `{TcpStream,TcpListener,UdpSocket}` by delegating to inner `Socket`
Removes some `unsafe` blocks.
2023-11-08 10:51:59 +09:00
Tomoaki Kawada 46bc247bd1 kmc-solid: Implement `{From,Into}Inner<OwnedFd>` for `Socket` 2023-11-08 10:51:59 +09:00
Tomoaki Kawada 6d1e4ddf03 kmc-solid: Remove `FileDesc`
Removes the private type `std::sys::solid::net::FileDesc`, replacing its
only usage in `std::sys::solid::net::Socket` with `std::os::solid::io::
OwnedFd`.
2023-11-08 10:51:57 +09:00
Tomoaki Kawada cbfab81f3d kmc-solid: Replace `{From,Into}Inner<c_int>` impls with `*RawFd` for `Socket`
Follows how other targets are implemented.
2023-11-08 10:48:49 +09:00
Tomoaki Kawada 0dd3b25e2d kmc-solid: Implement `AsFd` for `{Arc,Rc,Box}<impl AsFd>` 2023-11-08 10:48:49 +09:00
Tomoaki Kawada cf9c4a32f3 kmc-solid: Implement `AsFd` and conversion to/from `OwnedFd` for `{TcpStream,TcpListener,UdpSocket}` 2023-11-08 10:48:49 +09:00
Tomoaki Kawada ddfe168e6c kmc-solid: Document I/O safety in `std::os::solid::io`
Mostly copied from `std::os::unix::io`, except quantifying file
descriptors with SOLID Sockets and removing the paragraph mentioning
`mmap`.
2023-11-08 10:48:49 +09:00
Tomoaki Kawada 5d3aefe58d kmc-solid: Add `std::os::solid::io::{BorrowedFd,OwnedFd,AsFd}`
It's mostly based on `std::os::fd::owned`.
2023-11-08 10:48:49 +09:00
Maybe Waffle 102384523a Document how rust atomics work wrt mixed-sized and non-atomic accesses 2023-11-07 21:38:13 +00:00
bors 118a2deea5 Auto merge of #117617 - Urgau:bump-libc-0.2.150, r=Mark-Simulacrum
Bump libc dependency

This bumps the `libc` crate to version 0.2.150 which includes https://github.com/rust-lang/libc/pull/3410 which will help remove the old and deprecated check-cfg syntax.

Extracted from https://github.com/rust-lang/rust/pull/117612
2023-11-07 17:18:36 +00:00
Matthias Krüger 2a1f8bccee
Rollup merge of #117631 - smarnach:error-request-doc-fix, r=ChrisDenton
Documentation cleanup for core::error::Request.

This part of the documentation currently render like this:

![image](https://github.com/rust-lang/rust/assets/249196/b34cb907-4ce4-4e85-beca-510d8aa1fefb)

The new version renders like this:

![image](https://github.com/rust-lang/rust/assets/249196/fe18398a-15fb-42a7-82a4-f1856d48bd79)

Fixes:
* Add missing closing back tick.
* Remove spurious double back ticks.
* Add missing newline to render bullet point correctly.
* Fix grammar "there are methods calledrequest_ref and request_value are available" -> "there are methods calledrequest_ref and request_value".
* Change "methods" to "functions", which seems more appropriate for free functions.
2023-11-06 20:31:55 +01:00
bors b049093560 Auto merge of #116988 - RalfJung:null, r=WaffleLapkin
document that the null pointer has the 0 address

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

Will need t-lang FCP, but I think this is fairly uncontroversial -- there's probably already tons of code out there that relies on this.
2023-11-06 14:13:00 +00:00
Sven Marnach 3a096e96fa
Documentation cleanup for core::error::Request. 2023-11-06 11:38:27 +01:00
bors 7a892ab8d8 Auto merge of #117576 - the8472:fix-io-copy-vec, r=Mark-Simulacrum
Fix excessive initialization and reads beyond EOF in `io::copy(_, Vec<u8>)` specialization

fixes #117545 and https://github.com/bczhc/bzip3-rs/pull/8
2023-11-06 00:05:58 +00:00
bors fee5518cdd Auto merge of #96979 - SabrinaJewson:waker-update, r=workingjubilee
Override `Waker::clone_from` to avoid cloning `Waker`s unnecessarily

This would be very useful for futures — I think it’s pretty much always what they want to do instead of `*waker = cx.waker().clone()`.

Tracking issue: https://github.com/rust-lang/rust/issues/98287

r? rust-lang/libs-api `@rustbot` label +T-libs-api -T-libs
2023-11-05 21:44:24 +00:00
Ole Bertram 0ac438c8d4
Add `Duration::abs_diff` 2023-11-05 19:45:17 +01:00
bors 5103173af1 Auto merge of #117179 - Voultapher:fix-useless-comp-in-partition-equal, r=Mark-Simulacrum
Avoid unnecessary comparison in partition_equal

The branchy Hoare partition `partition_equal` as part of `slice::sort_unstable` has a bug that makes it perform a comparison of the last element twice.

Measuring inputs with a Zipfian distribution with characterizing exponent s == 1.0, yields a ~0.05% reduction in the total number of comparisons performed.
2023-11-05 17:41:36 +00:00
Urgau 15719a8c1d libc: bump dependency to 0.2.150 2023-11-05 18:32:10 +01:00
bors 992943dbae Auto merge of #117537 - GKFX:offset-of-enum-feature, r=cjgillot
Feature gate enums in offset_of

As requested at https://github.com/rust-lang/rust/issues/106655#issuecomment-1790815262, put enums in offset_of behind their own feature gate.

`@rustbot` label F-offset_of
2023-11-05 13:44:59 +00:00
bors 04817ff00c Auto merge of #117608 - matthiaskrgr:rollup-g9fagmv, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #116017 (Don't pass `-stdlib=libc++` when building C files on macOS)
 - #117524 (bootstrap/setup: create hooks directory if non-existing)
 - #117588 (Remove unused LoadResult::DecodeIncrCache variant)
 - #117596 (Add diagnostic items for a few of core's builtin macros)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-11-05 11:47:38 +00:00
Matthias Krüger a660516334
Rollup merge of #117596 - thomcc:core_macro_diag_items, r=Nilstrieb
Add diagnostic items for a few of core's builtin macros

Specifically, `env`, `option_env`, and `include`. There are a number of reasons why people might want to look at these in lints (For example, to ensure that things behave consistently, detect things that might make builds less reproducible, etc).

Concretely, in PL/Rust (well, `plrustc`) we have lints that forbid these (which I'd like to [add to clippy as restriction lints](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Landing.20a.20flotilla.20of.20lints.3F) eventually), and `dylint` also has [lints that look for `env!`/`option_env!`](109a07e9f2/examples/general/env_cargo_path/src/lib.rs) (although perhaps not `include`), which would benefit from this.

My experience is that it's pretty annoying to (robustly) check uses of builtin macros without these IME, although that's perhaps just my own fault (e.g. I could be doing it wrong).

At `@Nilstrieb's` suggestion, I've added a comment that explains why these are here, even though they are not used in the compiler. This is mostly to discourage removal, although it's not a big deal if it happens (I'm certainly not suggesting the presence of these be in any way stable).

---

In theory this is a library PR (in that it's in library/core), but I'm going to roll compiler because the existence of this or not is much more likely something they care about rather than libs. Hopefully nobody objects to this.

r? compiler
2023-11-05 12:41:48 +01:00
Ralf Jung 81af5b5031 update and clarify addr_of docs 2023-11-05 11:41:10 +01:00
bors 513a48517e Auto merge of #117504 - pcc:android-link-libunwind, r=Mark-Simulacrum
Remove obsolete support for linking unwinder on Android

Linking libgcc is no longer supported (see #103673), so remove the related link attributes and the check in unwind's build.rs. The check was the last remaining significant piece of logic in build.rs, so remove build.rs as well.
2023-11-05 09:50:21 +00:00
bors da1e0d1d75 Auto merge of #116218 - tgross35:const-maybe-uninit-zeroed, r=dtolnay
Stabilize `const_maybe_uninit_zeroed` and `const_mem_zeroed`

Make `MaybeUninit::zeroed` and `mem::zeroed` const stable. Newly stable API:

```rust
// core::mem
pub const unsafe fn zeroed<T>() ->;

impl<T> MaybeUninit<T> {
    pub const fn zeroed() -> MaybeUninit<T>;
}
```

This relies on features based around `const_mut_refs`. Per `@RalfJung,` this should be OK since we do not leak any `&mut` to the user.

For this to be possible, intrinsics `assert_zero_valid` and `assert_mem_uninitialized_valid` were made const stable.

Tracking issue: #91850
Zulip discussion: https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/topic/.60const_mut_refs.60.20dependents

r? libs-api
`@rustbot` label -T-libs +T-libs-api +A-const-eval
cc `@RalfJung`  `@oli-obk` `@rust-lang/wg-const-eval`
2023-11-05 05:56:21 +00:00
bors c3ae4707d5 Auto merge of #117581 - nicholasbishop:bishop-update-cb, r=Mark-Simulacrum
Bump compiler_builtins to 0.1.103
2023-11-05 01:59:32 +00:00
bors f5ca57e153 Auto merge of #117503 - kornelski:hint-try-reserved, r=workingjubilee
Hint optimizer about try-reserved capacity

This is #116568, but limited only to the less-common `try_reserve` functions to reduce bloat in debug binaries from debug info, while still addressing the main use-case #116570
2023-11-05 00:03:41 +00:00
Thom Chiovoloni 65bec86b42
Add diagnostic items for a few of core's builtin macros 2023-11-04 17:00:51 -07:00
Jonathan Behrens d9f7c9db02 Improve documentation 2023-11-04 15:45:55 -07:00
Matthias Krüger 1ee5e12710
Rollup merge of #117534 - RalfJung:str, r=Mark-Simulacrum
clarify that the str invariant is a safety, not validity, invariant

Updates these docs to match https://github.com/rust-lang/reference/pull/792
2023-11-04 21:38:29 +01:00
Matthias Krüger 805a56fc28
Rollup merge of #116894 - joshlf:patch-12, r=RalfJung
Guarantee that `char` has the same size and alignment as `u32`
2023-11-04 21:38:28 +01:00
Matthias Krüger 58645e06d9
Rollup merge of #110340 - jmaargh:jmaargh/deref-docs, r=Mark-Simulacrum
Deref docs: expand and remove "smart pointer" qualifier

**Ready for review**

~~This is an unpolished draft to be sanity-checked~~

Fixes #91004

~~Comments on substance and content of this are welcome. This is deliberately unpolished until ready to review so please try to stay focused on the big-picture.~~

~~Once this has been sanity checked, I will similarly update `DerefMut` and polish for review.~~
2023-11-04 21:38:28 +01:00
Trevor Gross 5e5f3341e3 Stabilize `const_mem_zeroed`
Make `core::mem::zeroed` const stable. Newly stable API:

    // core::mem
    pub const unsafe fn zeroed<T>() -> T;

This is stabilized with `const_maybe_uninit_zeroed` since it is a simple
wrapper.

In order to make this possible, intrinsics `assert_zero_valid` was made
const stable under `const_assert_type2`.
`assert_mem_uninitialized_valid` was also made const stable since it is
under the same gate.
2023-11-04 15:27:29 -04:00
Trevor Gross f6ce646d3f Stabilize `const_maybe_uninit_zeroed`
Make `MaybeUninit::zeroed` const stable. Newly stable API:

    // core::mem
    impl<T> MaybeUninit<T> {
        pub const fn zeroed() -> MaybeUninit<T>;
    }

Use of `const_mut_refs` should be acceptable since we do not leak the
mutability.

Tracking issue: #91850
2023-11-04 15:27:25 -04:00
jmaargh 7a2f83fa3f Draft fleshed-out deref docs
Re-draft Deref docs

Make general advice more explicit and note the difference between
generic and specific implementations.

Re-draft DerefMut docs in-line with Deref

Fix Deref docs typos

Fix broken links

Clarify advice for specific-over-generic impls

Add comment addressing Issue #73682

x fmt

Copy faillibility warning to DerefMut
2023-11-04 17:47:25 +00:00
Nicholas Bishop 5d3535c616 Bump compiler_builtins to 0.1.103 2023-11-04 13:11:10 -04:00
The 8472 78aa5e511c detect EOF earlier
The initial probe-for-empty-source by stack_buffer_copy only detected EOF
if the source was empty but not when it was merely small which lead to
additional calls to read() after Ok(0) had already been returned
in the stack copy routine
2023-11-04 16:11:01 +01:00
The 8472 8d8f06b277 avoid excessive initialization when copying to a Vec
It now keeps track of initialized bytes to avoid reinitialization.
It also keeps track of read sizes to avoid initializing more bytes
than the reader needs. This is important when passing a huge vector to a
Read that only has a few bytes to offer and doesn't implement read_buf().
2023-11-04 16:11:01 +01:00
Ralf Jung 0550ba5f77 avoid acronyms when we don't really need them 2023-11-04 12:24:09 +01:00
Ralf Jung 281d8cc4ae document ABI compatibility 2023-11-04 11:22:17 +01:00
alpharush c7d8c65c1a docs: clarify explicitly freeing heap allocated memory 2023-11-04 03:00:43 -05:00
bors 5020f7c3b8 Auto merge of #116412 - nnethercote:rm-plugin-support, r=bjorn3
Remove support for compiler plugins.

They've been deprecated for four years.

This commit includes the following changes.
- It eliminates the `rustc_plugin_impl` crate.
- It changes the language used for lints in `compiler/rustc_driver_impl/src/lib.rs` and `compiler/rustc_lint/src/context.rs`. External lints are now called "loaded" lints, rather than "plugins" to avoid confusion with the old plugins. This only has a tiny effect on the output of `-W help`.
- E0457 and E0498 are no longer used.
- E0463 is narrowed, now only relating to unfound crates, not plugins.
- The `plugin` feature was moved from "active" to "removed".
- It removes the entire plugins chapter from the unstable book.
- It removes quite a few tests, mostly all of those in `tests/ui-fulldeps/plugin/`.

Closes #29597.

r? `@ghost`
2023-11-03 22:32:56 +00:00
Nicholas Nethercote 5c462a32bd Remove support for compiler plugins.
They've been deprecated for four years.

This commit includes the following changes.
- It eliminates the `rustc_plugin_impl` crate.
- It changes the language used for lints in
  `compiler/rustc_driver_impl/src/lib.rs` and
  `compiler/rustc_lint/src/context.rs`. External lints are now called
  "loaded" lints, rather than "plugins" to avoid confusion with the old
  plugins. This only has a tiny effect on the output of `-W help`.
- E0457 and E0498 are no longer used.
- E0463 is narrowed, now only relating to unfound crates, not plugins.
- The `plugin` feature was moved from "active" to "removed".
- It removes the entire plugins chapter from the unstable book.
- It removes quite a few tests, mostly all of those in
  `tests/ui-fulldeps/plugin/`.

Closes #29597.
2023-11-04 08:50:46 +11:00
bors 1bb6553b96 Auto merge of #115333 - joshlf:patch-5, r=RalfJung
Guarantee representation of None in NPO

This allows users to soundly transmute zeroes into `Option` types subject to the null pointer optimization (NPO). It unblocks https://github.com/google/zerocopy/issues/293.
2023-11-03 20:29:13 +00:00
DaniPopes e6779d98ee
library: use `copied` instead of manual `map` 2023-11-03 17:18:45 +01:00
George Bateman a723b01ae2
cfg_attr offset_of_enum feature in doctest 2023-11-03 14:58:02 +00:00
George Bateman 7c09b99ebb
Feature gate enums in offset_of 2023-11-03 13:16:47 +00:00
Matthias Krüger 958a6af147
Rollup merge of #117434 - BugenZhao:box-error-provide, r=cuviper
delegate `<Box<E> as Error>::provide` to `<E as Error>::provide`

Fix #117432.
2023-11-03 12:44:49 +01:00
bors 49112241e9 Auto merge of #117510 - elichai:patch-3, r=cuviper
Add track_caller to transmute_copy

Currently if `size_of::<Src>() < size_of::<Dst>()` you will see the following error:
```rust
thread 'test' panicked at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/mem/mod.rs:1056:5:
cannot transmute_copy if Dst is larger than Src
```
This fixes it so it will show the invocation location
2023-11-03 08:41:59 +00:00
Ralf Jung 57f570bb33 clarify that the str invariant is a safety, not validity, invariant 2023-11-03 07:23:24 +01:00
Peter Collingbourne 654288bbb7 Remove obsolete support for linking unwinder on Android
Linking libgcc is no longer supported (see #103673), so remove the
related link attributes and the check in unwind's build.rs. The check
was the last remaining significant piece of logic in build.rs, so
remove build.rs as well.
2023-11-02 18:06:35 -07:00
ltdk 8337e86b28 Add insta-stable std:#️⃣:{DefaultHasher, RandomState} exports 2023-11-02 20:35:20 -04:00
ltdk 075409ddd9 Move RandomState and DefaultHasher into std::hash, but don't export for now 2023-11-02 20:35:20 -04:00
Michael Goulet c83f642f12 Pretty print Fn traits in rustc_on_unimplemented 2023-11-02 20:57:05 +00:00
Matthias Krüger 6268598dfb
Rollup merge of #117512 - joshlf:patch-8, r=dtolnay
Expand mem::offset_of! docs

Makes progress on #106655
2023-11-02 15:31:22 +01:00
Matthias Krüger 9575625835
Rollup merge of #117495 - compiler-errors:unsize-docs, r=lcnr
Clarify `Unsize` documentation

The documentation erroneously says that:

```rust
/// - Types implementing a trait `Trait` also implement `Unsize<dyn Trait>`.
/// - Structs `Foo<..., T, ...>` implement `Unsize<Foo<..., U, ...>>` if all of these conditions
///   are met:
///   - `T: Unsize<U>`.
///   - Only the last field of `Foo` has a type involving `T`.
///   - `Bar<T>: Unsize<Bar<U>>`, where `Bar<T>` stands for the actual type of that last field.
```

Specifically, `T: Unsize<U>` is not required to hold -- only the final field must implement `FinalField<T>: Unsize<FinalField<U>>`. This can be demonstrated by the test I added.

---

Second commit fleshes out the documentation a lot more.
2023-11-02 15:31:21 +01:00
Joshua Liebow-Feeser 2cc92e666f
Update mod.rs 2023-11-02 06:45:32 -07:00
Joshua Liebow-Feeser 9cf1a48599
Update mod.rs 2023-11-02 05:57:31 -07:00
Joshua Liebow-Feeser ec7996df7c
Remove trailing space 2023-11-02 05:35:08 -07:00
Joshua Liebow-Feeser 9bfd1c4bdb
Expand mem::offset_of! docs
Makes progress on #106655
2023-11-02 05:25:57 -07:00
Elichai Turkel 5e49a4165e
Add track_caller to transmute_copy 2023-11-02 10:43:59 +02:00
bors 46455dc650 Auto merge of #117386 - roblabla:fix-switch-stdio-win7, r=ChrisDenton
Fix switch_stdout_to on Windows7

The `switch_stdout_to` test was broken on Windows7, as deleting the temporary test folder would fail since the `switch-stdout-output` file we redirected the stdout to is never closed, and it's impossible on Win7 to delete an opened file.

To fix this issue, we make `switch_stdout_to` return the previous handle. Using this, we add a new `switch_stdout_to` call at the end of the test to return the stdio handles to their original state, and recover the handle to the file we opened. This handle is automatically closed at the end of the function, which should allow the temporary test folder to be deleted properly.
2023-11-02 07:58:38 +00:00
massivebird 5b342b7953 fixes: typo in `std::cmp::Ord` trait docs 2023-11-01 23:23:34 -04:00
Kornel 029fbd67ef Hint optimizer about reserved capacity 2023-11-02 00:52:06 +00:00
Michael Goulet 1221b7b652 Rework unsize documentation 2023-11-01 20:16:24 +00:00
Michael Goulet 6af30ec720 Remove a false statement from Unsize docs, add a test 2023-11-01 20:16:11 +00:00
bors 146dafa262 Auto merge of #114208 - GKFX:offset_of_enum, r=wesleywiser
Support enum variants in offset_of!

This MR implements support for navigating through enum variants in `offset_of!`, placing the enum variant name in the second argument to `offset_of!`. The RFC placed it in the first argument, but I think it interacts better with nested field access in the second, as you can then write things like

```rust
offset_of!(Type, field.Variant.field)
```

Alternatively, a syntactic distinction could be made between variants and fields (e.g. `field::Variant.field`) but I'm not convinced this would be helpful.

[RFC 3308 # Enum Support](https://rust-lang.github.io/rfcs/3308-offset_of.html#enum-support-offset_ofsomeenumstructvariant-field_on_variant)
Tracking Issue #106655.
2023-11-01 14:17:56 +00:00
Matthias Krüger 260e07b0cb
Rollup merge of #115626 - clarfonthey:unchecked-math, r=thomcc
Clean up unchecked_math, separate out unchecked_shifts

Tracking issue: #85122

Changes:

1. Remove `const_inherent_unchecked_arith` flag and make const-stability flags the same as the method feature flags. Given the number of other unsafe const fns already stabilised, it makes sense to just stabilise these in const context when they're stabilised.
2. Move `unchecked_shl` and `unchecked_shr` into a separate `unchecked_shifts` flag, since the semantics for them are unclear and they'll likely be stabilised separately as a result.
3. Add an `unchecked_neg` method exclusively to signed integers, under the `unchecked_neg` flag. This is because it's a new API and probably needs some time to marinate before it's stabilised, and while it *would* make sense to have a similar version for unsigned integers since `checked_neg` also exists for those there is absolutely no case where that would be a good idea, IMQHO.

The longer-term goal here is to prepare the `unchecked_math` methods for an FCP and stabilisation since they've existed for a while, their semantics are clear, and people seem in favour of stabilising them.
2023-11-01 11:29:41 +01:00
bors 815b3ae00a Auto merge of #115356 - devnexen:haiku_set_name_use_return, r=thomcc
`std:🧵:set_name` exploit the return on haiku
2023-11-01 07:53:49 +00:00
bors dd24c7bdbf Auto merge of #117422 - joshtriplett:stabilize-file-times, r=workingjubilee
Stabilize `file_set_times`

Approved via FCP in https://github.com/rust-lang/rust/issues/98245 .
2023-11-01 05:35:39 +00:00
George Bateman e742f809f6
Update based on wesleywiser review 2023-10-31 23:41:40 +00:00
George Bateman 9d6ce61376
Update MIR tests for offset_of 2023-10-31 23:26:02 +00:00
George Bateman d995bd61e7
Enums in offset_of: update based on est31, scottmcm & llogiq review 2023-10-31 23:26:02 +00:00
bors 09ac6e4b6d Auto merge of #117459 - matthiaskrgr:rollup-t3osb3c, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #113241 (rustdoc: Document lack of object safety on affected traits)
 - #117388 (Turn const_caller_location from a query to a hook)
 - #117417 (Add a stable MIR visitor)
 - #117439 (prepopulate opaque ty storage before using it)
 - #117451 (Add support for pre-unix-epoch file dates on Apple platforms (#108277))

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-31 23:08:56 +00:00
Sebastian Thiel a8ece1190b
Add support for pre-unix-epoch file dates on Apple platforms (#108277)
Time in UNIX system calls counts from the epoch, 1970-01-01. The timespec
struct used in various system calls represents this as a number of seconds and
a number of nanoseconds. Nanoseconds are required to be between 0 and
999_999_999, because the portion outside that range should be represented in
the seconds field; if nanoseconds were larger than 999_999_999, the seconds
field should go up instead.

Suppose you ask for the time 1969-12-31, what time is that? On UNIX systems
that support times before the epoch, that's seconds=-86400, one day before the
epoch. But now, suppose you ask for the time 1969-12-31 23:59:00.1. In other
words, a tenth of a second after one minute before the epoch.  On most UNIX
systems, that's represented as seconds=-60, nanoseconds=100_000_000. The macOS
bug is that it returns seconds=-59, nanoseconds=-900_000_000.

While that's in some sense an accurate description of the time (59.9 seconds
before the epoch), that violates the invariant of the timespec data structure:
nanoseconds must be between 0 and 999999999. This causes this assertion in the
Rust standard library.

So, on macOS, if we get a Timespec value with seconds less than or equal to
zero, and nanoseconds between -999_999_999 and -1 (inclusive), we can add
1_000_000_000 to the nanoseconds and subtract 1 from the seconds, and then
convert.  The resulting timespec value is still accepted by macOS, and when fed
back into the OS, produces the same results. (If you set a file's mtime with
that timestamp, then read it back, you get back the one with negative
nanoseconds again.)

Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2023-10-31 17:00:59 +01:00
Oli Scherer 4512f211ae Accept less invalid Rust in rustdoc 2023-10-31 13:58:03 +00:00
roblabla 4971e997e5 Fix switch_stdout_to on Windows7
The switch_stdout_to test was broken on Windows7, as the test
infrastructure would refuse to delete the temporary test folder because
the switch-stdout-output file we redirected the stdout to was still
opened.

To fix this issue, we make switch_stdout_to return the previous handle,
and add a new switch_stdout_to call at the end of the test to return the
stdio handles to their original state. The handle the second
switch_stdout_to returns will be automatically closed, which should
allow the temporary test folder to be deleted properly.
2023-10-31 09:50:07 +01:00
Bugen Zhao c872ccc510
delegate box error provide
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
2023-10-31 16:35:59 +08:00
Josh Triplett bcfc48db76 Stabilize `file_set_times`
Approved via FCP in https://github.com/rust-lang/rust/issues/98245 .
2023-10-31 14:34:02 +08:00
León Orell Valerian Liehr 5eb76fac7c
Rollup merge of #117205 - weiznich:multiple_notes_for_on_unimplemented, r=compiler-errors
Allows `#[diagnostic::on_unimplemented]` attributes to have multiple

notes

This commit extends the `#[diagnostic::on_unimplemented]` (and `#[rustc_on_unimplemented]`) attributes to allow multiple `note` options. This enables emitting multiple notes for custom error messages. For now I've opted to not change any of the existing usages of `#[rustc_on_unimplemented]` and just updated the relevant compile tests.

r? `@compiler-errors`

I'm happy to adjust any of the existing changed location to emit the old error message if that's desired.
2023-10-30 10:48:18 +01:00
León Orell Valerian Liehr 098bb3703c
Rollup merge of #117177 - Ayush1325:uefi-alloc-type, r=workingjubilee
Use ImageDataType for allocation type

Suggested at #100499

cc `@dvdhrm`
cc `@nicholasbishop`
2023-10-30 10:48:18 +01:00
Ayush Singh 441068b613
Use ImageDataType for allocation type
Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
2023-10-30 10:27:10 +05:30
Jonathan Behrens bc058b6f45 Add tracking issue 2023-10-29 19:11:18 -07:00
bors bcb5798dd8 Auto merge of #117332 - saethlin:panic-immediate-abort, r=workingjubilee
Increase the reach of panic_immediate_abort

I wanted to use/abuse this recently as part of another project, and I was surprised how many panic-related things were left in my binaries if I built a large crate with the feature enabled along with LTO. These changes get all the panic-related symbols that I could find out of my set of locally installed Rust utilities.
2023-10-30 00:03:47 +00:00
bors 608e9682f0 Auto merge of #117089 - wesleywiser:update_backtrace, r=Mark-Simulacrum
Update backtrace submodule

This pulls in a few notable changes (see the [complete list](99faef833f...e9da96eb45) for details):

- https://github.com/rust-lang/backtrace-rs/pull/508
- https://github.com/rust-lang/backtrace-rs/pull/566
- https://github.com/rust-lang/backtrace-rs/pull/569
  - Fixes #116403 by no longer using `dbghelp.dll` during backtrace capture.
2023-10-29 20:38:32 +00:00
Ben Kimock 2e7364a586 Increase the reach of panic_immediate_abort 2023-10-29 09:31:07 -04:00
Guillaume Gomez 72012402e1
Rollup merge of #117312 - RalfJung:memcpy-assumptions, r=Mark-Simulacrum
memcpy assumptions: link to source showing that GCC makes the same assumption

I finally stumbled upon a source showing that GCC also generates overlapping `memcpy`. So if we're linking major C compilers making such assumptions here, let's have both clang and GCC.
2023-10-29 12:35:01 +01:00
Guillaume Gomez e9c7ebe2cd
Rollup merge of #115968 - git-bruh:master, r=workingjubilee
Don't use LFS64 symbols on musl

Supersedes #106246

~~Note to packagers: If your distro's musl package has already been updated, then you won't be able to build a newer version of rust until a new rust release is made with these changes merged (which can be used to bootstrap). I'm using a super hacky method to bypass this by creating a stub library with LFS64 symbols and building a patched rust, so the symbols satisfy the build requirements while the final compiler build has no references to LFS64 symbols, example: https://codeberg.org/kiss-community/repo/pulls/160/files~~ Doesn't seem to be necessary with new rustup nightly builds, likely due to updates to vendored crates

cc ```@alyssais```
2023-10-29 12:34:59 +01:00
Jubilee Young 6649219c3f Remove asmjs from library 2023-10-28 23:10:45 -07:00
git-bruh 7a504cc68a Don't use LFS64 symbols on musl
Simplify #[cfg] blocks

fmt

don't try to use the more appropriate direntry on musl
2023-10-29 03:29:27 +00:00
Jubilee 2dd37d402c
Rollup merge of #117316 - Coekjan:const-binary-heap-constructor, r=dtolnay
Mark constructor of `BinaryHeap` as const fn

#112353
2023-10-28 17:08:05 -07:00
Jubilee 61cd3d0174
Rollup merge of #117162 - c410-f3r:try, r=workingjubilee
Remove `cfg_match` from the prelude

Fixes #117057

cc #115585
2023-10-28 17:08:04 -07:00
bors 7cc36de72d Auto merge of #116240 - dtolnay:constdiscriminant, r=thomcc
Const stabilize mem::discriminant

Tracking issue: #69821.

This PR is a rebase of https://github.com/rust-lang/rust/pull/103893 to resolve conflicts in library/core/src/lib.rs (against #102470 and #110393).
2023-10-28 19:38:15 +00:00
Ralf Jung 70a8e157ab make pointer_structural_match warn-by-default 2023-10-28 17:02:18 +02:00
coekjan 4dd7568a97
mark constructor of `BinaryHeap` as const fn 2023-10-28 21:30:43 +08:00
bors 7314873326 Auto merge of #117038 - saethlin:inline-range-methods, r=workingjubilee
Add #[inline] to some recalcitrant ops::range methods

Fixes https://github.com/rust-lang/rust/issues/116861
2023-10-28 13:21:00 +00:00
bors 3089c315b1 Auto merge of #116609 - eduardosm:bump-stdarch, r=workingjubilee
Bump stdarch submodule and remove special handling for LLVM intrinsics that are no longer needed

Bumps stdarch to pull https://github.com/rust-lang/stdarch/pull/1477, which reimplemented some functions with portable SIMD intrinsics instead of arch specific LLVM intrinsics.

Handling of those LLVM intrinsics is removed from cranelift codegen and miri.

cc `@RalfJung` `@bjorn3`
2023-10-28 11:26:34 +00:00
Ralf Jung b329c69f6c memcpy assumptions: link to source showing that GCC makes the same assumption 2023-10-28 11:54:04 +02:00
Jubilee d87b5e4727
Rollup merge of #116816 - ChrisDenton:api.rs, r=workingjubilee
Create `windows/api.rs` for safer FFI

FFI is inherently unsafe. For memory safety we need to assert that some contract is being upheld on both sides of the FFI, though of course we can only ever check our side. In Rust, `unsafe` blocks are used to assert safety and `// SAFETY` comments describing why it is safe. Currently in sys/windows we have a lot of this unsafety spread all over the place, with variations on the same unsafe patterns repeated. And because of the repitition and frequency, we're a bit lax with the safety comments.

This PR aims to fix this and to make FFI safety more auditable by creating an `api` module with the goal of centralising and consolidating this unsafety. It contains thin wrappers around the Windows API that make most functions safe to call or, if that's not possible, then at least safer. Note that its goal is *only* to address safety. It does not stray far from the Windows API and intentionally does not attempt to make higher lever wrappers around, for example, file handles. This is better left to the existing modules. The windows/api.rs file has a top level comment to help future contributors understand the intent of the module and the design decisions made.

I chose two functions as a first tentative step towards the above goal:

- [`GetLastError`](https://learn.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-getlasterror) is trivially safe. There's no reason to wrap it in an `unsafe` block every time. So I simply created a safe `get_last_error` wrapper.
- [`SetFileInformationByHandle`](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-setfileinformationbyhandle) is more complex. It essentially takes a generic type but over a C API which necessitates some amount of ceremony. Rather than implementing similar unsafe patterns in multiple places, I provide a safe `set_file_information_by_handle` that takes a Rusty generic type and handles converting that to the form required by the C FFI.

r? libs
2023-10-28 01:07:36 -07:00
Matthias Krüger f9d62a84f0
Rollup merge of #117281 - RalfJung:thread-safety, r=thomcc
std::thread : add SAFETY comment

I forgot to add this in https://github.com/rust-lang/rust/pull/117266.
2023-10-27 19:46:10 +02:00
Matthias Krüger 60b071fa8a
Rollup merge of #117270 - jhpratt:hide-print-internals, r=ChrisDenton
Hide internal methods from documentation

The two methods here are perma-unstable and only made public for technical reasons. There is no reason to show them in documentation.

`@rustbot` label +A-docs
2023-10-27 19:46:09 +02:00
Ralf Jung ccb36a688d std:🧵 add SAFETY comment 2023-10-27 15:18:32 +02:00
Georg Semmler 160b1793b2
Allows `#[diagnostic::on_unimplemented]` attributes to have multiple
notes

This commit extends the `#[diagnostic::on_unimplemented]` (and
`#[rustc_on_unimplemented]`) attributes to allow multiple `note`
options. This enables emitting multiple notes for custom error messages.
For now I've opted to not change any of the existing usages of
`#[rustc_on_unimplemented]` and just updated the relevant compile tests.
2023-10-27 12:42:42 +02:00
bors 95f6a01e8f Auto merge of #117272 - matthiaskrgr:rollup-upg122z, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #114998 (feat(docs): add cargo-pgo to PGO documentation 📝)
 - #116868 (Tweak suggestion span for outer attr and point at item following invalid inner attr)
 - #117240 (Fix documentation typo in std::iter::Iterator::collect_into)
 - #117241 (Stash and cancel cycle errors for auto trait leakage in opaques)
 - #117262 (Create a new ConstantKind variant (ZeroSized) for StableMIR)
 - #117266 (replace transmute by raw pointer cast)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-27 10:19:35 +00:00
Matthias Krüger 2fdac630b4
Rollup merge of #117266 - RalfJung:cast-not-transmute, r=thomcc
replace transmute by raw pointer cast

Now that https://github.com/rust-lang/rust/issues/113257 is fixed we can finally do this. :)
2023-10-27 11:48:07 +02:00
Matthias Krüger 203292e489
Rollup merge of #117240 - trueNAHO:docs-std-iter-Iterator-collect-into-fix-typo, r=the8472
Fix documentation typo in std::iter::Iterator::collect_into
2023-10-27 11:48:06 +02:00
Jacob Pratt 72d5f4b1dc
Hide internal methods from documentation 2023-10-27 04:30:49 -04:00
bors 54e57e66ff Auto merge of #116205 - WaffleLapkin:stabilize_pointer_byte_offsets, r=dtolnay
Stabilize `[const_]pointer_byte_offsets`

Closes #96283
Awaiting FCP completion: https://github.com/rust-lang/rust/issues/96283#issuecomment-1735835331

r? libs-api
2023-10-27 08:24:54 +00:00
Ralf Jung b3f7f4dff7 replace transmute by raw pointer cast 2023-10-27 08:02:16 +02:00
bors 707d8c3f1b Auto merge of #117260 - okaneco:ascii_branchless, r=thomcc
Refactor some `char`, `u8` ASCII functions to be branchless

Extract conditions in singular `matches!` with or-patterns to individual `matches!` statements which enables branchless code output. The following functions were changed:
- `is_ascii_alphanumeric`
- `is_ascii_hexdigit`
- `is_ascii_punctuation`

Added codegen tests

---

Continued from https://github.com/rust-lang/rust/pull/103024.
Based on the comment from `@scottmcm` https://github.com/rust-lang/rust/pull/103024#pullrequestreview-1248697206.

The unmodified `is_ascii_*` functions didn't seem to benefit from extracting the conditions.

I've never written a codegen test before, but I tried to check that no branches were emitted.
2023-10-27 04:06:40 +00:00
okaneco 465ffc9ca7 Refactor some `char`, `u8` ascii functions to be branchless
Decompose singular `matches!` with or-patterns to individual `matches!`
statements to enable branchless code output. The following functions
were changed:
- `is_ascii_alphanumeric`
- `is_ascii_hexdigit`
- `is_ascii_punctuation`

Add codegen tests

Co-authored-by: George Bateman <george.bateman16@gmail.com>
Co-authored-by: scottmcm <scottmcm@users.noreply.github.com>
2023-10-26 21:48:36 -04:00