Commit Graph

13017 Commits

Author SHA1 Message Date
Matthias Krüger 10ad10ee2a
Rollup merge of #119051 - ChrisDenton:wine, r=workingjubilee
Replace `FileAllocationInfo` with `FileEndOfFileInfo`

This fixes WINE support
2023-12-18 08:08:24 +01:00
Caleb Zulawski d655dd6dca Add new intrinsics 2023-12-17 23:00:29 -05:00
Caleb Zulawski 4767aaf826 Further explain semantics 2023-12-17 21:17:00 -05:00
Caleb Zulawski e245bafa9c Apply suggestions from code review
Co-authored-by: Ralf Jung <post@ralfj.de>
2023-12-17 21:17:00 -05:00
Caleb Zulawski 71a5698989 Improve simd_bitmask documentation and other minor fixes 2023-12-17 21:17:00 -05:00
Caleb Zulawski 560ac23b70 State type requirements first 2023-12-17 21:17:00 -05:00
Caleb Zulawski 1fd7de062e Clarify UB and improve grammar
Co-authored-by: Ralf Jung <post@ralfj.de>
2023-12-17 21:17:00 -05:00
Caleb Zulawski ef4cf01542 Add core::intrinsics::simd 2023-12-17 21:16:59 -05:00
bors 43dcc9b786 Auto merge of #114962 - darklyspaced:debug, r=est31
adds a column number to `dbg!()`

this would be very nice to have for a few reasons:
1. the rfc, when deciding not to add column numbers to macro, failed to acknowledge any potential ambiguous cases -- such as the one provided in #114910 -- which do exist
2. would be able to consistently and easily jump directly to the `dbg!()` regardless of the sutation
3. takes up, at a maximum, 3 characters of _horizontal_ screen space

fixes #114910
2023-12-17 23:01:18 +00:00
Chris Denton e585b0ed58
Use FileEndOfFileInfo, not FileAllocationInfo
This fixes WINE support
2023-12-17 17:57:33 +00:00
Ralf Jung c7e3b3f84c do not allow ABI mismatches inside repr(C) types 2023-12-17 09:34:25 +01:00
bors 5e7025419d Auto merge of #118830 - GuillaumeGomez:env-tracked_env, r=Nilstrieb
Add support for `--env` on `tracked_env::var`

Follow-up of https://github.com/rust-lang/rust/pull/118368.
Part of Part of https://github.com/rust-lang/rust/issues/80792.

It adds support of the `--env` option for proc-macros through `tracked_env::var`.

r? `@Nilstrieb`
2023-12-17 04:23:08 +00:00
Jubilee 6c2f00fbd7
Rollup merge of #118851 - bzEq:std-xcoff, r=Mark-Simulacrum
[std] Add xcoff in object's feature list

object-0.32.0 has supported XCOFF format. And backtrace in submodule has been updated to support XCOFF and AIX. Add `xcoff` to supported feature list to make backtrace built on AIX.
2023-12-15 21:32:58 -08:00
Jubilee 15e84ebc7b
Rollup merge of #118523 - okaneco:trim_ascii, r=Mark-Simulacrum
Add ASCII whitespace trimming functions to `&str`

- Add `trim_ascii_start`, `trim_ascii_end`, and `trim_ascii` functions to `&str` for trimming ASCII whitespace
- Add `#[inline]` to `[u8]` `trim_ascii` functions

These functions are feature-gated by `#![feature(byte_slice_trim_ascii)]` #94035
2023-12-15 21:32:57 -08:00
Jubilee 4b447b8bb7
Rollup merge of #118998 - jstasiak:improve-doc, r=workingjubilee
Link to is_benchmark from the Ipv6Addr::is_global documentation

All other relevant is_* methods are mentioned in the list of addresses here, is_benchmarking has been the only one missing.
2023-12-15 14:08:18 -08:00
Jubilee 5e85fece3a
Rollup merge of #118956 - danielhuang:patch-2, r=workingjubilee
Make CStr documentation consistent ("nul" instead of "null")

"nul" is used in method names and appears more often in the documentation than "null", so make all instances "nul" to keep it consistent.
2023-12-15 14:08:16 -08:00
Jubilee 1d54949765
Rollup merge of #118396 - compiler-errors:ast-lang-items, r=cjgillot
Collect lang items from AST, get rid of `GenericBound::LangItemTrait`

r? `@cjgillot`
cc #115178

Looking forward, the work to remove `QPath::LangItem` will also be significantly more difficult, but I plan on doing it as well. Specifically, we have to change:
1. A lot of `rustc_ast_lowering` for things like expr `..`
2. A lot of astconv, since we actually instantiate lang and non-lang paths quite differently.
3. A ton of diagnostics and clippy lints that are special-cased via `QPath::LangItem`

Meanwhile, it was pretty easy to remove `GenericBound::LangItemTrait`, so I just did that here.
2023-12-15 14:08:15 -08:00
Jakub Stasiak 47282799da Add link to is_benchmark from the Ipv6Addr::is_global documentation
All other relevant is_* methods are mentioned in the list of addresses
here, is_benchmarking has been the only one missing.
2023-12-15 20:53:54 +01:00
Matthias Krüger ea6daca3cb
Rollup merge of #118234 - tgross35:type_name_of_value, r=dtolnay
Stabilize `type_name_of_val`

Make the following API stable:

```rust
// in core::any
pub fn type_name_of_val<T: ?Sized>(_val: &T) -> &'static str
```

This is a convenience method to get the type name of a value, as opposed to `type_name` that takes a type as a generic.

