Commit Graph

5451 Commits

Author SHA1 Message Date
Dylan DPC
6011fd4655
Rollup merge of #115477 - kellerkindt:stabilized_int_impl, r=dtolnay
Stabilize the `Saturating` type

Closes #87920
Closes #92354

Stabilization report https://github.com/rust-lang/rust/issues/87920#issuecomment-1652346124
FCP https://github.com/rust-lang/rust/issues/87920#issuecomment-1676438885
2023-09-17 11:23:24 +00:00
Dylan DPC
584eb696df
Rollup merge of #115434 - soqb:ascii-char-manual-debug, r=dtolnay
make `Debug` impl for `ascii::Char` match that of `char`

# Objective
use a more recognisable format for the `Debug` impl on `ascii::Char` than the derived one based off the enum variants. The alogorithm used is the following:
 - escape `ascii::Char::{Null, CharacterTabulation, CarraigeReturn, LineFeed, ReverseSolidus, Apostrophe}` to `'\0'`, `'\t'`, `'\r'`, `'\n'`, `'\\'` and `'\''` respectively. these are the same escape codes as `<char as Debug>::fmt` uses.
 - if `u8::is_ascii_control` is false, print the character wrapped in single quotes.
 - otherwise, print in the format `'\xAB'` where `A` and `B` are the hex nibbles of the byte. (`char` uses unicode escapes and this seems like the corresponding ascii format).

Tracking issue: https://github.com/rust-lang/rust/issues/110998
2023-09-17 11:23:24 +00:00
bors
3ecc563628 Auto merge of #113748 - clarfonthey:ip-step, r=dtolnay
impl Step for IP addresses

ACP: rust-lang/libs-team#235

Note: since this is insta-stable, it requires an FCP.

Separating out from the bit operations PR since it feels logically disjoint, and so their FCPs can be separate.
2023-09-17 06:27:09 +00:00
bors
a09c1f85f1 Auto merge of #115782 - a1phyr:improve_pad_adapter, r=dtolnay
Improve `PadAdapter::write_char`

Split from #108043
2023-09-17 01:47:49 +00:00
Matthias Krüger
633f143921
Rollup merge of #115560 - ShE3py:format-results, r=dtolnay
Update doc for `alloc::format!` and `core::concat!`

Closes #115551.

