Commit Graph

11407 Commits

Author SHA1 Message Date
Dylan DPC
129c559764
Rollup merge of #112141 - anna-singleton:issue-111655-fix, r=thomcc
remove reference to Into in ? operator core/std docs, fix #111655

remove the text stating that `?` uses `Into::into` and add text stating it uses `From::from` instead. This closes #111655.
2023-06-01 11:09:45 +05:30
bors
ba1690bedd Auto merge of #111567 - Urgau:uplift_cast_ref_to_mut, r=b-naber
Uplift `clippy::cast_ref_to_mut` lint

This PR aims at uplifting the `clippy::cast_ref_to_mut` lint into rustc.

## `cast_ref_to_mut`

(deny-by-default)

The `cast_ref_to_mut` lint checks for casts of `&T` to `&mut T` without using interior mutability.

### Example

```rust,compile_fail
fn x(r: &i32) {
    unsafe {
        *(r as *const i32 as *mut i32) += 1;
    }
}
```

### Explanation

Casting `&T` to `&mut T` without interior mutability is undefined behavior, as it's a violation of Rust reference aliasing requirements.

-----

Mostly followed the instructions for uplifting a clippy lint described here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751

`@rustbot` label: +I-lang-nominated
r? compiler

-----

For Clippy:

changelog: Moves: Uplifted `clippy::cast_ref_to_mut` into rustc
2023-06-01 01:27:32 +00:00
anna-singleton
2eeb7693c5 remove reference to Into in ? operator core/std docs, fix 111655 2023-05-31 15:51:28 +01:00
bors
ad8304a0d5 Auto merge of #111076 - notriddle:notriddle/silence-private-dep-trait-impl-suggestions, r=cjgillot
diagnostics: exclude indirect private deps from trait impl suggest

Fixes #88696
2023-05-31 13:47:36 +00:00
Urgau
a51ad131e6 Add diagnostic items for ptr::cast_mut and ptr::from_ref 2023-05-31 12:26:36 +02:00
Matthias Krüger
2054acb0a4
Rollup merge of #112103 - Mark-Simulacrum:bootstrap-update, r=clubby789
Bootstrap update to 1.71 beta

Best reviewed by-commit.
2023-05-31 11:19:09 +02:00
bors
617d3d6d72 Auto merge of #112127 - matthiaskrgr:rollup-77pt893, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #112031 (Migrate  `item_proc_macro` to Askama)
 - #112053 (Remove `-Zcgu-partitioning-strategy`.)
 - #112069 (offset_of: don't require type to be `Sized`)
 - #112084 (enhancements on  build_helper utilization and rustdoc-gui-test)
 - #112096 (Remove array_zip)
 - #112108 (Fix re-export of doc hidden item inside private item not displayed)
 - #112113 (rustdoc: simplify `clean` by removing `FnRetTy`)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-05-31 05:42:26 +00:00
Matthias Krüger
88160ab94c
Rollup merge of #112096 - workingjubilee:array-unzip, r=scottmcm
Remove array_zip

`[T; N]::zip` is "eager" but most zips are mapped. This causes poor optimization in generated code. This is a fundamental design issue and "zip" is "prime real estate" in terms of function names, so let's free it up again.

- FCP concluded in https://github.com/rust-lang/rust/issues/80094#issuecomment-1468300057
- Closes https://github.com/rust-lang/rust/issues/80094
- Closes https://github.com/rust-lang/rust/issues/103555

Could use review to make sure we aren't losing any essential codegen tests.
r? `@scottmcm`
2023-05-31 07:07:02 +02:00
bors
f51fca3af3 Auto merge of #112120 - weihanglo:update-cargo, r=ehuss
Update cargo

