Commit Graph

5252 Commits

Author SHA1 Message Date
Matthias Krüger
cbe2522652
Rollup merge of #114382 - scottmcm:compare-bytes-intrinsic, r=cjgillot
Add a new `compare_bytes` intrinsic instead of calling `memcmp` directly

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

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

cc `@RalfJung` `@Amanieu`
2023-08-07 05:29:12 +02:00
Matthias Krüger
bab20b410e
Rollup merge of #98935 - kellerkindt:option_retain, r=Mark-Simulacrum
Implement `Option::take_if`

Tracking issue: #98934
ACP: rust-lang/libs-team#70 [accepted]
2023-08-07 05:29:09 +02:00
Scott McMurray
502af03445 Add a new compare_bytes intrinsic instead of calling memcmp directly 2023-08-06 15:47:40 -07:00
bors
eb088b8b9d Auto merge of #111200 - a1phyr:spec_sized_iterators, r=the8472
Optimize `Iterator` implementation for `&mut impl Iterator + Sized`

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

Closes #73480

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

```rust
struct Generate<T>(fn() -> T);
#[automatically_derived]
impl<T: ::core::marker::Copy> ::core::marker::Copy for Generate<T> { }
#[automatically_derived]
impl<T: ::core::clone::Clone> ::core::clone::Clone for Generate<T> {
    #[inline]
    fn clone(&self) -> Generate<T> {
        Generate(::core::clone::Clone::clone(&self.0))
    }
}
```
2023-08-05 14:00:16 +02:00
bors
1fe384649a Auto merge of #108955 - Nilstrieb:dont-use-me-pls, r=oli-obk
Add `internal_features` lint

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

Also requires some more test blessing for codegen tests etc

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

This PR,

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

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

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

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

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

* Better differentiate summaries for `from_bytes_until_nul` and `from_bytes_with_nul`
* Add some links where they may be helpful
2023-08-03 02:40:19 +00:00
bors
d170833431 Auto merge of #112431 - Urgau:cast_ref_to_mut_improvments, r=Nilstrieb
Improve `invalid_reference_casting` lint

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

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

This PR is best reviewed commit by commit.

r? compiler
2023-08-02 11:25:13 +00:00
Trevor Gross
c94dc72a1c Clarify documentation for CStr
* Better differentiate summaries for `from_bytes_until_nul` and
  `from_bytes_with_nul`
* Add some links where they may be helpful
2023-08-02 03:58:51 -04:00
Urgau
0b9529cca3 Add diagnostic items for <*const _>::cast and ptr::from_mut 2023-08-01 20:04:01 +02:00
bors
828bdc2c26 Auto merge of #112849 - m-ou-se:panic-message-format, r=thomcc
Change default panic handler message format.

This changes the default panic hook's message format from:

```
thread '{thread}' panicked at '{message}', {location}
```

to

```
thread '{thread}' panicked at {location}:
{message}
```

This puts the message on its own line without surrounding quotes, making it easiser to read. For example:

Before:
```
thread 'main' panicked at 'env variable `IMPORTANT_PATH` should be set by `wrapper_script.sh`', src/main.rs:4:6
```
After:
```
thread 'main' panicked at src/main.rs:4:6:
env variable `IMPORTANT_PATH` should be set by `wrapper_script.sh`
```

---

See this PR by `@nyurik,` which does that for only multi-line messages (specifically because of `assert_eq`): https://github.com/rust-lang/rust/pull/111071

This is the change that does that for *all* panic messages.
2023-08-01 14:15:09 +00:00
Matthias Krüger
14a5dc52c7
Rollup merge of #111081 - mattfbacon:master, r=workingjubilee
impl SliceIndex<str> for (Bound<usize>, Bound<usize>)

This impl is conspicuously missing.
2023-08-01 06:55:52 +02:00
Matthias Krüger
bcfa49f162
Rollup merge of #109318 - joboet:better_fmt_placeholder, r=dtolnay
Make `Debug` representations of `[Lazy, Once]*[Cell, Lock]` consistent with `Mutex` and `RwLock`

`Mutex` prints `<locked>` as a field value when its inner value cannot be accessed, but the lazy types print a fixed string like "`OnceCell(Uninit)`". This could cause confusion if the inner type is a unit type named `Uninit` and does not respect the pretty-printing flag. With this change, the format message is now "`OnceCell(<uninit>)`", consistent with `Mutex`.
2023-07-31 22:51:12 +02:00
Matt Fellenz
f189d00d40
Work around missing <*str>::len 2023-07-31 11:42:14 -07:00
Matt Fellenz
e12e7fcc50
impl SliceIndex<str> for (Bound<usize>, Bound<usize>) 2023-07-31 11:32:40 -07:00
Matthias Krüger
e3ca397593
Rollup merge of #102198 - lukas-code:nonnull_as_ref, r=Amanieu
`const`-stablilize `NonNull::as_ref`

A bunch of pointer to reference methods have been made unstably const some time ago in #91823 under the feature gate `const_ptr_as_ref`.
Out of these, `NonNull::as_ref` can be implemented as a `const fn` in stable rust today, so i hereby propose to const stabilize this function only.