Const stability is not added because this relies on `type_name` which is also not const. That has a blocking issue https://github.com/rust-lang/rust/issues/97156.

Wording was also changed to direct most of the details to `type_name` so we don't have as much duplicated documentation.

Fixes tracking issue #66359.

There were two main concerns in the tracking issue:

1. Naming: `type_name_of` and `type_name_of_val` seem like the only mentioned options. Differences in opinion here come from `std::mem::{size_of, align_of, size_of_val, align_of_val}`. This PR leaves the name as `type_name_of_val`, but I can change if desired since it is pretty verbose.
2. What this displays for `&dyn`: I don't think that having `type_name_of_val` function resolve those is worth the headache it would be, see https://github.com/rust-lang/rust/issues/66359#issuecomment-1718480774 for some workarounds. I also amended the docs wording to leave it open-ended, in case we have means to change that behavior in the future.

``@rustbot`` label -T-libs +T-libs-api +needs-fcp
r? libs-api
2023-12-15 20:19:53 +01:00
Maybe Waffle b863e9ba57
Stabilize `ptr::{from_ref, from_mut}` 2023-12-15 08:34:59 -08:00
Cameron Steffen 04fafd69de Cfg remove lang items in doctest 2023-12-15 16:17:28 +00:00
bors cca2bda07e Auto merge of #118966 - matthiaskrgr:rollup-sdvjwy6, r=matthiaskrgr
Rollup of 3 pull requests

Successful merges:

 - #116888 (Add discussion that concurrent access to the environment is unsafe)
 - #118888 (Uplift `TypeAndMut` and `ClosureKind` to `rustc_type_ir`)
 - #118929 (coverage: Tidy up early parts of the instrumentor pass)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-12-15 06:52:44 +00:00
Matthias Krüger 44fd74aede
Rollup merge of #116888 - tbu-:pr_unsafe_env, r=Amanieu
Add discussion that concurrent access to the environment is unsafe

The bug report #27970 has existed for 8 years, the actual bug dates back to Rust pre-1.0. I documented it since it's in the interest of the user to be aware of it. The note can be removed once #27970 is fixed.
2023-12-15 06:50:17 +01:00
bors 1559dd2dbf Auto merge of #118770 - saethlin:fix-inline-never-uses, r=nnethercote
Fix cases where std accidentally relied on inline(never)

This PR increases the power of `-Zcross-crate-inline-threshold=always` so that it applies through `#[inline(never)]`. Note that though this is called "cross-crate-inlining" in this case especially it is _just_ lazy per-CGU codegen. The MIR inliner and LLVM still respect the attribute as much as they ever have.

Trying to bootstrap with the new `-Zcross-crate-inline-threshold=always` change revealed two bugs:

We have special intrinsics `assert_inhabited`, `assert_zero_valid`, and `assert_mem_uniniitalized_valid` which codegen backends will lower to nothing or a call to `panic_nounwind`.  Since we may not have any call to `panic_nounwind` in MIR but emit one anyway, we need to specially tell `MirUsedCollector` about this situation.

`#[lang = "start"]` is special-cased already so that `MirUsedCollector` will collect it, but then when we make it cross-crate-inlinable it is only assigned to a CGU based on whether `MirUsedCollector` saw a call to it, which of course we didn't.

---

I started looking into this because https://github.com/rust-lang/rust/pull/118683 revealed a case where we were accidentally relying on a function being `#[inline(never)]`, and cranking up cross-crate-inlinability seems like a way to find other situations like that.

r? `@nnethercote` because I don't like what I'm doing to the CGU partitioning code here but I can't come up with something much better
2023-12-15 04:54:14 +00:00
Daniel Huang f2f9b1d82a
Update c_str.rs 2023-12-14 19:08:36 -05:00
Daniel Huang d031795c81
Update c_str.rs 2023-12-14 19:05:03 -05:00
Urgau 3ea1331f51 Fix target_feature config in portable-simd 2023-12-14 14:50:32 +01:00
Ben Kimock e559172249 Fix cases where std accidentally relied on inline(never) 2023-12-14 08:30:36 -05:00
bors 1aa6aefdc9 Auto merge of #118566 - klensy:cstr-new, r=WaffleLapkin
use c literals in compiler and library

Relands refreshed https://github.com/rust-lang/rust/pull/111647
2023-12-14 11:14:03 +00:00
Tobias Bucher 2093d0c58e Reformulate `std::env::{set,remove}_env` as safety note 2023-12-13 12:49:38 +01:00
bors f651b436ce Auto merge of #117050 - c410-f3r:here-we-go-again, r=petrochenkov
[`RFC 3086`] Attempt to try to resolve blocking concerns

Implements what is described at https://github.com/rust-lang/rust/issues/83527#issuecomment-1744822345 to hopefully make some progress.

It is unknown if such approach is or isn't desired due to the lack of further feedback, as such, it is probably best to nominate this PR to the official entities.

`@rustbot` labels +I-compiler-nominated
2023-12-13 06:37:08 +00:00
bors 9f1bfe53b6 Auto merge of #118900 - workingjubilee:rollup-wkv9hq1, r=workingjubilee
Rollup of 10 pull requests

Successful merges:

 - #118858 (Remove dead codes in core)
 - #118864 (Fix alignment passed down to LLVM for simd_masked_load)
 - #118872 (Add rustX check to codeblock attributes lint)
 - #118873 (fix `waker_getters` tracking issue number)
 - #118884 (NFC: simplify merging of two vecs)
 - #118885 (clippy::complexity fixes)
 - #118886 (Clean up variables in `search.js`)
 - #118887 (Typo)
 - #118889 (more clippy::complexity fixes)
 - #118891 (Actually parse async gen blocks correctly)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-12-13 04:38:30 +00:00