17 commits in 64fb38c97ac4d3a327fc9032c862dd28c8833b17..f7b95e31642e09c2b6eabb18ed75007dda6677a0
2023-05-23 18:53:23 +0000 to 2023-05-30 19:25:02 +0000
- chore: detect the channel a PR wants to merge into (rust-lang/cargo#12181)
- refactor: de-depulicate `make_dep_prefix` implementation (rust-lang/cargo#12203)
- Re-enable code_generation test on Windows (rust-lang/cargo#12199)
- docs: add doc comments for git source and friends (rust-lang/cargo#12192)
- test: set retry sleep to 1ms for all tests (rust-lang/cargo#12194)
- fix(add): Reduce the chance we re-format the user's `[features]` table (rust-lang/cargo#12191)
- test(add): Remove expensive test (rust-lang/cargo#12188)
- Add a description of `Cargo.lock` conflicts in the Cargo FAQ (rust-lang/cargo#12185)
- refactor(tests): Reduce cargo-add setup load (rust-lang/cargo#12189)
- Warn when an edition 2021 crate is in a virtual workspace with default resolver (rust-lang/cargo#10910)
- refactor(tests): Reduce cargo-remove setup load (rust-lang/cargo#12184)
- chore: Lexicographically order `-Z` flags (rust-lang/cargo#12182)
- chore(ci): remove temporary fix for rustup 1.24.1 (rust-lang/cargo#12180)
- fix: AIX searches dynamic libraries in `LIBPATH`. (rust-lang/cargo#11968)
- deps: remove unused features from windows-sys (rust-lang/cargo#12176)
- Automatically inherit workspace lints when running cargo new/init (rust-lang/cargo#12174)
- Test that the new `debuginfo` options match between cargo and rustc (rust-lang/cargo#12022)

r? `@ghost`
2023-05-31 03:03:10 +00:00
Weihang Lo
5abff3753a
Explicit set workspace.resolver = "1"
rust-lang/cargo#10910 starts emitting warning if resolver is not set
for 2021 edition package. We want to surpress the warning for now.
2023-05-31 00:08:11 +01:00
bors
9610dfe5a9 Auto merge of #109698 - epage:wtf, r=Amanieu
Allow limited access to `OsStr` bytes

`OsStr` has historically kept its implementation details private out of
concern for locking us into a specific encoding on Windows.

This is an alternative to rust-lang#95290 which proposed specifying the encoding on Windows.  Instead, this
only specifies that for cross-platform code, `OsStr`'s encoding is a superset of UTF-8 and defines
rules for safely interacting with it

At minimum, this can greatly simplify the `os_str_bytes` crate and every
arg parser that interacts with `OsStr` directly (which is most of those
that support invalid UTF-8).

Tracking issue: #111544
2023-05-30 21:26:22 +00:00
Mark Rousskov
42e757192d Bump to latest beta compiler 2023-05-30 08:00:10 -04:00
Mark Rousskov
4f9b394c8a Swap out CURRENT_RUSTC_VERSION to 1.71.0 2023-05-30 07:54:29 -04:00
Nilstrieb
7a4006cc52
Rollup merge of #111543 - Urgau:uplift_invalid_utf8_in_unchecked, r=WaffleLapkin
Uplift `clippy::invalid_utf8_in_unchecked` lint

This PR aims at uplifting the `clippy::invalid_utf8_in_unchecked` lint into two lints.

## `invalid_from_utf8_unchecked`

(deny-by-default)

The `invalid_from_utf8_unchecked` lint checks for calls to `std::str::from_utf8_unchecked` and `std::str::from_utf8_unchecked_mut` with an invalid UTF-8 literal.

### Example

```rust
unsafe {
    std::str::from_utf8_unchecked(b"cl\x82ippy");
}
```

### Explanation

Creating such a `str` would result in undefined behavior as per documentation for `std::str::from_utf8_unchecked` and `std::str::from_utf8_unchecked_mut`.

## `invalid_from_utf8`

(warn-by-default)

The `invalid_from_utf8` lint checks for calls to `std::str::from_utf8` and `std::str::from_utf8_mut` with an invalid UTF-8 literal.

### Example

```rust
std::str::from_utf8(b"ru\x82st");
```

### Explanation

Trying to create such a `str` would always return an error as per documentation for `std::str::from_utf8` and `std::str::from_utf8_mut`.

-----

Mostly followed the instructions for uplifting a clippy lint described here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751

````@rustbot```` label: +I-lang-nominated
r? compiler

-----

For Clippy:

changelog: Moves: Uplifted `clippy::invalid_utf8_in_unchecked` into rustc
2023-05-30 12:57:38 +02:00
Nilstrieb
18c9baf4fe
Rollup merge of #107916 - reez12g:issue-107040, r=Amanieu
fix comment on Allocator trait

fixes https://github.com/rust-lang/rust/issues/107040
2023-05-30 12:57:38 +02:00
Jubilee Young
472230d192 Remove array_zip
`[T; N]::zip` is "eager" but most zips are mapped.
This causes poor optimization in generated code.
This is a fundamental design issue and "zip" is
"prime real estate" in terms of function names,
so let's free it up again.
2023-05-30 00:40:39 -07:00
reez12g
000cd9b5fb fix comment on Allocator trait 2023-05-30 13:56:57 +09:00
Scott McMurray
11fa1764ee Make TrustedStep require Copy
All the implementations of the trait already are `Copy`, and this seems to be enough to simplify the implementations enough to make the MIR inliner willing to inline basics like `Range::next`.
2023-05-29 13:19:47 -07:00
Matthias Krüger
e71b3b3cfa
Rollup merge of #112045 - Sp00ph:update_current_impl, r=Amanieu
Followup to #111973

I somehow forgot to update the comment on `select_nth_unstable_by_key` in #111973, so this PR fixes that.

r? `@Amanieu`
2023-05-29 04:03:03 +02:00
Markus Everling
448a388387 Update current impl comment for select_nth_unstable_by_key 2023-05-28 16:12:48 +00:00
Matthias Krüger
5a4c04cc2c
Rollup merge of #111656 - finnbear:string_leak_unbounded_lifetime, r=Amanieu
Use an unbounded lifetime in `String::leak`.

Using `'a` instead of `'static` is predicted to make the process of making `String` generic over an allocator easier/less of a breaking change.

See:
- https://github.com/rust-lang/rust/pull/109814#issuecomment-1550164195
- https://github.com/rust-lang/rust/pull/109814#issuecomment-1550250163

ACP: https://github.com/rust-lang/libs-team/issues/109
2023-05-27 20:40:29 +02:00
Matthias Krüger
1d06bb9612
Rollup merge of #108630 - overlookmotel:realloc-docs-fix, r=Amanieu
Fix docs for `alloc::realloc`

Fixes #108546.

Corrects the docs for `alloc::realloc` to bring the safety constraints into line with `Layout::from_size_align_unchecked`'s constraints.
2023-05-27 20:40:27 +02:00
bors
f91b634643 Auto merge of #110975 - Amanieu:panic_count, r=joshtriplett
Rework handling of recursive panics

This PR makes 2 changes to how recursive panics works (a panic while handling a panic).

1. The panic count is no longer used to determine whether to force an immediate abort. This allows code like the following to work without aborting the process immediately:

```rust
struct Double;

impl Drop for Double {
    fn drop(&mut self) {
        // 2 panics are active at once, but this is fine since it is caught.
        std::panic::catch_unwind(|| panic!("twice"));
    }
}

let _d = Double;

panic!("once");
```

Rustc already generates appropriate code so that any exceptions escaping out of a `Drop` called in the unwind path will immediately abort the process.

2. Any panics while the panic hook is executing will force an immediate abort. This is necessary to avoid potential deadlocks like #110771 where a panic happens while holding the backtrace lock. We don't even try to print the panic message in this case since the panic may have been caused by `Display` impls.

Fixes #110771
2023-05-27 15:12:24 +00:00
Amanieu d'Antras
ef7f0e697b Rework handling of recursive panics 2023-05-27 16:35:16 +02:00
bors
82b311b418 Auto merge of #112016 - GuillaumeGomez:rollup-fhqn4i6, r=GuillaumeGomez
Rollup of 6 pull requests

Successful merges:

 - #111936 (Include test suite metadata in the build metrics)
 - #111952 (Remove DesugaringKind::Replace.)
 - #111966 (Add #[inline] to array TryFrom impls)
 - #111983 (Perform MIR type ops locally in new solver)
 - #111997 (Fix re-export of doc hidden macro not showing up)
 - #112014 (rustdoc: get unnormalized link destination for suggestions)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-05-27 12:29:07 +00:00
Guillaume Gomez
b2abb2b056
Rollup merge of #111966 - saethlin:inline-slice-tryfrom, r=thomcc
Add #[inline] to array TryFrom impls

I was looking into https://github.com/rust-lang/rust/issues/111959 and I realized we don't have these. They seem like an uncontroversial addition.

IMO this PR does not fix that issue. I think the bad codegen is being caused by some underlying deeper problem but this change might cause the MIR inliner to paper over it in this specific case.

r? `@thomcc`
2023-05-27 13:38:31 +02:00
bors
786178b2ab Auto merge of #111934 - scottmcm:stabilize-hash-one, r=Amanieu
Stabilize `BuildHasher::hash_one`

FCP completed in https://github.com/rust-lang/rust/issues/86161#issuecomment-1561125732
2023-05-27 09:47:42 +00:00
bors
a525c7ddba Auto merge of #111928 - c410-f3r:dqewdas, r=eholk
[RFC-2011] Expand more expressions

cc #44838

Expands `if`, `let`, `match` and also makes `generic_assert_internals` an allowed feature when using `assert!`. `#![feature(generic_assert)]` is still needed to activate everything.

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

fn fun(a: Option<i32>, b: Option<i32>, c: Option<i32>) {
  assert!(
    if a.is_some() { 1 } else { 2 } == 3
      && if let Some(elem) = b { elem == 4 } else { false }
      && match c { Some(_) => true, None => false }
  );
}

fn main() {
  fun(Some(1), None, Some(2));
}

// Assertion failed: assert!(
//   if a.is_some() { 1 } else { 2 } == 3
//     && if let Some(elem) = b { elem == 4 } else { false }
//     && match c { Some(_) => true, None => false }
// );
//
// With captures:
//   a = Some(1)
//   b = None
//   c = Some(2)
```
2023-05-27 07:02:48 +00:00
bors
dbfc95f969 Auto merge of #111348 - ozkanonur:remove-hardcoded-rustdoc-flags, r=albertlarsan68,oli-obk
new tool `rustdoc-gui-test`

Implements new tool `rustdoc-gui-test` that allows using compiletest headers for `rustdoc-gui` tests.
2023-05-27 04:20:44 +00:00
Matthias Krüger
18398ad337
Rollup merge of #111973 - Sp00ph:update_current_impl, r=Amanieu
Update current implementation comments for `select_nth_unstable`

This more accurately reflects the actual implementation, as it hasn't been a simple quickselect since #106997. While it does say that the current implementation always runs in O(n), I don't think it should require an FCP as it doesn't guarantee linearity in general and only points out that the current implementation is in fact linear.

r? `@Amanieu`
2023-05-27 00:23:59 +02:00
Urgau
b84c190b9a Allow newly uplifted invalid_from_utf8 lint 2023-05-27 00:18:28 +02:00
Urgau
7f99c7d3e6 Add invalid_from_utf8 analogous to invalid_from_utf8_unchecked 2023-05-27 00:18:28 +02:00
Urgau
7f8846a9ef Uplift clippy::invalid_utf8_in_unchecked as invalid_from_utf8_unchecked 2023-05-27 00:16:47 +02:00
bors
1a5f8bce74 Auto merge of #103291 - ink-feather-org:typeid_no_struct_match, r=dtolnay
Remove structural match from `TypeId`

As per https://github.com/rust-lang/rust/pull/99189#issuecomment-1203720442.

> Removing the structural equality might make sense, but is a breaking change that'd require a libs-api FCP.

https://github.com/rust-lang/rust/pull/99189#issuecomment-1197545482

> Landing this PR now (well, mainly the "remove structural equality" part) would unblock `const fn` `TypeId::of`, since we only postponed that because we were guaranteeing too much.

See also #99189, #101698
2023-05-26 17:29:03 +00:00
Matthias Krüger
2daecf7c45
Rollup merge of #111940 - zirconium-n:io-read-doc-change, r=thomcc
Clarify safety concern of `io::Read::read` is only relevant in unsafe code

We have this clarification note in other similar place like [Iterator::size_hint](https://doc.rust-lang.org/stable/std/iter/trait.Iterator.html#method.size_hint).

The lack of clarification might lead to confusion to Rust beginners. [Relevant URLO post](https://users.rust-lang.org/t/can-read-overflow-a-buffer/94347).
2023-05-26 08:24:08 +02:00
Markus Everling
ea327915d8 Update current implementation comments for select_nth_unstable 2023-05-26 01:31:04 +00:00
Ben Kimock
e1b8fad664 Add #[inline] to array TryFrom impls 2023-05-25 18:24:27 -04:00
Michael Goulet
fb45513126
Rollup merge of #107522 - Sp00ph:introselect, r=Amanieu
Add Median of Medians fallback to introselect

Fixes #102451.

This PR is a follow up to #106997. It adds a Fast Deterministic Selection implementation as a fallback to the introselect algorithm used by `select_nth_unstable`. This allows it to guarantee O(n) worst case running time, while maintaining good performance in all cases.

This would fix #102451, which was opened because the `select_nth_unstable` docs falsely claimed that it had O(n) worst case performance, even though it was actually quadratic in the worst case. #106997 improved the worst case complexity to O(n log n) by using heapsort as a fallback, and this PR further improves it to O(n) (this would also make #106933 unnecessary).
It also improves the actual runtime if the fallback gets called: Using a pathological input of size `1 << 19` (see the playground link in #102451), calculating the median is roughly 3x faster using fast deterministic selection as a fallback than it is using heapsort.

The downside to this is less code reuse between the sorting and selection algorithms, but I don't think it's that bad. The additional algorithms are ~250 LOC with no `unsafe` blocks (I tried using unsafe to avoid bounds checks but it didn't noticeably improve the performance).
I also let it fuzz for a while against the current `select_nth_unstable` implementation to ensure correctness, and it seems to still fulfill all the necessary postconditions.

cc `@scottmcm` who reviewed #106997
2023-05-25 13:57:59 -07:00
raldone01
f2bdaf1a4d Remove structural match from TypeId. 2023-05-25 20:15:39 +02:00
bors
a2b1646c59 Auto merge of #86844 - bjorn3:global_alloc_improvements, r=pnkfelix
Support #[global_allocator] without the allocator shim

This makes it possible to use liballoc/libstd in combination with `--emit obj` if you use `#[global_allocator]`. This is what rust-for-linux uses right now and systemd may use in the future. Currently they have to depend on the exact implementation of the allocator shim to create one themself as `--emit obj` doesn't create an allocator shim.

Note that currently the allocator shim also defines the oom error handler, which is normally required too. Once `#![feature(default_alloc_error_handler)]` becomes the only option, this can be avoided. In addition when using only fallible allocator methods and either `--cfg no_global_oom_handling` for liballoc (like rust-for-linux) or `--gc-sections` no references to the oom error handler will exist.

To avoid this feature being insta-stable, you will have to define `__rust_no_alloc_shim_is_unstable` to avoid linker errors.

(Labeling this with both T-compiler and T-lang as it originally involved both an implementation detail and had an insta-stable user facing change. As noted above, the `__rust_no_alloc_shim_is_unstable` symbol requirement should prevent unintended dependence on this unstable feature.)
2023-05-25 16:59:57 +00:00
Michael Howell
5fb752bdd5 std: make fortanix-sgx-abi a public depedenceny
It's exported publicly, so it should not be linted.
2023-05-25 08:15:05 -07:00
Michael Howell
8c21920cc7 std: make internal-only items pub(crate)
This works around a weird problem that looks like a bug in the
`exported_private_dependencies` lint.
2023-05-25 08:15:05 -07:00
Michael Howell
b537c1f175 std: mark common functions in test crate pub(crate)
This is not a library, so there's no reason for them to be `pub`.
Without doing this, compiling the test crates causes private dep
lint errors:

      error: type `PathBuf` from private dependency 'std' in public interface
        --> library/std/tests/common/mod.rs:26:5
         |
      26 |     pub fn join(&self, path: &str) -> PathBuf {
         |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         |
         = note: `-D exported-private-dependencies` implied by `-D warnings`

      error: type `Path` from private dependency 'std' in public interface
        --> library/std/tests/common/mod.rs:31:5
         |
      31 |     pub fn path(&self) -> &Path {
         |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^

      error: could not compile `std` (test "create_dir_all_bare") due to 2 previous errors

This happens because Cargo passes `--extern 'priv:std=...` when
compiling the test crate.

I'm not sure if these warnings are desirable or not. They seem correct
in a very pedantic way (the dependency on `std` is not marked public,
since it's implicit), but also pointless (the test crate is not an API,
so who cares what it does).
2023-05-25 08:15:04 -07:00
Michael Howell
64025bb168 bootstrap: enable Cargo public-dependency feature for libstd 2023-05-25 08:13:23 -07:00
Ziru Niu
dd56f930cc Clarify safety concern of io::Read::read is only relevant in unsafe code 2023-05-25 18:38:38 +08:00
Scott McMurray
ba5a3968b8 Stabilize BuildHasher::hash_one 2023-05-24 23:47:50 -07:00
Matthias Krüger
8497948c7a
Rollup merge of #95198 - clarfonthey:get_chunk, r=scottmcm
Add slice::{split_,}{first,last}_chunk{,_mut}

This adds to the existing tracking issue for `slice::array_chunks` (#74985) under a separate feature, `slice_get_chunk`.

Currently, we have the existing `first`/`last` API for slices:

```rust
impl [T] {
    pub const fn first(&self) -> Option<&T>;
    pub const fn first_mut(&mut self) -> Option<&mut T>;
    pub const fn last(&self) -> Option<&T>;
    pub const fn last_mut(&mut self) -> Option<&mut T>;
    pub const fn split_first(&self) -> Option<(&T, &[T])>;
    pub const fn split_first_mut(&mut self) -> Option<(&mut T, &mut [T])>;
    pub const fn split_last(&self) -> Option<(&T, &[T])>;
    pub const fn split_last_mut(&mut self) -> Option<(&mut T, &mut [T])>;
}
```

This augments it with a `first_chunk`/`last_chunk` API that allows retrieving multiple elements at once:

```rust
impl [T] {
    pub const fn first_chunk<const N: usize>(&self) -> Option<&[T; N]>;
    pub const fn first_chunk_mut<const N: usize>(&mut self) -> Option<&mut [T; N]>;
    pub const fn last_chunk<const N: usize>(&self) -> Option<&[T; N]>;
    pub const fn last_chunk_mut<const N: usize>(&mut self) -> Option<&mut [T; N]>;
    pub const fn split_first_chunk<const N: usize>(&self) -> Option<(&[T; N], &[T])>;
    pub const fn split_first_chunk_mut<const N: usize>(&mut self) -> Option<(&mut [T; N], &mut [T])>;
    pub const fn split_last_chunk<const N: usize>(&self) -> Option<(&[T; N], &[T])>;
    pub const fn split_last_chunk_mut<const N: usize>(&mut self) -> Option<(&mut [T; N], &mut [T])>;
}
```

The code is based off of a copy of the existing API, with the documentation and examples properly modified. Currently, the most common way to perform these kinds of lookups with the existing methods is via `slice.as_chunks::<N>().0[0]` or the worse `slice.as_chunks::<N>().0[slice.len() - N]`, which is substantially less readable than `slice.first_chunk::<N>()` or `slice.last_chunk::<N>()`.

ACP: https://github.com/rust-lang/libs-team/issues/69
2023-05-25 08:01:07 +02:00
Caio
462a96c9e9 [RFC-2011] Expand more expressions 2023-05-24 21:15:50 -03:00
Manish Goregaokar
8038606bf3
Rollup merge of #111915 - jyn514:libtest-errors, r=thomcc
libtest: Improve error when missing `-Zunstable-options`

"only accepted on the nightly compiler" is misleading when this *is* nightly.
2023-05-24 15:05:05 -07:00
Markus Everling
fd5fa012e9 Use helper functions for min/max_idx 2023-05-24 19:33:04 +00:00