Tracking issue: #91822

``@rustbot`` label +T-libs-api -T-libs
2023-07-30 20:36:34 +02:00
Martin Nordholts
c6566a8037 Explain more clearly why fn() -> T can't be #[derive(Clone)] 2023-07-30 18:04:38 +02:00
Matthias Krüger
e3bf088fb5
Rollup merge of #112655 - WaffleLapkin:must_use_map_or, r=workingjubilee
Mark `map_or` as `#[must_use]`

I don't know what else to say.

r? libs
2023-07-30 14:25:08 +02:00
Maybe Waffle
90f9640528 Mark map_or as #[must_use] 2023-07-30 10:22:23 +00:00
fee1-dead
b97da75156
Rollup merge of #113512 - vallentin:lines-doc, r=workingjubilee
Updated lines doc to include trailing carriage return note

Updated `str::lines` doc to include explicit info about (trailing) carriage returns.

Reference: #100311
2023-07-30 07:13:02 +00:00
Urgau
507d497cfa Adjust some tests for invalid_reference_casting improvements 2023-07-29 12:20:59 +02:00
Mara Bos
0e729404da Change default panic handler message format. 2023-07-29 11:42:50 +02:00
bors
2dc661037d Auto merge of #113099 - bvanjoi:fix-112713-2, r=petrochenkov
fix(resolve): update the ambiguity glob binding as warning recursively

Fixes #47525
Fixes #56593, but `issue-56593-2.rs` is not fixed to ensure backward compatibility.
Fixes #98467
Fixes #105235
Fixes #112713

This PR had added a field called `warn_ambiguous` in `NameBinding` which is only for back compatibly reason and used for lint.

More details: https://github.com/rust-lang/rust/pull/112743

r? `@petrochenkov`
2023-07-29 06:04:41 +00:00
bors
5ed61a4378 Auto merge of #114197 - matthiaskrgr:rollup-iluf7u4, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #113773 (Don't attempt to compute layout of type referencing error)
 - #114107 (Prevent people from assigning me as a PR reviewer)
 - #114124 (tests/ui/proc-macro/*: Migrate FIXMEs to check-pass)
 - #114171 (Fix switch-stdout test for none unix/windows platforms)
 - #114172 (Fix issue_15149 test for the SGX target)
 - #114173 (btree/map.rs: remove "Basic usage" text)
 - #114174 (doc: replace wrong punctuation mark)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-07-29 04:18:46 +00:00
bors
4734ac0943 Auto merge of #111916 - fee1-dead-contrib:noop-method-call-warn, r=compiler-errors
make `noop_method_call` warn by default

r? `@compiler-errors`
2023-07-29 01:40:50 +00:00
bohan
771c832338 library: allow ambiguous_glob_reexports for core_arch 2023-07-29 00:19:59 +08:00
Tshepang Mbambo
0457eda673
doc: replace wrong punctuation mark 2023-07-28 14:46:17 +02:00
Guillaume Gomez
eb1f1a4cc0
Rollup merge of #114109 - veera-sivarajan:fix-str-docs, r=GuillaumeGomez
Docs: Fix URL for `rmatches`

This PR fixes a link to `str::rmatches()` by pointing it to the correct URL.
2023-07-27 16:05:14 +02:00
Guillaume Gomez
ee54896ca1
Rollup merge of #114091 - waywardmonkeys:doc-fmt-finish-comments, r=GuillaumeGomez
docs: fmt::Debug*: Fix comments for finish method.

In the code sample for the `finish` method on `DebugList`, `DebugMap`, and `DebugSet`, refer to finishing the list, map, or set, rather than struct as it did.
2023-07-27 16:05:14 +02:00
bors
e7d6ce3a6f Auto merge of #114034 - Amanieu:riscv-atomicbool, r=thomcc
Optimize `AtomicBool` for target that don't support byte-sized atomics

`AtomicBool` is defined to have the same layout as `bool`, which means that we guarantee that it has a size of 1 byte. However on certain architectures such as RISC-V, LLVM will emulate byte atomics using a masked CAS loop on an aligned word.

We can take advantage of the fact that `bool` only ever has a value of 0 or 1 to replace `swap` operations with `and`/`or` operations that LLVM can lower to word-sized atomic `and`/`or` operations. This takes advantage of the fact that the incoming value to a `swap` or `compare_exchange` for `AtomicBool` is often a compile-time constant.

### Example

```rust
pub fn swap_true(atomic: &AtomicBool) -> bool {
    atomic.swap(true, Ordering::Relaxed)
}
```

### Old

```asm
	andi	a1, a0, -4
	slli	a0, a0, 3
	li	a2, 255
	sllw	a2, a2, a0
	li	a3, 1
	sllw	a3, a3, a0
	slli	a3, a3, 32
	srli	a3, a3, 32
.LBB1_1:
	lr.w	a4, (a1)
	mv	a5, a3
	xor	a5, a5, a4
	and	a5, a5, a2
	xor	a5, a5, a4
	sc.w	a5, a5, (a1)
	bnez	a5, .LBB1_1
	srlw	a0, a4, a0
	andi	a0, a0, 255
	snez	a0, a0
	ret
```