Jubilee 18e0966f39
Rollup merge of #118873 - lukas-code:fix_waker_getter_tracking_issue_number, r=workingjubilee
fix `waker_getters` tracking issue number

The feature currently links to the closed issue https://github.com/rust-lang/rust/issues/87021. Make it link to the tracking issue https://github.com/rust-lang/rust/issues/96992 instead.
2023-12-12 18:48:52 -08:00
Jubilee 2d1d443d7f
Rollup merge of #118858 - mu001999:dead_code/clean, r=cuviper
Remove dead codes in core

Detected by #118257
2023-12-12 18:48:50 -08:00
bors 77d1699756 Auto merge of #116438 - ChrisDenton:truncate, r=thomcc
Windows: Allow `File::create` to work on hidden files

This makes `OpenOptions::new().write(true).create(true).truncate(true).open(&path)` work if the path exists and is a hidden file. Previously it would fail with access denied.

This makes it consistent with `OpenOptions::new().write(true).truncate(true).open(&path)` (note the lack of `create`) which does not have this restriction. It's also more consistent with other platforms.

Fixes #115745 (see that issue for more details).
2023-12-13 02:27:12 +00:00
Kai Luo 9f64023096 Use different cfg for AIX 2023-12-13 10:15:27 +08:00
okaneco e4808afe8e Add ASCII whitespace trimming functions to `&str`
Add `trim_ascii_start`, `trim_ascii_end`, and `trim_ascii` functions to
`&str` for trimming ASCII whitespace under the `byte_slice_trim_ascii`
feature gate.
Add `inline` to `[u8]` `trim_ascii` functions
2023-12-12 12:53:59 -05:00
Lukas Markeffsky 04f3adb4a7 fix `waker_getters` tracking issue number 2023-12-12 14:38:13 +01:00
darklyspaced cbb36d808b added column number to dbg!() 2023-12-12 18:12:23 +08:00
r01and 6c0dbb8cc6
Remove dead codes in core 2023-12-12 07:03:37 +00:00
Kai Luo d2402e3f0d Add xcoff support 2023-12-12 10:20:06 +08:00
The 8472 6a2f44e9d8 add comment to RawVec::cap field 2023-12-11 23:38:48 +01:00
The 8472 502df1b7d4 add more niches to rawvec 2023-12-11 23:38:48 +01:00
Guillaume Gomez 6ce2fefea6 Add support for `--env` on `tracked_env::var` 2023-12-11 16:44:33 +01:00
bors 8a3765582c Auto merge of #117758 - Urgau:lint_pointer_trait_comparisons, r=davidtwco
Add lint against ambiguous wide pointer comparisons

This PR is the resolution of https://github.com/rust-lang/rust/issues/106447 decided in https://github.com/rust-lang/rust/issues/117717 by T-lang.

## `ambiguous_wide_pointer_comparisons`

*warn-by-default*

The `ambiguous_wide_pointer_comparisons` lint checks comparison of `*const/*mut ?Sized` as the operands.

### Example

```rust
let ab = (A, B);
let a = &ab.0 as *const dyn T;
let b = &ab.1 as *const dyn T;

let _ = a == b;
```

### Explanation

The comparison includes metadata which may not be expected.

-------

This PR also drops `clippy::vtable_address_comparisons` which is superseded by this one.

~~One thing: is the current naming right? `invalid` seems a bit too much.~~

Fixes https://github.com/rust-lang/rust/issues/117717
2023-12-11 14:33:16 +00:00
bors ff2c56344c Auto merge of #118823 - GuillaumeGomez:rollup-6v51gxv, r=GuillaumeGomez
Rollup of 3 pull requests

Successful merges:

 - #118802 (Remove edition umbrella features.)
 - #118807 (Remove an allocation in min_stack)
 - #118812 (rustdoc-search: do not treat associated type names as types)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-12-11 12:33:04 +00:00
Guillaume Gomez f712d73108
Rollup merge of #118807 - SUPERCILEX:allo, r=the8472
Remove an allocation in min_stack
2023-12-11 11:40:37 +01:00
bors 6f40082313 Auto merge of #118661 - fee1-dead-contrib:restore-const-partialEq, r=compiler-errors
Restore `const PartialEq`

And thus fixes a number of tests. There is a bug that still needs to be fixed, so WIP for now.

r? `@compiler-errors`
2023-12-11 10:34:51 +00:00
bors e299752868 Auto merge of #118032 - RalfJung:char-u32, r=Mark-Simulacrum
guarantee that char and u32 are ABI-compatible

In https://github.com/rust-lang/rust/pull/116894 we added a guarantee that `char` has the same alignment as `u32`, but there is still one axis where these types could differ: function call ABI. So let's nail that down as well: in a function signature, `char` and `u32` are completely equivalent.

This is a new stable guarantee, so it will need t-lang approval.
2023-12-11 04:13:19 +00:00
Nicholas Nethercote 925f7fad57 Improve `print_tts` by changing `tokenstream::Spacing`.
`tokenstream::Spacing` appears on all `TokenTree::Token` instances,
both punct and non-punct. Its current usage:
- `Joint` means "can join with the next token *and* that token is a
  punct".
- `Alone` means "cannot join with the next token *or* can join with the
  next token but that token is not a punct".