Used comments instead of `assert!`s as [`std::fmt`](https://doc.rust-lang.org/std/fmt/index.html#usage) uses comments.

Should all the str-related macros (`format!`, `format_args!`, `concat!`, `stringify!`, `println!`, `writeln!`, etc.) references each others? For instance, [`concat!`](https://doc.rust-lang.org/core/macro.concat.html) mentions that integers are stringified, but don't link to `stringify!`.

`@rustbot` label +A-docs +A-fmt
2023-09-16 23:20:41 +02:00
Matthias Krüger
edfe8b4434
Rollup merge of #115329 - xzmeng:fix-std-doc, r=dtolnay
fix std::primitive doc: homogenous -> homogeneous

replace "homogenous" with the more commonly used "homogeneous".
2023-09-16 23:20:39 +02:00
bors
4514fb98d5 Auto merge of #112229 - clarfonthey:range-iter-count, r=dtolnay
Specialize count for range iterators

Since `size_hint` is already specialized, it feels apt to specialize `count` as well. Without any specialized version of `ExactSizeIterator::len` or `Step::steps_between`, this feels like a more reliable way of accessing this without having to rely on knowing that `size_hint` is correct.

In my case, this is particularly useful to access the `steps_between` implementation for `char` from the standard library without having to compute it manually.

I didn't think it was worth modifying the `Step` trait to add a version of `steps_between` that used native overflow checks since this is just doing one subtraction in most cases anyway, and so I decided to make the inclusive version use `checked_add` so it didn't have this lopsided overflow-checks-but-only-sometimes logic.
2023-09-16 16:43:31 +00:00
Matthias Krüger
c2f228f654
Rollup merge of #115607 - RalfJung:safe-traits-unsafe-code, r=dtolnay
clarify that unsafe code must not rely on our safe traits

This adds a disclaimer to PartialEq, Eq, PartialOrd, Ord, Hash, Deref, DerefMut.

We already have a similar disclaimer in ExactSizeIterator (worded a bit differently):
```
/// Note that this trait is a safe trait and as such does *not* and *cannot*
/// guarantee that the returned length is correct. This means that `unsafe`
/// code **must not** rely on the correctness of [`Iterator::size_hint`]. The
/// unstable and unsafe [`TrustedLen`](super::marker::TrustedLen) trait gives
/// this additional guarantee.
```
If there are any other traits that should carry such a disclaimer, please let me know.

Fixes https://github.com/rust-lang/rust/issues/73682
2023-09-16 11:48:18 +02:00
Ralf Jung
d49123ddc9 fix a comment about assert_receiver_is_total_eq 2023-09-16 11:43:34 +02:00
ltdk
08aa6c9b65 Specialize count for range iterators 2023-09-16 01:33:56 -04:00
ltdk
8184c9c50d impl Step for IP addresses 2023-09-16 01:28:13 -04:00
bors
635c4a5e61 Auto merge of #114494 - est31:extend_useless_ptr_null_checks, r=jackh726
Make useless_ptr_null_checks smarter about some std functions

This teaches the `useless_ptr_null_checks` lint that some std functions can't ever return null pointers, because they need to point to valid data, get references as input, etc.

This is achieved by introducing an `#[rustc_never_returns_null_ptr]` attribute and adding it to these std functions (gated behind bootstrap `cfg_attr`).

Later on, the attribute could maybe be used to tell LLVM that the returned pointer is never null. I don't expect much impact of that though, as the functions are pretty shallow and usually the input data is already never null.

Follow-up of PR #113657

Fixes #114442
2023-09-16 03:40:20 +00:00
bors
e81f85fe9e Auto merge of #115520 - Finomnis:const_transmute_copy, r=dtolnay
Stabilize const_transmute_copy

Closes #83165
2023-09-16 01:51:55 +00:00
bors
c728bf3963 Auto merge of #114656 - bossmc:rework-no-coverage-attr, r=oli-obk
Rework `no_coverage` to `coverage(off)`

As discussed at the tail of https://github.com/rust-lang/rust/issues/84605 this replaces the `no_coverage` attribute with a `coverage` attribute that takes sub-parameters (currently `off` and `on`) to control the coverage instrumentation.

Allows future-proofing for things like `coverage(off, reason="Tested live", issue="#12345")` or similar.
2023-09-14 01:05:18 +00:00
Benoît du Garreau
814f4f6f52 Improve PadAdapter::write_char 2023-09-12 15:57:36 +02:00
Guillaume Gomez
1fb672c738
Rollup merge of #115201 - notriddle:notriddle/type-alias-impl-list, r=GuillaumeGomez
rustdoc: list matching impls on type aliases

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

Fixes #99952

Remake of https://github.com/rust-lang/rust/pull/112429

Partially reverts https://github.com/rust-lang/rust/pull/112543, but keeps the test case.

This version of the PR avoids the infinite loop by structurally matching types instead of using full unification. This version does not support type alias trait bounds, but the compiler does not enforce those anyway (https://github.com/rust-lang/rust/issues/21903).

r? `@GuillaumeGomez`

CC `@lcnr`
2023-09-08 14:10:51 +02:00
Guillaume Gomez
2cceedd0ef
Rollup merge of #104299 - mkrasnitski:discriminant-transmute-docs, r=oli-obk
Clarify stability guarantee for lifetimes in enum discriminants

Since `std::mem::Discriminant` erases lifetimes, it should be clarified that changing the concrete value of a lifetime parameter does not change the value of an enum discriminant for a given variant. This is useful as it guarantees that it is safe to transmute `Discriminant<Foo<'a>>` to `Discriminant<Foo<'b>>` for any combination of `'a` and `'b`. This also holds for type-generics as long as the type parameters do not change, e.g. `Discriminant<Foo<T, 'a>>` can be transmuted to `Discriminant<Foo<T, 'b>>`.

Side note: Is what I've written actually enough to imply soundness (or rather codify it), or should it specifically be spelled out that it's OK to transmute in the above way?
2023-09-08 14:10:49 +02:00
Andy Caldwell
679267f2ac
Rename the feature, but not the attribute, to coverage_attribute 2023-09-08 12:46:09 +01:00
Andy Caldwell
8e03371fc3
Rework no_coverage to coverage(off) 2023-09-08 12:46:06 +01:00
bors
feb06732c0 Auto merge of #114299 - clarfonthey:char-min, r=dtolnay,BurntSushi
Add char::MIN

ACP: rust-lang/libs-team#252
Tracking issue: #114298

r? `@rust-lang/libs-api`
2023-09-08 00:02:48 +00:00
bors
4e5b31c2b0 Auto merge of #115166 - Urgau:invalid_ref_casting-invalid-unsafecell-usage, r=est31
Lint on invalid usage of `UnsafeCell::raw_get` in reference casting

This PR proposes to take into account `UnsafeCell::raw_get` method call for non-Freeze types for the `invalid_reference_casting` lint.

The goal of this is to catch those kind of invalid reference casting:
```rust
fn as_mut<T>(x: &T) -> &mut T {
    unsafe { &mut *std::cell::UnsafeCell::raw_get(x as *const _ as *const _) }
    //~^ ERROR casting `&T` to `&mut T` is undefined behavior
}
```

r? `@est31`
2023-09-07 00:24:45 +00:00
Darius Wiles
408dca7241
Fix minor grammar typo 2023-09-06 09:47:22 -07:00
Ralf Jung
62111145b7 clarify that unsafe code must not rely on our safe traits 2023-09-06 16:12:39 +02:00
ShE3py
94e651b9b2
Update doc for alloc::format! and core::concat! 2023-09-06 15:11:21 +02:00
Matthias Krüger
14c57f1adb
Rollup merge of #114794 - RalfJung:swap-safety, r=m-ou-se
clarify safety documentation of ptr::swap and ptr::copy

Closes https://github.com/rust-lang/rust/issues/81005
2023-09-05 20:15:01 +02:00
Ralf Jung
4684ffaf2a
if -> when 2023-09-05 17:20:31 +02:00
Matthias Krüger
9381e5bf58
Rollup merge of #115540 - cjgillot:custom-debuginfo, r=oli-obk
Support debuginfo for custom MIR.
2023-09-05 15:16:51 +02:00
Matthias Krüger
781253bc32
Rollup merge of #114813 - RalfJung:fpu-control, r=Amanieu
explain why we can mutate the FPU control word

This is usually not allowed (see https://github.com/rust-lang/stdarch/pull/1454), but here we have a special case.
2023-09-05 15:16:48 +02:00
Matthias Krüger
cbab5adf8a
Rollup merge of #114412 - RalfJung:libc-symbols, r=pnkfelix
document our assumptions about symbols provided by the libc

LLVM makes assumptions about `memcmp`, `memmove`, and `memset` that go beyond what the C standard guarantees -- see https://reviews.llvm.org/D86993. Since we use LLVM, we are inheriting these assumptions.

With https://github.com/rust-lang/rust/pull/114382 we are also making a similar assumption about `memcmp`, so I added that to the list.

Fixes https://github.com/rust-lang/unsafe-code-guidelines/issues/426.
2023-09-05 15:16:47 +02:00
Matthias Krüger
a23f216136
Rollup merge of #113510 - ink-feather-org:const_ptr_transmute_docs, r=RalfJung
Document soundness of Integer -> Pointer -> Integer conversions in `const` contexts.

see this [zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/topic/Soundness.20of.20Integer.20-.3E.20Pointer.20-.3E.20Integer.20conversions)

r? `@RalfJung`

With this slice `Iterator`'s should be able to be made const once the const Trait reimplementation is done.
2023-09-05 15:16:47 +02:00
Maybe Waffle
1811fe6af0 Simplify core::hint::spin_loop 2023-09-04 19:53:40 +00:00
bors
abfc6c4438 Auto merge of #115491 - Zoxc:refcell-tweak, r=Mark-Simulacrum
Outline panicking code for `RefCell::borrow` and `RefCell::borrow_mut`

This outlines panicking code for `RefCell::borrow` and `RefCell::borrow_mut` to reduce code size.
2023-09-03 23:03:03 +00:00
Finomnis
0bb54814e1 Stabilize const_transmute_copy 2023-09-03 23:20:31 +02:00
Matthias Krüger
50aea927f5
Rollup merge of #115279 - schuelermine:patch/doc/RangeFull/remote-parens, r=Mark-Simulacrum
RangeFull: Remove parens around .. in documentation snippet

I’ve removed unnecessary parentheses in a documentation snippet documenting `RangeFull`. It could’ve lead people to believe the parentheses were necessary.
2023-09-03 21:38:41 +02:00
John Kåre Alsaker
00c251134d Outline panicking code for RefCell::borrow and RefCell::borrow_mut 2023-09-03 05:10:58 +02:00
Michael Watzko
ad54426945 Stabilize the Saturating type (saturating_int_impl, gh-87920)
Also stabilizes saturating_int_assign_impl, gh-92354.

And also make pub fns const where the underlying saturating_*
fns became const in the meantime since the Saturating type was
created.
2023-09-03 01:22:46 +02:00
Michael Watzko
0eb41335e2 Unimpl Shl, ShlAssign, Shr and ShrAssign for Saturating 2023-09-03 01:21:49 +02:00
bors
c4f25777a0 Auto merge of #115273 - the8472:take-fold, r=cuviper
Optimize Take::{fold, for_each} when wrapping TrustedRandomAccess iterators
2023-09-02 12:40:16 +00:00
Matthias Krüger
1bbd307349
Rollup merge of #115449 - scottmcm:stable-const-is-ascii, r=ChrisDenton
Const-stabilize `is_ascii`

Resolves #111090

FCP completed in https://github.com/rust-lang/rust/issues/111090#issuecomment-1688490049
2023-09-02 07:48:23 +02:00
Matthias Krüger
1df0c21af1
Rollup merge of #114845 - scottmcm:npo-align, r=WaffleLapkin
Add alignment to the NPO guarantee

This PR [changes](https://github.com/rust-lang/rust/pull/114845#discussion_r1294363357) "same size" to "same size and alignment" in the option module's null pointer optimization docs in <https://doc.rust-lang.org/std/option/#representation>.

As far as I know, this has been true for a long time in the actual rustc implementation, but it's not in the text of those docs, so I figured I'd bring this up to FCP it.

I also see no particular reason that we'd ever *want* to have higher alignment on these.  In many of the cases it's impossible, as the minimum alignment is already the size of the type, but even if we *could* do things like on 32-bit we could say that `NonZeroU64` is 4-align but `Option<NonZeroU64>` is 8-align, I just don't see any value in doing that, so feel completely fine closing this door for the few things on which the NPO is already guaranteed.  These are basically all primitives, and should end up with the same size & alignment as those primitives.

(There's no layout guarantee for something like `Option<[u8; 3]>`, where it'd be at least plausible to consider raising the alignment from 1 to 4 on, say, some hypothetical target that doesn't have efficient unaligned 4-byte load/stores.  And even if we ever did start to offer some kind of guarantee around such a type, I doubt we'd put it under the "null pointer" optimization header.)

Screenshots for the new examples:
![image](https://github.com/rust-lang/rust/assets/18526288/a7dbff42-50b4-462e-9e27-00d511b58763)
![image](https://github.com/rust-lang/rust/assets/18526288/dfd55288-80fb-419a-bc11-26198c27f9f9)
2023-09-02 07:48:21 +02:00
bors
f9ba43ce14 Auto merge of #113295 - clarfonthey:ascii-step, r=cuviper
Implement Step for ascii::Char

This allows iterating over ranges of `ascii::Char`, similarly to ranges of `char`.

Note that `ascii::Char` is still unstable, tracked in #110998.
2023-09-02 00:02:50 +00:00
Scott McMurray
570c312bc5 Const-stabilize is_ascii 2023-09-01 11:02:09 -07:00
Camille GILLOT
905fd1ba17 Support bootstrap. 2023-09-01 16:18:50 +00:00
Camille GILLOT
6cec91d647 Support debuginfo for custom MIR. 2023-09-01 16:16:31 +00:00
bors
361f8ba847 Auto merge of #114065 - lukas-code:u16_from_char, r=dtolnay
`impl TryFrom<char> for u16`

This PR implements the final missing `char` -> unsigned integer conversion.

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

r? libs-api
`@rustbot` label +T-libs-api +needs-fcp -T-libs
2023-09-01 16:01:06 +00:00
soqb
9c0e5ebf65 fix Debug impl for AsciiChar 2023-09-01 12:29:40 +01:00
Caio
0164f7e8b2
[clippy] Use symbols intended for arithmetic_side_effects 2023-09-01 10:28:55 +02:00
Trevor Gross
fe0eb8b49b Implement CStr::count_bytes
This is feature gated under `cstr_count_bytes` and provides a more
straightforward way to access the length of a `CStr`

Link: https://github.com/rust-lang/rust/issues/113219
2023-08-29 13:38:22 -04:00
Trevor Gross
e8f9d1a80f Refactor the const strlen implementation to const_strlen
Currently, `CStr::from_ptr` contains its own implementation of `strlen`
that uses `const_eval_select` to either call libc's `strlen` or use a
naive Rust implementation. Refactor that into its own function so we can
use it elsewhere in the module.
2023-08-29 13:36:45 -04:00
bors
f6faef4475 Auto merge of #114795 - RalfJung:cell-swap, r=dtolnay
make Cell::swap panic if the Cells partially overlap

The following function ought to be sound:
```rust
fn as_cell_of_array<T, const N: usize>(c: &[Cell<T>; N]) -> &Cell<[T; N]> {
    unsafe { transmute(c) }
}
```
However, due to `Cell::swap`, it currently is not -- safe code can [cause a use-after-free](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=c9415799722d985ff7d2c2c997b724ca). This PR fixes that.

Fixes https://github.com/rust-lang/rust/issues/80778
2023-08-29 07:53:56 +00:00
Meng Xiangzhuo
57fccf9e5b fix std::primitive doc: homogenous -> homogeneous 2023-08-29 06:23:34 +08:00
Matthias Krüger
9b0abe3537
Rollup merge of #115311 - dtolnay:usearcself, r=compiler-errors
Revert "Suggest using `Arc` on `!Send`/`!Sync` types"

Closes https://github.com/rust-lang/rust/issues/114687. This is a clean revert of https://github.com/rust-lang/rust/pull/88936 + https://github.com/rust-lang/rust/pull/115210. The suggestion to Arc\<{Self}\> when Self does not implement Send is *always* wrong.

https://github.com/rust-lang/rust/pull/114842 is considering a way to make a more refined suggestion.
2023-08-28 19:53:57 +02:00
Matthias Krüger
2eff0deca3
Rollup merge of #115310 - RalfJung:panic-and-format, r=scottmcm
Document panic behavior across editions, and improve xrefs

This revives (parts of) https://github.com/rust-lang/rust/pull/96518.
r? `@scottmcm`
Cc `@ijackson`
2023-08-28 19:53:56 +02:00
The 8472
07a1d5f027 reduce indirection in for_each specialization 2023-08-28 14:37:31 +02:00
David Tolnay
823bacb6e3
Revert "Suggest using Arc on !Send/!Sync types"
This reverts commit 9de1a472b6.
2023-08-28 03:16:48 -07:00
David Tolnay
4120936f6d
Revert "Make rustc_on_unimplemented std-agnostic for alloc::rc"
This reverts commit 6ec570aca5.
2023-08-28 03:16:42 -07:00
Ralf Jung
5016695357 improve panic.md edition disucssion, and nits 2023-08-28 12:11:19 +02:00
Ian Jackson
39c642e3d2 format, format_args: Make xref to std::fmt much more prominent
That xref contains the actual documentation for what format! does.
It should be very prominent - particularly, more so than the other
links.
2023-08-28 11:54:40 +02:00
Ian Jackson
2ec8b6b50f panic macro: Link directly to format syntax, not to format! 2023-08-28 11:52:21 +02:00
Ian Jackson
11167071db panic macro: Document edition differences
Having a section for this inspired by the docs for array::IntoIterator
2023-08-28 11:50:38 +02:00
bors
1bd043098e Auto merge of #103836 - H4x5:extra-float-constants, r=thomcc
Add additional float constants

Initial implementation of this ACP: https://github.com/rust-lang/libs-team/issues/119. [Accepted]
Tracking issue: #103883

The values for the constants are copied from the [`libstdc++` source code](16e2427f50/libstdc%2B%2B-v3/include/std/numbers (L57-L120)).
2023-08-28 08:54:28 +00:00
Matthias Krüger
32053f7602
Rollup merge of #115280 - RalfJung:panic-cleanup-triple-backtrace, r=Amanieu
avoid triple-backtrace due to panic-during-cleanup

Supersedes https://github.com/rust-lang/rust/pull/115020
Cc https://github.com/rust-lang/rust/issues/114954
r? ``@Amanieu``
2023-08-28 08:13:59 +02:00
Matthias Krüger
d2644d9fe9
Rollup merge of #114238 - jhpratt:fix-duration-div, r=thomcc
Fix implementation of `Duration::checked_div`

I ran across this while running some sanity checks on `time`. Quickcheck immediately found a bug, and as I'd modified the code from `std` I knew there was a bug here as well.

tl;dr this code fails ([playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1189a3efcdfc192c27d6d87815359353))

```rust
use std::time::Duration;

fn main() {
    assert_eq!(
        Duration::new(1, 1).checked_div(7),
        Some(Duration::new(0, 142_857_143)),
    );
}
```

The existing code determines that 1/7 = 0 (seconds), 1/7 = 0 (nanoseconds), 1 billion / 7 = 142,857,142 (extra nanoseconds). The billion comes from multiplying the remainder of the seconds (1) by the number of nanoseconds in a second. However, **this wrongly ignores any remaining nanoseconds**. This PR takes that into consideration, adds a test, and also changes the roundabout way of calculating the remainder into directly computing it.

Note: This is _not_ a rounding error. This result divides evenly.

`@rustbot` label +A-time +C-bug +S-waiting-on-reviewer +T-libs
2023-08-28 08:13:57 +02:00
Ralf Jung
1087e90a2e avoid triple-backtrace due to panic-during-cleanup 2023-08-27 20:02:46 +02:00
Anselm Schüler
2a270a0066
Remove parens around .. in documentation snippet 2023-08-27 19:16:15 +02:00
The 8472
72b01d5cca Optimize Take::{fold, for_each} when wrapping TrustedRandomAccess iterators 2023-08-27 15:32:34 +02:00
bors
f320f42c59 Auto merge of #114969 - kpreid:dropdoc, r=Mark-Simulacrum
Go into more detail about panicking in drop.

This patch was sitting around in my drafts. I don't recall the motivation, but I think it was someone expressing confusion over “will likely abort” (since, in fact, a panicking drop _not_ caused by dropping while panicking will predictably _not_ abort).

I hope that the new text will leave people well-informed about why not to panic and when it is reasonable to panic.
2023-08-27 06:12:00 +00:00
Matthias Krüger
c3668d3d7c
Rollup merge of #115210 - DogPawHat:std-agnostic-rustc_on_unimplemented-for-alloc-rc, r=WaffleLapkin
Make `rustc_on_unimplemented` std-agnostic for `alloc::rc`

See https://github.com/rust-lang/rust/issues/112923

Just a few lines related to `alloc:rc` for `Send` and `Sync`.

That seems to be all of the `... = "std::..."` issues found, but there a few notes with `std::` inside them still.

r? `@WaffleLapkin`
2023-08-26 13:08:34 +02:00
Matthias Krüger
8e35b2082c
Rollup merge of #115197 - tbu-:pr_simpler_ipv6_addr_display, r=joshtriplett
Remove special cases that are no longer needed due to #112606

cc #112606
2023-08-26 13:08:33 +02:00
Ciarán Curley
6ec570aca5
Make rustc_on_unimplemented std-agnostic for alloc::rc 2023-08-26 00:52:51 +01:00
bors
84382dd10a Auto merge of #115133 - coderwithcat:master, r=cuviper
use the correct link
2023-08-25 18:49:51 +00:00
bors
b60f7b51a2 Auto merge of #115045 - RalfJung:unwind-terminate-reason, r=davidtwco
when terminating during unwinding, show the reason why

With this, the output on double-panic becomes something like that:
```
thread 'main' panicked at src/tools/miri/tests/fail/panic/double_panic.rs:15:5:
first
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at src/tools/miri/tests/fail/panic/double_panic.rs:10:9:
second
stack backtrace:
   0:           0xbe273a - std::backtrace_rs::backtrace::miri::trace_unsynchronized::<&mut [closure@std::sys_common::backtrace::_print_fmt::{closure#1}]>
                               at /home/r/src/rust/rustc.3/library/std/src/../../backtrace/src/backtrace/miri.rs:99:5
   1:           0xbe22e6 - std::backtrace_rs::backtrace::miri::trace::<&mut [closure@std::sys_common::backtrace::_print_fmt::{closure#1}]>
                               at /home/r/src/rust/rustc.3/library/std/src/../../backtrace/src/backtrace/miri.rs:62:14
   2:           0xbe1086 - std::backtrace_rs::backtrace::trace_unsynchronized::<[closure@std::sys_common::backtrace::_print_fmt::{closure#1}]>
                               at /home/r/src/rust/rustc.3/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   3:           0xba3afd - std::sys_common::backtrace::_print_fmt
                               at /home/r/src/rust/rustc.3/library/std/src/sys_common/backtrace.rs:67:5
   4:           0xba2471 - <std::sys_common::backtrace::_print::DisplayBacktrace as std::fmt::Display>::fmt
                               at /home/r/src/rust/rustc.3/library/std/src/sys_common/backtrace.rs:44:22
   5:           0xbcf754 - core::fmt::rt::Argument::<'_>::fmt
                               at /home/r/src/rust/rustc.3/library/core/src/fmt/rt.rs:138:9
   6:           0x9b8f81 - std::fmt::write
                               at /home/r/src/rust/rustc.3/library/core/src/fmt/mod.rs:1094:17
   7:           0x21391d - <std::sys::unix::stdio::Stderr as std::io::Write>::write_fmt
                               at /home/r/src/rust/rustc.3/library/std/src/io/mod.rs:1714:15
   8:           0xba37b1 - std::sys_common::backtrace::_print
                               at /home/r/src/rust/rustc.3/library/std/src/sys_common/backtrace.rs:47:5
   9:           0xba365b - std::sys_common::backtrace::print
                               at /home/r/src/rust/rustc.3/library/std/src/sys_common/backtrace.rs:34:9
  10:           0x143c67 - std::panic_hook_with_disk_dump::{closure#1}
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:278:22
  11:           0x144187 - std::panic_hook_with_disk_dump
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:312:9
  12:           0x143659 - std::panicking::default_hook
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:239:5
  13:           0x1482a7 - std::panicking::rust_panic_with_hook
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:729:13
  14:           0x1475d5 - std::rt::begin_panic::<&str>::{closure#0}
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:650:9
  15:           0xba496a - std::sys_common::backtrace::__rust_end_short_backtrace::<[closure@std::rt::begin_panic<&str>::{closure#0}], !>
                               at /home/r/src/rust/rustc.3/library/std/src/sys_common/backtrace.rs:170:18
  16:           0x147599 - std::rt::begin_panic::<&str>
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:649:12
  17:            0x31916 - <Foo as std::ops::Drop>::drop
                               at src/tools/miri/tests/fail/panic/double_panic.rs:10:9
  18:           0x1a2b5e - std::ptr::drop_in_place::<Foo> - shim(Some(Foo))
                               at /home/r/src/rust/rustc.3/library/core/src/ptr/mod.rs:497:1
  19:            0x202bf - main
                               at src/tools/miri/tests/fail/panic/double_panic.rs:16:1
  20:            0xcc6a8 - <fn() as std::ops::FnOnce<()>>::call_once - shim(fn())
                               at /home/r/src/rust/rustc.3/library/core/src/ops/function.rs:250:5
  21:           0xba47d9 - std::sys_common::backtrace::__rust_begin_short_backtrace::<fn(), ()>
                               at /home/r/src/rust/rustc.3/library/std/src/sys_common/backtrace.rs:154:18
  22:           0x141a6a - std::rt::lang_start::<()>::{closure#0}
                               at /home/r/src/rust/rustc.3/library/std/src/rt.rs:166:18
  23:            0xcca18 - std::ops::function::impls::<impl std::ops::FnOnce<()> for &dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe>::call_once
                               at /home/r/src/rust/rustc.3/library/core/src/ops/function.rs:284:13
  24:           0x146469 - std::panicking::try::do_call::<&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe, i32>
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:524:40
  25:           0x145e09 - std::panicking::try::<i32, &dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe>
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:488:19
  26:            0x7b0ac - std::panic::catch_unwind::<&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe, i32>
                               at /home/r/src/rust/rustc.3/library/std/src/panic.rs:142:14
  27:           0x14189b - std::rt::lang_start_internal::{closure#2}
                               at /home/r/src/rust/rustc.3/library/std/src/rt.rs:148:48
  28:           0x146481 - std::panicking::try::do_call::<[closure@std::rt::lang_start_internal::{closure#2}], isize>
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:524:40
  29:           0x145e2c - std::panicking::try::<isize, [closure@std::rt::lang_start_internal::{closure#2}]>
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:488:19
  30:            0x7b0d5 - std::panic::catch_unwind::<[closure@std::rt::lang_start_internal::{closure#2}], isize>
                               at /home/r/src/rust/rustc.3/library/std/src/panic.rs:142:14
  31:           0x1418b0 - std::rt::lang_start_internal
                               at /home/r/src/rust/rustc.3/library/std/src/rt.rs:148:20
  32:           0x141a97 - std::rt::lang_start::<()>
                               at /home/r/src/rust/rustc.3/library/std/src/rt.rs:165:17
thread 'main' panicked at /home/r/src/rust/rustc.3/library/core/src/panicking.rs:126:5:
panic in a destructor during cleanup
stack backtrace:
   0:           0xe9f6d7 - std::backtrace_rs::backtrace::miri::trace_unsynchronized::<&mut [closure@std::sys_common::backtrace::_print_fmt::{closure#1}]>
                               at /home/r/src/rust/rustc.3/library/std/src/../../backtrace/src/backtrace/miri.rs:99:5
   1:           0xe9f27d - std::backtrace_rs::backtrace::miri::trace::<&mut [closure@std::sys_common::backtrace::_print_fmt::{closure#1}]>
                               at /home/r/src/rust/rustc.3/library/std/src/../../backtrace/src/backtrace/miri.rs:62:14
   2:           0xe9e016 - std::backtrace_rs::backtrace::trace_unsynchronized::<[closure@std::sys_common::backtrace::_print_fmt::{closure#1}]>
                               at /home/r/src/rust/rustc.3/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   3:           0xba3afd - std::sys_common::backtrace::_print_fmt
                               at /home/r/src/rust/rustc.3/library/std/src/sys_common/backtrace.rs:67:5
   4:           0xba2471 - <std::sys_common::backtrace::_print::DisplayBacktrace as std::fmt::Display>::fmt
                               at /home/r/src/rust/rustc.3/library/std/src/sys_common/backtrace.rs:44:22
   5:           0xbcf754 - core::fmt::rt::Argument::<'_>::fmt
                               at /home/r/src/rust/rustc.3/library/core/src/fmt/rt.rs:138:9
   6:           0x9b8f81 - std::fmt::write
                               at /home/r/src/rust/rustc.3/library/core/src/fmt/mod.rs:1094:17
   7:           0x4d0895 - <std::sys::unix::stdio::Stderr as std::io::Write>::write_fmt
                               at /home/r/src/rust/rustc.3/library/std/src/io/mod.rs:1714:15
   8:           0xba37b1 - std::sys_common::backtrace::_print
                               at /home/r/src/rust/rustc.3/library/std/src/sys_common/backtrace.rs:47:5
   9:           0xba365b - std::sys_common::backtrace::print
                               at /home/r/src/rust/rustc.3/library/std/src/sys_common/backtrace.rs:34:9
  10:           0x400bd4 - std::panic_hook_with_disk_dump::{closure#1}
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:278:22
  11:           0x144187 - std::panic_hook_with_disk_dump
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:312:9
  12:           0x143659 - std::panicking::default_hook
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:239:5
  13:           0x1482a7 - std::panicking::rust_panic_with_hook
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:729:13
  14:           0x40403b - std::panicking::begin_panic_handler::{closure#0}
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:619:13
  15:           0xe618b3 - std::sys_common::backtrace::__rust_end_short_backtrace::<[closure@std::panicking::begin_panic_handler::{closure#0}], !>
                               at /home/r/src/rust/rustc.3/library/std/src/sys_common/backtrace.rs:170:18
  16:           0x403fc8 - std::panicking::begin_panic_handler
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:617:5
  17:           0xee23e9 - core::panicking::panic_nounwind_fmt
                               at /home/r/src/rust/rustc.3/library/core/src/panicking.rs:96:14
  18:           0xee29e6 - core::panicking::panic_nounwind
                               at /home/r/src/rust/rustc.3/library/core/src/panicking.rs:126:5
  19:           0xee365e - core::panicking::panic_in_cleanup
                               at /home/r/src/rust/rustc.3/library/core/src/panicking.rs:206:5
  20:            0x2028a - main
                               at src/tools/miri/tests/fail/panic/double_panic.rs:13:1
  21:           0x3895ee - <fn() as std::ops::FnOnce<()>>::call_once - shim(fn())
                               at /home/r/src/rust/rustc.3/library/core/src/ops/function.rs:250:5
  22:           0xe61725 - std::sys_common::backtrace::__rust_begin_short_backtrace::<fn(), ()>
                               at /home/r/src/rust/rustc.3/library/std/src/sys_common/backtrace.rs:154:18
  23:           0x3fe9aa - std::rt::lang_start::<()>::{closure#0}
                               at /home/r/src/rust/rustc.3/library/std/src/rt.rs:166:18
  24:           0x389962 - std::ops::function::impls::<impl std::ops::FnOnce<()> for &dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe>::call_once
                               at /home/r/src/rust/rustc.3/library/core/src/ops/function.rs:284:13
  25:           0x4033b9 - std::panicking::try::do_call::<&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe, i32>
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:524:40
  26:           0x402d58 - std::panicking::try::<i32, &dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe>
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:488:19
  27:           0x337ff7 - std::panic::catch_unwind::<&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe, i32>
                               at /home/r/src/rust/rustc.3/library/std/src/panic.rs:142:14
  28:           0x3fe7e7 - std::rt::lang_start_internal::{closure#2}
                               at /home/r/src/rust/rustc.3/library/std/src/rt.rs:148:48
  29:           0x4033d6 - std::panicking::try::do_call::<[closure@std::rt::lang_start_internal::{closure#2}], isize>
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:524:40
  30:           0x402d7f - std::panicking::try::<isize, [closure@std::rt::lang_start_internal::{closure#2}]>
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:488:19
  31:           0x338028 - std::panic::catch_unwind::<[closure@std::rt::lang_start_internal::{closure#2}], isize>
                               at /home/r/src/rust/rustc.3/library/std/src/panic.rs:142:14
  32:           0x1418b0 - std::rt::lang_start_internal
                               at /home/r/src/rust/rustc.3/library/std/src/rt.rs:148:20
  33:           0x3fe9dc - std::rt::lang_start::<()>
                               at /home/r/src/rust/rustc.3/library/std/src/rt.rs:165:17
thread caused non-unwinding panic. aborting.
```
If we also land https://github.com/rust-lang/rust/pull/115020, the 2nd backtrace disappears, hopefully making the "panic in a destructor during cleanup" easier to see.

Fixes https://github.com/rust-lang/rust/issues/114954.
2023-08-25 08:47:18 +00:00
cui fliter
9c3f44f922 use the correct link
Signed-off-by: cui fliter <imcusg@gmail.com>
2023-08-25 15:45:41 +08:00
Guillaume Gomez
20768b270e Fix intra-doc links from pointer appearing in windows HANDLE type alias 2023-08-24 21:36:38 -07:00
Tobias Bucher
5e76e20d71 Remove special cases that are no longer needed due to #112606 2023-08-25 03:54:28 +02:00
Urgau
89800a27fc Lint on invalid UnsafeCell::raw_get with invalid_reference_casting lint 2023-08-24 15:00:21 +02:00
Ralf Jung
ddea3f981e document more things as needing to stay in sync 2023-08-24 13:28:26 +02:00
Ralf Jung
4c53783f3c when terminating during unwinding, show the reason why 2023-08-24 13:28:26 +02:00
bors
8a6b67f988 Auto merge of #115094 - Mark-Simulacrum:bootstrap-update, r=ozkanonur
Update bootstrap compiler to 1.73.0 beta
2023-08-24 11:10:52 +00:00
Mark Rousskov
0a916062aa Bump cfg(bootstrap) 2023-08-23 20:05:14 -04:00
Urgau
7ee77b5d1b Add support for ptr::write for the invalid_reference_casting lint 2023-08-22 15:47:29 +02:00
Mark Rousskov
c8522adb97 Replace version placeholders with 1.73.0 2023-08-22 06:57:00 -04:00
bors
795ade084a Auto merge of #113365 - dima74:diralik/add-deprecated-suggestions, r=workingjubilee
Add `suggestion` for some `#[deprecated]` items

Consider code:
```rust
fn main() {
    let _ = ["a", "b"].connect(" ");
}
```

Currently it shows deprecated warning:
```rust
warning: use of deprecated method `std::slice::<impl [T]>::connect`: renamed to join
 --> src/main.rs:2:24
  |
2 |     let _ = ["a", "b"].connect(" ");
  |                        ^^^^^^^
  |
  = note: `#[warn(deprecated)]` on by default
```

This PR adds `suggestion` for `connect` and some other deprecated items, so the warning will be changed to this:
```rust
warning: use of deprecated method `std::slice::<impl [T]>::connect`: renamed to join
 --> src/main.rs:2:24
  |
2 |     let _ = ["a", "b"].connect(" ");
  |                        ^^^^^^^
  |
  = note: `#[warn(deprecated)]` on by default
help: replace the use of the deprecated method
  |
2 |     let _ = ["a", "b"].join(" ");
  |                        ^^^^
```
2023-08-22 00:02:50 +00:00
Ralf Jung
0188b9cbb4 try to clarify wording 2023-08-21 13:54:03 +02:00
Dmitry Murzin
07b57f9a7a
Add suggestion for some #[deprecated] items 2023-08-21 12:51:51 +03:00
Matthias Krüger
2bca4b5913
Rollup merge of #115000 - RalfJung:custom-mir-call, r=compiler-errors,JakobDegen
custom_mir: change Call() terminator syntax to something more readable

I find our current syntax very hard to read -- I cannot even remember the order of arguments, and having the "next block" *before* the actual function call is very counter-intuitive IMO. So I suggest we use `Call(ret_val = function(v), next_block)` instead.

r? `@JakobDegen`
2023-08-20 08:34:05 +02:00
bors
9c699a40cc Auto merge of #113167 - ChAoSUnItY:redundant_explicit_link, r=GuillaumeGomez
rustdoc: Add lint `redundant_explicit_links`

Closes #87799.
- Lint warns by default
- Reworks link parser to cache original link's display text

r? `@jyn514`
2023-08-20 01:04:22 +00:00
Matthias Krüger
cad8f8cbff
Rollup merge of #114950 - xfix:inline-cstr-from-ptr, r=cuviper
Inline strlen_rt in CStr::from_ptr

This enables LLVM to optimize this function as if it was strlen (LLVM knows what it does, and can avoid calling it in certain situations) without having to enable std-aware LTO. This is essentially doing what https://github.com/rust-lang/rust/pull/90007 did, except updated for this function being `const`.

Pretty sure it's safe to roll-up, considering last time I did make this change it didn't affect performance (`CStr::from_ptr` isn't really used all that often in Rust code that is checked by rust-perf).
2023-08-20 00:28:31 +02:00
Ralf Jung
7a6346660e custom_mir: change Call() terminator syntax to something more readable 2023-08-19 22:41:33 +02:00
Kevin Reid
2c21635382 Add modulo and mod as doc aliases for rem_euclid.
When I was learning Rust I looked for “a modulo function” and couldn’t
find one, so thought I had to write my own; it wasn't at all obvious
that a function with “rem” in the name was the function I wanted.
Hopefully this will save the next learner from that.

However, it does have the disadvantage that the top results in rustdoc
for “mod” are now these aliases instead of the Rust keyword, which
probably isn't ideal.
2023-08-18 12:28:27 -07:00
Kevin Reid
2bccf1e296 Go into more detail about panicking in drop. 2023-08-18 07:48:10 -07:00
Kyle Lin
c4afb8a868 resolve conflicts 2023-08-18 15:22:58 +08:00
Kyle Lin
2ec3e297ab tidy doc link 2023-08-18 15:19:23 +08:00
Konrad Borowski
e94ba4ae78 Inline strlen_rt in CStr::from_ptr
This enables LLVM to optimize this function as if it was strlen
without having to enable std-aware LTO.
2023-08-18 09:19:09 +02:00
Matthias Krüger
503a8fc92d
Rollup merge of #114881 - RalfJung:cstr, r=cuviper
clarify CStr lack of layout guarnatees

Follow-up to https://github.com/rust-lang/rust/pull/114800
r? `@cuviper`
2023-08-17 08:39:22 +02:00
Matthias Krüger
2667d853a6
Rollup merge of #114784 - Urgau:many-improve-invalid_reference_casting-lint, r=est31
Improve `invalid_reference_casting` lint

This PR improves the `invalid_reference_casting` lint:
 - by considering an unlimited number of casts instead only const to mut ptr
 - by also considering ptr-to-integer and integer-to-ptr casts
 - by also taking into account [`ptr::cast`](https://doc.rust-lang.org/std/primitive.pointer.html#method.cast), [`ptr::cast`](https://doc.rust-lang.org/std/primitive.pointer.html#method.cast-1) and [`ptr::cast_const`](https://doc.rust-lang.org/std/primitive.pointer.html#method.cast_const)

Most of this improvements comes from skimming Github Code Search result for [`&mut \*.*as \*const`](https://github.com/search?q=lang%3Arust+%2F%26mut+%5C*.*as+%5C*const%2F&type=code)

r? ``@est31`` (maybe)
2023-08-16 20:10:37 +02:00
Ralf Jung
3e9679e861 clarify CStr lack of layout guarnatees 2023-08-16 09:37:06 +02:00
Ralf Jung
e7a1e4271d use mem::swap instead of ptr::swap_nonoverlapping 2023-08-16 08:47:06 +02:00
Matthias Krüger
6024ad1a05
Rollup merge of #114871 - schvv31n:fix-link-in-docs, r=scottmcm
Update the link in the docs of `std::intrinsics`

The previous link in that place, https://github.com/rust-lang/miri/blob/master/src/shims/intrinsics.rs, no longer points to an existing file.
2023-08-16 08:43:53 +02:00
Matthias Krüger
6f27032118
Rollup merge of #114861 - RalfJung:no-effect, r=wesleywiser
fix typo: affect -> effect

I just realized I made a silly typo when writing that comment...
2023-08-16 08:43:52 +02:00