### New

```asm
	andi	a1, a0, -4
	slli	a0, a0, 3
	li	a2, 1
	sllw	a2, a2, a0
	amoor.w	a1, a2, (a1)
	srlw	a0, a1, a0
	andi	a0, a0, 255
	snez	a0, a0
	ret
```
2023-07-27 01:00:12 +00:00
Veera
0169ce968c Fix URL for rmatches 2023-07-26 17:57:56 -05:00
Bruce Mitchener
9f47ff84e3 docs: fmt::Debug*: Fix comments for finish method.
In the code sample for the `finish` method on `DebugList`,
`DebugMap`, and `DebugSet`, refer to finishing the list, map, or
set, rather than struct as it did.
2023-07-26 19:02:26 +07:00
Amanieu d'Antras
3dbee5bc71 Optimize AtomicBool for target that don't support byte-sized atomics
`AtomicBool` is defined to have the same layout as `bool`, which means
that we guarantee that it has a size of 1 byte. However on certain
architectures such as RISC-V, LLVM will emulate byte atomics using a
masked CAS loop on an aligned word.

We can take advantage of the fact that `bool` only ever has a value of 0
or 1 to replace `swap` operations with `and`/`or` operations that LLVM
can lower to word-sized atomic `and`/`or` operations. This takes
advantage of the fact that the incoming value to a `swap` or
`compare_exchange` for `AtomicBool` is often a compile-time constant.
2023-07-26 00:09:49 +01:00
bors
1821920cc8 Auto merge of #111362 - mj10021:issue-74838-update, r=cuviper
delete [allow(unused_unsafe)] from issue #74838

While looking into issue #111288 I noticed the following `#[allow(...)]` with a `FIXME` asking for it to be removed.  Deleting the `#[allow(...)]` does not seem to break anything, it seems like the lint has been updated for unsafe blocks in macros?
2023-07-24 23:20:05 +00:00
James Dietz
db4a153440 remove additional [allow(unused_unsafe)] 2023-07-24 17:56:38 -04:00
Deadbeef
626efab67f fix 2023-07-23 09:58:31 +00:00
Ben Kimock
65e52bb26c Add #[inline] to core debug assertion helpers 2023-07-22 12:07:06 -04:00
bors
8164cdb9ee Auto merge of #113746 - clarfonthey:ip_bits, r=thomcc
Add BITS, from_bits, to_bits to IP addresses

ACP: rust-lang/libs-team#235
Tracking issue: #113744
2023-07-22 13:18:50 +00:00
Matthias Krüger
65b5cba0dd
Rollup merge of #113898 - ajtribick:encode_utf16_size_hint, r=cuviper
Fix size_hint for EncodeUtf16

More realistic upper and lower bounds, and handle the case where the iterator is located within a surrogate pair.

Resolves #113897
2023-07-22 11:48:54 +02:00
Matthias Krüger
58a4be1dfb
Rollup merge of #113252 - tgross35:const-cstr-from-ptr-tracking-issue, r=ChrisDenton
Update the tracking issue for `const_cstr_from_ptr`

Tracking issue #101719 was for `const_cstr_methods`, #113219 is a new issue specific for `const_cstr_from_ptr`.

(I believe #101719 could also be closed)

```@rustbot``` label +T-libs-api +A-docs
2023-07-22 11:48:53 +02:00
Matthias Krüger
6003d6b60b
Rollup merge of #112490 - Alexendoo:c-char-cfg-all, r=cuviper
Remove `#[cfg(all())]` workarounds from `c_char`

Casts to type aliases are now ignored by Clippy https://github.com/rust-lang/rust-clippy/pull/8596

Closes https://github.com/rust-lang/rust-clippy/issues/8093
2023-07-22 11:48:52 +02:00
bors
a5e2eca40e Auto merge of #112699 - bluebear94:mf/more-is-sorted-tests, r=cuviper
Add more comprehensive tests for is_sorted and friends

See #53485 and #55045.
2023-07-21 23:25:04 +00:00
Andrew Tribick
f777339af3 Clarify logic on bytes:code units ratio 2023-07-21 23:49:31 +02:00
bors
d26f0b79d5 Auto merge of #105571 - kadiwa4:remove_atomic_init_consts, r=Amanieu
remove the unstable `core::sync::atomic::ATOMIC_*_INIT` constants

Tracking issue: #99069

It would be weird to ever stabilise these as they are already deprecated.
2023-07-21 01:59:34 +00:00
Andrew Tribick
e6fa5c18b5 Fix size_hint for EncodeUtf16 2023-07-20 21:52:33 +02:00
Scott McMurray
34732e8560 Get !nonnull metadata consistently in slice iterators, without needing assumes 2023-07-20 11:33:49 -07:00
ltdk
b307014d48 Link methods in From impls 2023-07-18 20:58:35 -04:00