Commit Graph

13915 Commits

Author SHA1 Message Date
bors
96561a8fd1 Auto merge of #121428 - okaneco:ipaddr_parse, r=cuviper
net: Don't use checked arithmetic when parsing numbers with known max digits

Add a branch to `Parser::read_number` that determines whether checked or regular arithmetic is used.

- If `max_digits.is_some()`, then we know we are parsing a `u8` or `u16` because `read_number` is only called with `Some(3)` or `Some(4)`. Both types fit within a `u32` without risk of overflow. Thus, we can use plain arithmetic to avoid extra instructions from `checked_mul` and `checked_add`.

Add benches for `IpAddr`, `Ipv4Addr`, `Ipv6Addr`, `SocketAddr`, `SocketAddrV4`, and `SocketAddrV6` parsing
2024-03-05 15:29:19 +00:00
bors
bdde2a80ae Auto merge of #121138 - Swatinem:grapheme-extend-ascii, r=cuviper
Add ASCII fast-path for `char::is_grapheme_extended`

I discovered that `impl Debug for str` is quite slow because it ends up doing a `unicode_data::grapheme_extend::lookup` for each char, which ends up doing a binary search.

This introduces a fast-path for ASCII chars which do not have this property.

The `lookup` is thus completely gone from profiles.

---

As a followup, maybe it’s worth implementing this fast path directly in `unicode_data` so that it can check for the lower bound directly before going to a potentially expensive binary search.
2024-03-05 10:28:55 +00:00
bors
41d97c8a5d Auto merge of #122012 - matthiaskrgr:rollup-bzqjj2n, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #121213 (Add an example to demonstrate how Rc::into_inner works)
 - #121262 (Add vector time complexity)
 - #121287 (Clarify/add `must_use` message for Rc/Arc/Weak::into_raw.)
 - #121664 (Adjust error `yield`/`await` lowering)
 - #121826 (Use root obligation on E0277 for some cases)
 - #121838 (Use the correct logic for nested impl trait in assoc types)
 - #121913 (Don't panic when waiting on poisoned queries)
 - #121987 (pattern analysis: abort on arity mismatch)
 - #121993 (Avoid using unnecessary queries when printing the query stack in panics)
 - #121997 (interpret/cast: make more matches on FloatTy properly exhaustive)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-03-05 08:02:07 +00:00
Matthias Krüger
35f6eee51a
Rollup merge of #121826 - estebank:e0277-root-obligation-2, r=oli-obk
Use root obligation on E0277 for some cases

When encountering trait bound errors that satisfy some heuristics that tell us that the relevant trait for the user comes from the root obligation and not the current obligation, we use the root predicate for the main message.

This allows to talk about "X doesn't implement Pattern<'_>" over the most specific case that just happened to fail, like  "char doesn't implement Fn(&mut char)" in
`tests/ui/traits/suggest-dereferences/root-obligation.rs`

The heuristics are:

 - the type of the leaf predicate is (roughly) the same as the type from the root predicate, as a proxy for "we care about the root"
 - the leaf trait and the root trait are different, so as to avoid talking about `&mut T: Trait` and instead remain talking about `T: Trait` instead
 - the root trait is not `Unsize`, as to avoid talking about it in `tests/ui/coercion/coerce-issue-49593-box-never.rs`.

```
error[E0277]: the trait bound `&char: Pattern<'_>` is not satisfied
  --> $DIR/root-obligation.rs:6:38
   |
LL |         .filter(|c| "aeiou".contains(c))
   |                             -------- ^ the trait `Fn<(char,)>` is not implemented for `&char`, which is required by `&char: Pattern<'_>`
   |                             |
   |                             required by a bound introduced by this call
   |
   = note: required for `&char` to implement `FnOnce<(char,)>`
   = note: required for `&char` to implement `Pattern<'_>`
note: required by a bound in `core::str::<impl str>::contains`
  --> $SRC_DIR/core/src/str/mod.rs:LL:COL
help: consider dereferencing here
   |
LL |         .filter(|c| "aeiou".contains(*c))
   |                                      +
```

Fix #79359, fix #119983, fix #118779, cc #118415 (the suggestion needs to change), cc #121398 (doesn't fix the underlying issue).
2024-03-05 06:40:31 +01:00
Matthias Krüger
72651306b3
Rollup merge of #121287 - zachs18:rc-into-raw-must-use, r=cuviper
Clarify/add `must_use` message for Rc/Arc/Weak::into_raw.

The current `#[must_use]` messages for `{sync,rc}::Weak::into_raw` ("`self` will be dropped if the result is not used") are misleading, as `self` is consumed and will *not* be dropped.