The fact that `Alone` is used for two different cases is awkward.
This commit augments `tokenstream::Spacing` with a new variant
`JointHidden`, resulting in:
- `Joint` means "can join with the next token *and* that token is a
  punct".
- `JointHidden` means "can join with the next token *and* that token is a
  not a punct".
- `Alone` means "cannot join with the next token".

This *drastically* improves the output of `print_tts`. For example,
this:
```
stringify!(let a: Vec<u32> = vec![];)
```
currently produces this string:
```
let a : Vec < u32 > = vec! [] ;
```
With this PR, it now produces this string:
```
let a: Vec<u32> = vec![] ;
```
(The space after the `]` is because `TokenTree::Delimited` currently
doesn't have spacing information. The subsequent commit fixes this.)

The new `print_tts` doesn't replicate original code perfectly. E.g.
multiple space characters will be condensed into a single space
character. But it's much improved.

`print_tts` still produces the old, uglier output for code produced by
proc macros. Because we have to translate the generated code from
`proc_macro::Spacing` to the more expressive `token::Spacing`, which
results in too much `proc_macro::Along` usage and no
`proc_macro::JointHidden` usage. So `space_between` still exists and
is used by `print_tts` in conjunction with the `Spacing` field.

This change will also help with the removal of `Token::Interpolated`.
Currently interpolated tokens are pretty-printed nicely via AST pretty
printing. `Token::Interpolated` removal will mean they get printed with
`print_tts`. Without this change, that would result in much uglier
output for code produced by decl macro expansions. With this change, AST
pretty printing and `print_tts` produce similar results.

The commit also tweaks the comments on `proc_macro::Spacing`. In
particular, it refers to "compound tokens" rather than "multi-char
operators" because lifetimes aren't operators.
2023-12-11 09:19:09 +11:00
Alex Saveau af8dfde7f9
Remove an allocation in min_stack
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2023-12-10 13:28:59 -08:00
bors 84f6130fe3 Auto merge of #118692 - surechen:remove_unused_imports, r=petrochenkov
remove redundant imports

detects redundant imports that can be eliminated.

for #117772 :

In order to facilitate review and modification, split the checking code and removing redundant imports code into two PR.

r? `@petrochenkov`
2023-12-10 11:55:48 +00:00
Deadbeef f635cd2e82 Restore `const PartialEq` 2023-12-10 09:30:07 +00:00
bors c1a3919378 Auto merge of #118792 - naglis:fix-mutex-doc-typo, r=workingjubilee
Fix typo in `std::sync::Mutex` example
2023-12-10 09:02:29 +00:00
bors 61afc9c928 Auto merge of #116949 - hamza1311:stablize-arc_unwrap_or_clone, r=dtolnay
Stablize arc_unwrap_or_clone

Fixes: #93610

This likely needs FCP. I created this PR as it's stabilization is trivial and FCP can be just conducted here. Not sure how to ping the libs API team (last attempt didn't work apparently according to GH UI)
2023-12-10 05:01:00 +00:00
surechen 40ae34194c remove redundant imports
detects redundant imports that can be eliminated.

for #117772 :

In order to facilitate review and modification, split the checking code and
removing redundant imports code into two PR.
2023-12-10 10:56:22 +08:00
naglis 7d50a39763 Fix typo in `std::sync::Mutex` example 2023-12-10 02:21:53 +02:00
bors 608f32435a Auto merge of #117873 - quininer:android-emutls, r=Amanieu
Add emulated TLS support

This is a reopen of https://github.com/rust-lang/rust/pull/96317 . many android devices still only use 128 pthread keys, so using emutls can be helpful.

Currently LLVM uses emutls by default for some targets (such as android, openbsd), but rust does not use it, because `has_thread_local` is false.

This commit has some changes to allow users to enable emutls:

1. add `-Zhas-thread-local` flag to specify that std uses `#[thread_local]` instead of pthread key.
2. when using emutls, decorate symbol names to find thread local symbol correctly.
3. change `-Zforce-emulated-tls` to `-Ztls-model=emulated` to explicitly specify whether to generate emutls.

r? `@Amanieu`
2023-12-09 05:32:35 +00:00
bors 1a3aa4ad14 Auto merge of #114136 - TennyZhuang:linked-list-retain, r=thomcc
add LinkedList::{retain,retain_mut}

Implement #114135

The API is consistent with other collections.
2023-12-09 02:38:45 +00:00
Michael Goulet 96bb542a31 Implement `async gen` blocks 2023-12-08 17:23:25 +00:00
Matthias Krüger 982a238ac9
Rollup merge of #118581 - ianrrees:add-drop-note-to-once_lock, r=workingjubilee
OnceLock: Add note about drop and statics

Hi!  Just a minor documentation addition, I've attempted to build docs locally but ran in to issues, so am not 100% sure this change will render correctly.
2023-12-08 06:44:41 +01:00
Matthias Krüger 992f7ee5fd
Rollup merge of #118505 - CLEckhardt:update_ip_addr_bits_docs, r=cuviper
Elaborate on ip_addr bit conversion endianness

Adds explanation of how endianness is handled when converting `Ipv4Addr` and `Ipv6Addr` to and from bits. This is intended to unblock stabilization of the affected methods.

Addresses #113744
2023-12-08 06:44:41 +01:00
Ian Rees 88fccc465f OnceLock: Rework example, statics aren't dropped 2023-12-08 09:49:54 +13:00
Chris Eckhardt c3bb1b50a5 Elaborate on ip_addr bit conversion endianness
Adds explanation of how endianness is handled when converting `Ipv4Addr`
and `Ipv6Addr` to and from bits.