This PR changes their `#[must_use]` message to the same as `Arc::into_raw`'s[ current `#[must_use]` message](d573564575/library/alloc/src/sync.rs (L1482)) ("losing the pointer will leak memory"), and also adds it to `Rc::into_raw`, which is not currently `#[must_use]`.
2024-03-05 06:40:30 +01:00
Matthias Krüger
22827fd5b1
Rollup merge of #121262 - 20jasper:add-vector-time-complexity, r=cuviper
Add vector time complexity

Added time complexity for `Vec` methods `push`, `push_within_capacity`, `pop`, and `insert`.

<details>

<summary> Reference images </summary>

![`Vec::push` documentation](https://github.com/rust-lang/rust/assets/78604367/dc966bbd-e92e-45a6-af82-35afabfa79a9)

![`Vec::push_within_capacity` documentation](https://github.com/rust-lang/rust/assets/78604367/9aadaf48-46ed-4fad-bdd5-74b98a61f4bb)

![`Vec::pop` documentation](https://github.com/rust-lang/rust/assets/78604367/88ec0389-a346-4ea5-a3b7-17caf514dd8b)

![`Vec::insert` documentation](https://github.com/rust-lang/rust/assets/78604367/960c15c3-ef8e-4aa7-badc-35ce80f6f221)

</details>

I followed a convention to use `#Time complexity` that I found in [the `BinaryHeap` documentation](https://doc.rust-lang.org/std/collections/struct.BinaryHeap.html#time-complexity-1). Looking through the rest of standard library collections, there is not a consistent way to handle this.

[`Vec::swap_remove`](https://doc.rust-lang.org/std/vec/struct.Vec.html#method.swap_remove) does not have a dedicated section for time complexity but does list it.

[`VecDeque::rotate_left`](https://doc.rust-lang.org/std/collections/struct.VecDeque.html#complexity) uses a `#complexity` heading.
2024-03-05 06:40:29 +01:00
Matthias Krüger
c2f6c0b806
Rollup merge of #121213 - Takashiidobe:takashi/example-for-rc-into-inner, r=cuviper
Add an example to demonstrate how Rc::into_inner works

This PR adds an example to Rc::into_inner, since it didn't have one previously.
2024-03-05 06:40:29 +01:00
bors
5a1e5449c8 Auto merge of #121001 - nyurik:optimize-core-fmt, r=cuviper
perf: improve write_fmt to handle simple strings

In case format string has no arguments, simplify its implementation with a direct call to `output.write_str(value)`. This builds on `@dtolnay` original [suggestion](https://github.com/serde-rs/serde/pull/2697#issuecomment-1940376414). This does not change any expectations because the original `fn write()` implementation calls `write_str` for parts of the format string.

```rust
write!(f, "text")  ->  f.write_str("text")
```

```diff
 /// [`write!`]: crate::write!
+#[inline]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub fn write(output: &mut dyn Write, args: Arguments<'_>) -> Result {
+    if let Some(s) = args.as_str() { output.write_str(s) } else { write_internal(output, args) }
+}
+
+/// Actual implementation of the [`write`], but without the simple string optimization.
+fn write_internal(output: &mut dyn Write, args: Arguments<'_>) -> Result {
     let mut formatter = Formatter::new(output);
     let mut idx = 0;
```

* Hopefully it will improve the simple case for the https://github.com/rust-lang/rust/issues/99012
* Another related (original?) issues #10761
* Previous similar attempt to fix it by by `@Kobzol` #100700

CC: `@m-ou-se` as probably the biggest expert in everything `format!`
2024-03-05 05:33:17 +00:00
bors
2eeff462b7 Auto merge of #120675 - oli-obk:intrinsics3.0, r=pnkfelix
Add a scheme for moving away from `extern "rust-intrinsic"` entirely

All `rust-intrinsic`s can become free functions now, either with a fallback body, or with a dummy body and an attribute, requiring backends to actually implement the intrinsic.

This PR demonstrates the dummy-body scheme with the `vtable_size` intrinsic.

cc https://github.com/rust-lang/rust/issues/63585

follow-up to #120500

MCP at https://github.com/rust-lang/compiler-team/issues/720
2024-03-05 00:13:01 +00:00
okaneco
69637c9212 Add benches for net parsing
Add benches for IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4,
and SocketAddrV6 parsing
2024-03-04 18:46:24 -05:00
okaneco
31c758e052 net: Add branch to Parser::read_number for parsing without checked
arithmetic

If `max_digits.is_some()`, then we know we are parsing a `u8` or `u16`
because `read_number` is only called with `Some(3)` or `Some(4)`. Both
types fit well within a `u32` without risk of overflow. Thus, we can use
plain arithmetic to avoid extra instructions from `checked_mul` and
`checked_add`.
2024-03-04 18:46:09 -05:00
Matthias Krüger
c83ca5ba9a
Rollup merge of #121977 - Lee-Janggun:master, r=WaffleLapkin
Doc: Fix incorrect reference to integer in Atomic{Ptr,Bool}::as_ptr.

I am assuming "resulting integer" is an error, since we are talking about pointers and booleans here. Seems like it was missed while copy & pasting the docs from the integer versions. I also checked the rest of the docs, and this was the only mention of integers.
2024-03-04 22:16:34 +01:00
Matthias Krüger
4944ab449a
Rollup merge of #121968 - roblabla:fix-win7, r=jhpratt
Don't run test_get_os_named_thread on win7

This test won't work on windows 7, as the Thread::set_name function is not implemented there (win7 does not provide a documented mechanism to set thread names).
2024-03-04 22:16:33 +01:00
Matthias Krüger
9d81d4e46b
Rollup merge of #121939 - jonaspleyer:patch-typo-core-From-descr, r=workingjubilee
Small enhancement to description of From trait

- fix small typo
- avoid repetition of formulations
2024-03-04 22:16:32 +01:00
Matthias Krüger
008ab3387b
Rollup merge of #121732 - Voultapher:improve-assert_matches-documentation, r=cuviper
Improve assert_matches! documentation

This new documentation tries to limit the impact of the conceptual pitfall, that the if guard relaxes the constraint, when really it tightens it. This is achieved by changing the text and examples. The previous documentation also chose a rather weird and non-representative example for the if guard, that made it needlessly complicated to understand.
2024-03-04 22:16:31 +01:00
Matthias Krüger
706fe0b7d8
Rollup merge of #120976 - matthiaskrgr:constify_TL_statics, r=lcnr
constify a couple thread_local statics
2024-03-04 22:16:30 +01:00
Oli Scherer
1e57df1969 Add a scheme for moving away from extern "rust-intrinsic" entirely 2024-03-04 16:13:50 +00:00
Janggun Lee
05e68facbb
Fix comment in Atomic{Ptr,Bool}::as_ptr. 2024-03-04 22:15:05 +09:00
Jonas Pleyer
e46306043b
include feedback from workingjubilee
- Refer to trait directly
- small typo in encapsulate

Co-authored-by: Jubilee <46493976+workingjubilee@users.noreply.github.com>
2024-03-04 10:04:46 +01:00
roblabla
9eb927e025 Don't run test_get_os_named_thread on win7
This test won't work on windows 7, as the Thread::set_name function is
not implemented there (win7 does not provide a documented mechanism to
set thread names).
2024-03-04 09:24:41 +01:00
Matthias Krüger
dc8b71ae2b
Rollup merge of #121935 - RalfJung:ptr-without-prov, r=scottmcm
library/ptr: mention that ptr::without_provenance is equivalent to deriving from the null ptr

This might help clarify why you can't do memory accesses with it.
2024-03-03 22:56:14 +01:00
Esteban Küber
89a3c19832 Be more lax in .into_iter() suggestion when encountering Iterator methods on non-Iterator
```
error[E0599]: no method named `map` found for struct `Vec<bool>` in the current scope
  --> $DIR/vec-on-unimplemented.rs:3:23
   |
LL |     vec![true, false].map(|v| !v).collect::<Vec<_>>();
   |                       ^^^ `Vec<bool>` is not an iterator
   |
help: call `.into_iter()` first
   |
LL |     vec![true, false].into_iter().map(|v| !v).collect::<Vec<_>>();
   |                       ++++++++++++
```

We used to provide some help through `rustc_on_unimplemented` on non-`impl Trait` and non-type-params, but this lets us get rid of some otherwise unnecessary conditions in the annotation on `Iterator`.
2024-03-03 18:53:36 +00:00
Esteban Küber
f0c93117ed Use root obligation on E0277 for some cases
When encountering trait bound errors that satisfy some heuristics that
tell us that the relevant trait for the user comes from the root
obligation and not the current obligation, we use the root predicate for
the main message.

This allows to talk about "X doesn't implement Pattern<'_>" over the
most specific case that just happened to fail, like  "char doesn't
implement Fn(&mut char)" in
`tests/ui/traits/suggest-dereferences/root-obligation.rs`

The heuristics are:

 - the type of the leaf predicate is (roughly) the same as the type
   from the root predicate, as a proxy for "we care about the root"
 - the leaf trait and the root trait are different, so as to avoid
   talking about `&mut T: Trait` and instead remain talking about
   `T: Trait` instead
 - the root trait is not `Unsize`, as to avoid talking about it in
   `tests/ui/coercion/coerce-issue-49593-box-never.rs`.

```
error[E0277]: the trait bound `&char: Pattern<'_>` is not satisfied
  --> $DIR/root-obligation.rs:6:38
   |
LL |         .filter(|c| "aeiou".contains(c))
   |                             -------- ^ the trait `Fn<(char,)>` is not implemented for `&char`, which is required by `&char: Pattern<'_>`
   |                             |
   |                             required by a bound introduced by this call
   |
   = note: required for `&char` to implement `FnOnce<(char,)>`
   = note: required for `&char` to implement `Pattern<'_>`
note: required by a bound in `core::str::<impl str>::contains`
  --> $SRC_DIR/core/src/str/mod.rs:LL:COL
help: consider dereferencing here
   |
LL |         .filter(|c| "aeiou".contains(*c))
   |                                      +
```

Fix #79359, fix #119983, fix #118779, cc #118415 (the suggestion needs
to change).
2024-03-03 18:53:35 +00:00
Lukas Bergdoll
c45f0a977a
Apply suggestions from code review
Co-authored-by: Josh Stone <cuviper@gmail.com>
2024-03-03 15:30:46 +01:00
Jonas Pleyer
fb2b918866 Small enhancement to description of From trait
- fix small typo
- avoid repetition of formulations
2024-03-03 15:29:09 +01:00
Ralf Jung
d579caf384 library/ptr: mention that ptr::without_provenance is equivalent to deriving from the null ptr 2024-03-03 12:34:38 +01:00
Ian Neumann
eb5328b721 Add missing get_name for wasm::thread. 2024-03-03 00:25:51 -08:00
bors
3793e5ba23 Auto merge of #121856 - ChrisDenton:abort, r=joboet
Cleanup windows `abort_internal`

As the comments on the functions say, we define abort in both in panic_abort and in libstd. This PR makes the two implementation (mostly) the same.

Additionally it:
* uses `options(noreturn)` on the asm instead of using `core::intrinsics::unreachable`.
* removed unnecessary allow lints
* added `FAST_FAIL_FATAL_APP_EXIT` to our generated Windows API bindings instead of defining it manually (std only)
2024-03-03 04:26:34 +00:00
bors
0decdac390 Auto merge of #121914 - Nadrieril:rollup-ol98ncg, r=Nadrieril
Rollup of 5 pull requests

Successful merges:

 - #120761 (Add initial support for DataFlowSanitizer)
 - #121622 (Preserve same vtable pointer when cloning raw waker, to fix Waker::will_wake)
 - #121716 (match lowering: Lower bindings in a predictable order)
 - #121731 (Now that inlining, mir validation and const eval all use reveal-all, we won't be constraining hidden types here anymore)
 - #121841 (`f16` and `f128` step 2: intrinsics)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-03-02 22:59:19 +00:00
Guillaume Boisseau
b0ca9b5d44
Rollup merge of #121622 - dtolnay:wake, r=cuviper
Preserve same vtable pointer when cloning raw waker, to fix Waker::will_wake

Fixes #121600.

As `@jkarneges` identified in https://github.com/rust-lang/rust/issues/121600#issuecomment-1963041051, the issue is two different const promotions produce two statics at different addresses, which may or may not later be deduplicated by the linker (in this case not).

Prior to #119863, the content of the statics was compared, and they were equal. After, the address of the statics are compared and they are not equal.

It is documented that `will_wake` _"works on a best-effort basis, and may return false even when the Wakers would awaken the same task"_ so this PR fixes a quality-of-implementation issue, not a correctness issue.
2024-03-02 20:13:22 +01:00
Chris Denton
ce26c78820
Cleanup windows abort_internal 2024-03-02 18:22:15 +00:00
Matthias Krüger
5b66e008e0
Rollup merge of #121888 - cppcoffee:style, r=Nilstrieb
style library/core/src/error.rs

Add an extra blank line for clarity in distinguishing implementations.
2024-03-02 16:53:16 +01:00
Matthias Krüger
3e59b7834a
Rollup merge of #121759 - RalfJung:addr_of, r=the8472
attempt to further clarify addr_of docs
2024-03-02 16:53:15 +01:00
Matthias Krüger
2f72206b4c
Rollup merge of #121758 - joboet:move_pal_thread_local, r=ChrisDenton
Move thread local implementation to `sys`

Part of #117276.
2024-03-02 16:53:14 +01:00
Matthias Krüger
0f544f280a
Rollup merge of #121666 - ChrisDenton:thread-name, r=cuviper
Use the OS thread name by default if `THREAD_INFO` has not been initialized

Currently if `THREAD_INFO` hasn't been initialized then the name will be set to `None`.  This PR changes it to use the OS thread name by default. This mostly affects foreign threads at the moment but we could expand this to make more use of the OS thread name in the future.

Note: I've only implemented `Thread::get_name` for windows, linux and macos (and macos adjacent) targets. The rest just return `None`.
2024-03-02 16:53:14 +01:00
Lukas Bergdoll
d6438f5266 Apply review comments 2024-03-02 14:07:25 +01:00
Ralf Jung
ec5e2dc241 attempt to further clarify addr_of docs 2024-03-02 10:12:02 +01:00
Matthias Krüger
c95f485744
Rollup merge of #121861 - tbu-:pr_floating_point_exact_examples, r=workingjubilee
Use the guaranteed precision of a couple of float functions in docs
2024-03-02 10:09:37 +01:00
Matthias Krüger
78249a6790
Rollup merge of #121847 - shamatar:btreemap_fix_implicits, r=cuviper
Remove hidden use of Global

Fixes #121797
2024-03-02 10:09:37 +01:00
Matthias Krüger
4f3d7e2d11
Rollup merge of #121835 - nnethercote:mv-HandleStore, r=bjorn3
Move `HandleStore` into `server.rs`.

This just moves the server-relevant parts of handles into `server.rs`. It introduces a new higher-order macro `with_api_handle_types` to avoid some duplication.

This fixes two `FIXME` comments, and makes things clearer, by not having server code in `client.rs`.

r? ```@bjorn3```
2024-03-02 10:09:36 +01:00
Matthias Krüger
d0e5431eb0
Rollup merge of #109263 - squell:master, r=cuviper
fix typo in documentation for std::fs::Permissions

Please check and re-check this PR carefully to see if I got this right.

But by my logic, if the `read_only` function returns `true`, I would not expect be able to write to the file (it being read only); so this text is meant to clarify that `read_only` being `false` doesn't mean *you* can actually write to the file, just that "in general" someone is able to.
2024-03-02 10:09:34 +01:00
Xiaobo Liu
624f9d3c78
style library/core/src/error.rs 2024-03-02 16:03:23 +08:00
Matthias Krüger
4f32f78fc6
Rollup merge of #121730 - ecnelises:aix_pgo, r=wesleywiser
Add profiling support to AIX

AIX ld needs special option to merge objects with profiling. Also, profiler_builtins should include builtins for AIX from compiler-rt.
2024-03-01 22:38:48 +01:00
Matthias Krüger
441217d9b5
Rollup merge of #121634 - RavuAlHemio:slice-prefix-suffix-docs, r=cuviper
Clarify behavior of slice prefix/suffix operations in case of equality

Operations such as starts_with, ends_with, strip_prefix and strip_suffix can be either strict (do not consider a slice to be a prefix/suffix of itself) or not. In Rust's case, they are not strict. Add a few phrases to the documentation to clarify this.
2024-03-01 22:38:47 +01:00
Chris Denton
6cb0c404b3
Add get_name placeholder to other targets 2024-03-01 16:38:02 -03:00
Tobias Bucher
bcccab88ca Use the guaranteed precision of a couple of float functions in docs 2024-03-01 18:57:42 +01:00
Matthias Krüger
68dd5e65a9
Rollup merge of #121850 - reitermarkus:generic-nonzero-unsafe-trait, r=Nilstrieb
Make `ZeroablePrimitive` trait unsafe.

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

r? `@dtolnay`
2024-03-01 17:51:33 +01:00
Matthias Krüger
90ca049320
Rollup merge of #121736 - HTGAzureX1212:HTGAzureX1212/remove-mutex-unlock, r=jhpratt
Remove `Mutex::unlock` Function

As of the completion of the FCP in https://github.com/rust-lang/rust/issues/81872#issuecomment-1474104525, it has come to the conclusion to be closed.

This PR removes the function entirely in light of the above.

Closes #81872.
2024-03-01 17:51:30 +01:00
Markus Reiter
f6d2607163
Make ZeroablePrimitive trait unsafe. 2024-03-01 13:49:37 +01:00
Alexander
fb8ac06477 remove hidden use of Global 2024-03-01 11:51:28 +00:00