Addresses #113744
2023-12-07 09:16:03 -06:00
bors 568f6a8641 Auto merge of #116565 - Sword-Destiny:master, r=Amanieu
add teeos std impl

add teeos std library implement.

this MR is draft untill the libc update to 0.2.150

this MR is the final step for suppot rust in teeos.
first step(add target): https://github.com/rust-lang/rust/pull/113480
second step(add teeos libc): https://github.com/rust-lang/libc/pull/3333
2023-12-07 05:22:21 +00:00
袁浩 e353eb91fb add teeos std impl
Signed-off-by: 袁浩 <yuanhao34@huawei.com>
2023-12-07 10:33:03 +08:00
bors c9d85d67c4 Auto merge of #117960 - zhiqiangxu:dry, r=workingjubilee
chore: avoid duplicate code in `Weak::inner`
2023-12-07 02:27:41 +00:00
Matthias Krüger 2f71a448c0
Rollup merge of #118669 - klensy:comment-fix, r=workingjubilee
library: fix comment about const assert in win api

Resolves [comment ](https://github.com/rust-lang/rust/pull/116816#discussion_r1415869524)

r? `@workingjubilee`
2023-12-06 17:22:00 +01:00
Matthias Krüger 49d6594278
Rollup merge of #117563 - 0xalpharush:docs/into-raw, r=workingjubilee
docs: clarify explicitly freeing heap allocated memory

The documentation for `Box::into_raw` didn't mention `drop` and wondered if I was doing something wrong. Based off [this](https://stackoverflow.com/questions/75441199/rust-how-do-i-correctly-free-heap-allocated-memory), I think it's helpful to include the more concise yet explicit way to free heap allocated memory. This is my first rust PR and I went through https://std-dev-guide.rust-lang.org/development/, but let me know if I missed something :)
2023-12-06 17:21:57 +01:00
quininer e5b76892cc Add emulated TLS support
Currently LLVM uses emutls by default
for some targets (such as android, openbsd),
but rust does not use it, because `has_thread_local` is false.

This commit has some changes to allow users to enable emutls:

1. add `-Zhas-thread-local` flag to specify
    that std uses `#[thread_local]` instead of pthread key.
2. when using emutls, decorate symbol names
    to find thread local symbol correctly.
3. change `-Zforce-emulated-tls` to `-Ztls-model=emulated`
    to explicitly specify whether to generate emutls.
2023-12-07 00:21:32 +08:00
klensy 7ff9648808 library: fix comment about const assert in win api 2023-12-06 13:52:30 +03:00
bors 15bb3e204a Auto merge of #118460 - the8472:fix-vec-realloc, r=saethlin
Fix in-place collect not reallocating when necessary

Regression introduced in https://github.com/rust-lang/rust/pull/110353.
This was [caught by miri](https://rust-lang.zulipchat.com/#narrow/stream/269128-miri/topic/Cron.20Job.20Failure.20.28miri-test-libstd.2C.202023-11.29/near/404764617)

r? `@saethlin`
2023-12-06 08:45:11 +00:00
Urgau 5e1bfb538f Adjust tests for newly added ambiguous_wide_pointer_comparisons lint 2023-12-06 09:03:48 +01:00
Urgau 30c7b18d25 Allow ambiguous_wide_pointer_comparisons lint for std methods 2023-12-06 09:03:48 +01:00
bors 1dd4db5062 Auto merge of #118655 - compiler-errors:rollup-vrngyzn, r=compiler-errors
Rollup of 9 pull requests

Successful merges:

 - #117793 (Update variable name to fix `unused_variables` warning)
 - #118123 (Add support for making lib features internal)
 - #118268 (Pretty print `Fn<(..., ...)>` trait refs with parentheses (almost) always)
 - #118346 (Add `deeply_normalize_for_diagnostics`, use it in coherence)
 - #118350 (Simplify Default for tuples)
 - #118450 (Use OnceCell in cell module documentation)
 - #118585 (Fix parser ICE when recovering `dyn`/`impl` after `for<...>`)
 - #118587 (Cleanup error handlers some more)
 - #118642 (bootstrap(builder.rs): Don't explicitly warn against `semicolon_in_expressions_from_macros`)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-12-06 04:20:51 +00:00
bors 84a554cda9 Auto merge of #117072 - betrusted-io:unwinding-crate-support, r=cuviper
Use `unwinding` crate for unwinding on Xous platform

This patch adds support for using [unwinding](https://github.com/nbdd0121/unwinding) on platforms where libunwinding isn't viable. An example of such a platform is `riscv32imac-unknown-xous-elf`.

### Background

The Rust project maintains a fork of llvm at [llvm-project](https://github.com/rust-lang/llvm-project/) where it applies patches on top of the llvm project. This mostly seems to be to get unwinding support for the SGX project, and there may be other patches that I'm unaware of.

There is a lot of machinery in the build system to support compiling `libunwind` on other platforms, and I needed to add additional patches to llvm in order to add support for Xous.

Rather than continuing down this path, it seemed much easier to use a Rust-based library. The `unwinding` crate by `@nbdd0121` fits this description perfectly.

### Future work

This could potentially replace the custom patches for `libunwind` on other platforms such as SGX, and could enable unwinding support on many more exotic platforms.

### Anti-goals

This is not designed to replace `libunwind` on tier-one platforms or those where unwinding support already exists. There is already a well-established approach for unwinding there. Instead, this aims to enable unwinding on new platforms where C++ code may be difficult to compile.
2023-12-06 02:23:01 +00:00
Sean Cross a6b8de68a6 std: xous: take eh_frame address from main args
The main() function takes an argument that contains the eh_frame
address. Implement `unwinding` support by looking for unwinding data at
this address.

Signed-off-by: Sean Cross <sean@xobs.io>
2023-12-06 09:07:07 +08:00
zhiqiangxu 75d76c8ffe Don't repeat yourself 2023-12-06 09:02:19 +08:00
bors 28968414c5 Auto merge of #118547 - alexcrichton:invert-common-net-inclusion, r=workingjubilee
std: Invert logic for inclusion of `sys_common::net`

The `library/std/src/sys_common/net.rs` module is intended to define common implementations of networking-related APIs across a variety of platforms that share similar APIs (e.g. Berkeley-style sockets and all). This module is not included for more fringe targets however such as UEFI or "unknown" targets to libstd (those classified as `restricted-std`). Previously the `sys_common/net.rs` file was set up such that an allow-list indicated it shouldn't be used. This commit inverts the logic to have an allow-list of when it should be used instead.

The goal of this commit is to make it a bit easier to experiment with a new Rust target. Currently more esoteric targets are required to get an exception in this `cfg_if` block to use `crate::sys::net` such as for unsupported targets. With this inversion of logic only targets which actually support networking will be listed, where most of those are lumped under `cfg(unix)`.

Given that this change is likely to cause some breakage for some target by accident I've attempted to be somewhat robust with this by following these steps to defining the new predicate for inverted logic.

1. Take all supported targets and filter out all `cfg(unix)` ones as these should all support `sys_common/net.rs`.
2. Take remaining targets and filter out `cfg(windows)` ones.
3. The remaining dozen-or-so targets were all audited by hand. Mostly this included `target_os = "hermit"` and `target_os = "solid_asp3"` which required an allow-list entry, but remaining targets were all already excluded (didn't use `sys_common/net.rs` so they were left out.

If this causes breakage it should be relatively easy to fix and I'd be happy to follow-up with any PRs necessary.
2023-12-06 00:04:28 +00:00
bors e9013ac0e4 Auto merge of #118273 - AngelicosPhosphoros:dedup_2_loops_version_77772_2, r=the8472
Split `Vec::dedup_by` into 2 cycles

First cycle runs until we found 2 same elements, second runs after if there any found in the first one. This allows to avoid any memory writes until we found an item which we want to remove.

This leads to significant performance gains if all `Vec` items are kept: -40% on my benchmark with unique integers.

Results of benchmarks before implementation (including new benchmark where nothing needs to be removed):
 *   vec::bench_dedup_all_100                 74.00ns/iter  +/- 13.00ns
 *   vec::bench_dedup_all_1000               572.00ns/iter +/- 272.00ns
 *   vec::bench_dedup_all_100000              64.42µs/iter  +/- 19.47µs
 *   __vec::bench_dedup_none_100                67.00ns/iter  +/- 17.00ns__
 *   __vec::bench_dedup_none_1000              662.00ns/iter  +/- 86.00ns__
 *   __vec::bench_dedup_none_10000               9.16µs/iter   +/- 2.71µs__
 *   __vec::bench_dedup_none_100000             91.25µs/iter   +/- 1.82µs__
 *   vec::bench_dedup_random_100             105.00ns/iter  +/- 11.00ns
 *   vec::bench_dedup_random_1000            781.00ns/iter  +/- 10.00ns
 *   vec::bench_dedup_random_10000             9.00µs/iter   +/- 5.62µs
 *   vec::bench_dedup_random_100000          449.81µs/iter  +/- 74.99µs
 *   vec::bench_dedup_slice_truncate_100     105.00ns/iter  +/- 16.00ns
 *   vec::bench_dedup_slice_truncate_1000      2.65µs/iter +/- 481.00ns
 *   vec::bench_dedup_slice_truncate_10000    18.33µs/iter   +/- 5.23µs
 *   vec::bench_dedup_slice_truncate_100000  501.12µs/iter  +/- 46.97µs

Results after implementation:
 *   vec::bench_dedup_all_100                 75.00ns/iter   +/- 9.00ns
 *   vec::bench_dedup_all_1000               494.00ns/iter +/- 117.00ns
 *   vec::bench_dedup_all_100000              58.13µs/iter   +/- 8.78µs
 *   __vec::bench_dedup_none_100                52.00ns/iter  +/- 22.00ns__
 *   __vec::bench_dedup_none_1000              417.00ns/iter +/- 116.00ns__
 *   __vec::bench_dedup_none_10000               4.11µs/iter +/- 546.00ns__
 *   __vec::bench_dedup_none_100000             40.47µs/iter   +/- 5.36µs__
 *   vec::bench_dedup_random_100              77.00ns/iter  +/- 15.00ns
 *   vec::bench_dedup_random_1000            681.00ns/iter  +/- 86.00ns
 *   vec::bench_dedup_random_10000            11.66µs/iter   +/- 2.22µs
 *   vec::bench_dedup_random_100000          469.35µs/iter  +/- 20.53µs
 *   vec::bench_dedup_slice_truncate_100     100.00ns/iter   +/- 5.00ns
 *   vec::bench_dedup_slice_truncate_1000      2.55µs/iter +/- 224.00ns
 *   vec::bench_dedup_slice_truncate_10000    18.95µs/iter   +/- 2.59µs
 *   vec::bench_dedup_slice_truncate_100000  492.85µs/iter  +/- 72.84µs

Resolves #77772

P.S. Note that this is same PR as #92104 I just missed review then forgot about it.
Also, I cannot reopen that pull request so I am creating a new one.
I responded to remaining questions directly by adding commentaries to my code.
2023-12-05 21:40:02 +00:00
AngelicosPhosphoros 964df019d2 Split `Vec::dedup_by` into 2 cycles
First cycle runs until we found 2 same elements, second runs after if there any found in the first one. This allows to avoid any memory writes until we found an item which we want to remove.

This leads to significant performance gains if all `Vec` items are kept: -40% on my benchmark with unique integers.

Results of benchmarks before implementation (including new benchmark where nothing needs to be removed):
 *   vec::bench_dedup_all_100                 74.00ns/iter  +/- 13.00ns
 *   vec::bench_dedup_all_1000               572.00ns/iter +/- 272.00ns
 *   vec::bench_dedup_all_100000              64.42µs/iter  +/- 19.47µs
 *   __vec::bench_dedup_none_100                67.00ns/iter  +/- 17.00ns__
 *   __vec::bench_dedup_none_1000              662.00ns/iter  +/- 86.00ns__
 *   __vec::bench_dedup_none_10000               9.16µs/iter   +/- 2.71µs__
 *   __vec::bench_dedup_none_100000             91.25µs/iter   +/- 1.82µs__
 *   vec::bench_dedup_random_100             105.00ns/iter  +/- 11.00ns
 *   vec::bench_dedup_random_1000            781.00ns/iter  +/- 10.00ns
 *   vec::bench_dedup_random_10000             9.00µs/iter   +/- 5.62µs
 *   vec::bench_dedup_random_100000          449.81µs/iter  +/- 74.99µs
 *   vec::bench_dedup_slice_truncate_100     105.00ns/iter  +/- 16.00ns
 *   vec::bench_dedup_slice_truncate_1000      2.65µs/iter +/- 481.00ns
 *   vec::bench_dedup_slice_truncate_10000    18.33µs/iter   +/- 5.23µs
 *   vec::bench_dedup_slice_truncate_100000  501.12µs/iter  +/- 46.97µs

Results after implementation:
 *   vec::bench_dedup_all_100                 75.00ns/iter   +/- 9.00ns
 *   vec::bench_dedup_all_1000               494.00ns/iter +/- 117.00ns
 *   vec::bench_dedup_all_100000              58.13µs/iter   +/- 8.78µs
 *   __vec::bench_dedup_none_100                52.00ns/iter  +/- 22.00ns__
 *   __vec::bench_dedup_none_1000              417.00ns/iter +/- 116.00ns__
 *   __vec::bench_dedup_none_10000               4.11µs/iter +/- 546.00ns__
 *   __vec::bench_dedup_none_100000             40.47µs/iter   +/- 5.36µs__
 *   vec::bench_dedup_random_100              77.00ns/iter  +/- 15.00ns
 *   vec::bench_dedup_random_1000            681.00ns/iter  +/- 86.00ns
 *   vec::bench_dedup_random_10000            11.66µs/iter   +/- 2.22µs
 *   vec::bench_dedup_random_100000          469.35µs/iter  +/- 20.53µs
 *   vec::bench_dedup_slice_truncate_100     100.00ns/iter   +/- 5.00ns
 *   vec::bench_dedup_slice_truncate_1000      2.55µs/iter +/- 224.00ns
 *   vec::bench_dedup_slice_truncate_10000    18.95µs/iter   +/- 2.59µs
 *   vec::bench_dedup_slice_truncate_100000  492.85µs/iter  +/- 72.84µs

Resolves #77772
2023-12-05 21:01:00 +01:00
Michael Goulet 6fa93e83c9
Rollup merge of #118450 - marcin-serwin:master, r=workingjubilee
Use OnceCell in cell module documentation

The spanning tree example in the std cell module implementation was created before `OnceCell` was added to Rust so it uses `RefCell`. However, in this case using `OnceCell` seems more appropriate and produces simpler code. As a bonus, this also means that all three cell types are presented in the examples of std cell module.
2023-12-05 14:52:43 -05:00
Michael Goulet aa5f25174d
Rollup merge of #118350 - DaniPopes:tuple-default, r=workingjubilee
Simplify Default for tuples

Doesn't need a separate block for each element
2023-12-05 14:52:43 -05:00
Michael Goulet 19bf749560
Rollup merge of #118123 - RalfJung:internal-lib-features, r=compiler-errors
Add support for making lib features internal

We have the notion of an "internal" lang feature: a feature that is never intended to be stabilized, and using which can cause ICEs and other issues without that being considered a bug.

This extends that idea to lib features as well. It is an alternative to https://github.com/rust-lang/rust/pull/115623: instead of using an attribute to declare lib features internal, we simply do this based on the name. Everything ending in `_internals` or `_internal` is considered internal.

Then we rename `core_intrinsics` to `core_intrinsics_internal`, which fixes https://github.com/rust-lang/rust/issues/115597.
2023-12-05 14:52:41 -05:00
Michael Goulet 2d2a76d411
Rollup merge of #117793 - wdunicornpro:patch-1, r=workingjubilee
Update variable name to fix `unused_variables` warning

This PR fixes an `unused_variables` warning within `os.rs` when targeting `espidf`.
2023-12-05 14:52:40 -05:00
Trevor Gross b225aab5ef Stabilize `type_name_of_val`
Make the following API stable:

    // in core::any
    pub fn type_name_of_val<T: ?Sized>(_val: &T) -> &'static str

Const stability is not added because this relies on `type_name` which is also
not const. That has a blocking issue.

Fixes #66359
2023-12-05 14:49:09 -05:00
The 8472 13a843ebcb Fix in-place collect not reallocating when necessary 2023-12-05 20:09:22 +01:00
bors 154f645d76 Auto merge of #118362 - RalfJung:panic_nounwind, r=thomcc
make sure panic_nounwind_fmt can still be fully inlined (e.g. for panic_immediate_abort)

Follow-up to https://github.com/rust-lang/rust/pull/110303.
2023-12-05 12:05:22 +00:00
Guillaume Gomez 89ed7fc040
Rollup merge of #118591 - RalfJung:portable-simd-build-fix, r=workingjubilee,calebzulawski
portable-simd: fix test suite build

``@workingjubilee`` ``@calebzulawski`` don't we run these portable-simd tests on rustc CI? Currently they don't even build here.
2023-12-04 20:46:10 +01:00
Ralf Jung bcfeaabaf3 portable-simd: add missing feature gate 2023-12-04 08:16:03 +01:00
Gurinder Singh 423481ba54 Improve example in `slice::windows()` doc
Now using a window of 3 instead 2 because it removes any
confusion about exactly how consecutive windows overlap
2023-12-04 11:17:42 +05:30
bors 85a4bd8f58 Auto merge of #116915 - bend-n:unwet, r=saethlin
Add an assume that the index is inbounds to slice::get_unchecked

Fixes #116878
2023-12-04 03:09:45 +00:00
bendn 73afc00cf9
use `assume(idx < self.len())` in `[T]::get_unchecked` 2023-12-04 06:00:12 +07:00
Ralf Jung 2a3fcc0a57 move calling miri_promise_symbolic_alignment to a shared helper 2023-12-03 21:51:14 +01:00
Ralf Jung bebba4f6e0 miri: support 'promising' alignment for symbolic alignment check 2023-12-03 21:51:14 +01:00
klensy c0134887d2 library: use c string literals 2023-12-03 14:54:09 +03:00
bors 71940e0a8a Auto merge of #118487 - RalfJung:exposed-provenance, r=thomcc
move exposed-provenance APIs into separate feature gate

We have already stated explicitly for all the 'exposed' functions that

> Using this method means that code is *not* following strict provenance rules.

However, they were part of the same feature gate and still described as part of the strict provenance experiment. Unfortunately, their semantics are much less clear and certainly nowhere near stabilization, so in preparation for an attempt to stabilize the strict provenance APIs, I suggest we split the things related to "exposed" into their own feature gate. I also used this opportunity to better explain how Exposed Provenance fits into the larger plan here: this is *one possible candidate* for `as` semantics, but we don't know if it is actually viable, so we can't really promise that it is equivalent to `as`. If it works out we probably want to make `as` equivalent to the 'exposed' APIs; if it doesn't, we will remove them again and try to find some other semantics for `as`.
2023-12-03 07:04:12 +00:00
bors 2f1ba4a0af Auto merge of #118128 - RalfJung:bad-intrinsics, r=the8472
warn against using intrinsics that leave the scope of our memory model
2023-12-03 05:03:12 +00:00
bors d5fab33766 Auto merge of #118484 - blyxxyz:os-str-slice, r=BurntSushi
Add substring API for `OsStr`

This adds a method for taking a substring of an `OsStr`, which in combination with [`OsStr::as_encoded_bytes()`](https://doc.rust-lang.org/std/ffi/struct.OsStr.html#method.as_encoded_bytes) makes it possible to implement most string operations in safe code.

API:
```rust
impl OsStr {
    pub fn slice_encoded_bytes<R: ops::RangeBounds<usize>>(&self, range: R) -> &Self;
}
```
Motivation, examples and research at https://github.com/rust-lang/libs-team/issues/306.

Tracking issue: #118485

cc `@epage`
r? libs-api
2023-12-02 20:02:15 +00:00
Alex Crichton 672ea93652 std: Invert logic for inclusion of `sys_common::net`
The `library/std/src/sys_common/net.rs` module is intended to define
common implementations of networking-related APIs across a variety of
platforms that share similar APIs (e.g. Berkeley-style sockets and all).
This module is not included for more fringe targets however such as UEFI
or "unknown" targets to libstd (those classified as `restricted-std`).
Previously the `sys_common/net.rs` file was set up such that an
allow-list indicated it shouldn't be used. This commit inverts the logic
to have an allow-list of when it should be used instead.

The goal of this commit is to make it a bit easier to experiment with a
new Rust target. Currently more esoteric targets are required to get an
exception in this `cfg_if` block to use `crate::sys::net` such as for
unsupported targets. With this inversion of logic only targets which
actually support networking will be listed, where most of those are
lumped under `cfg(unix)`.

Given that this change is likely to cause some breakage for some target
by accident I've attempted to be somewhat robust with this by following
these steps to defining the new predicate for inverted logic.

1. Take all supported targets and filter out all `cfg(unix)` ones as
   these should all support `sys_common/net.rs`.
2. Take remaining targets and filter out `cfg(windows)` ones.
3. The remaining dozen-or-so targets were all audited by hand. Mostly
   this included `target_os = "hermit"` and `target_os = "solid_asp3"`
   which required an allow-list entry, but remaining targets were all
   already excluded (didn't use `sys_common/net.rs` so they were left
   out.

If this causes breakage it should be relatively easy to fix and I'd be
happy to follow-up with any PRs necessary.
2023-12-02 11:38:32 -08:00