Commit Graph

10374 Commits

Author SHA1 Message Date
Mara Bos
67bb7ba3ea Don't re-export private/unstable ArgumentV1 from alloc. 2023-01-29 20:15:02 +01:00
bors
c62665e09c Auto merge of #107328 - matthiaskrgr:rollup-lfqwo0o, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #106904 (Preserve split DWARF files when building archives.)
 - #106971 (Handle diagnostics customization on the fluent side (for one specific diagnostic))
 - #106978 (Migrate mir_build's borrow conflicts)
 - #107150 (`ty::tls` cleanups)
 - #107168 (Use a type-alias-impl-trait in `ObligationForest`)
 - #107189 (Encode info for Adt in a single place.)
 - #107322 (Custom mir: Add support for some remaining, easy to support constructs)
 - #107323 (Disable ConstGoto opt in cleanup blocks)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-01-26 15:58:08 +00:00
Matthias Krüger
c87996a8ad
Rollup merge of #107322 - JakobDegen:custom-mir, r=tmiasko
Custom mir: Add support for some remaining, easy to support constructs

Some documentation for previous changes and support for `Deinit`, checked binops, len, and array repetition

r? ```@oli-obk``` or ```@tmiasko```
2023-01-26 15:02:22 +01:00
bors
3e97763872 Auto merge of #106745 - m-ou-se:format-args-ast, r=oli-obk
Move format_args!() into AST (and expand it during AST lowering)

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

This moves FormatArgs from rustc_builtin_macros to rustc_ast_lowering. For now, the end result is the same. But this allows for future changes to do smarter things with format_args!(). It also allows Clippy to directly access the ast::FormatArgs, making things a lot easier.

This change turns the format args types into lang items. The builtin macro used to refer to them by their path. After this change, the path is no longer relevant, making it easier to make changes in `core`.

This updates clippy to use the new language items, but this doesn't yet make clippy use the ast::FormatArgs structure that's now available. That should be done after this is merged.
2023-01-26 12:44:47 +00:00
Jakob Degen
d7f59e91e0 Custom mir: Add support for some remaining, easy to support constructs 2023-01-26 03:29:28 -08:00
bors
40fda7b3fe Auto merge of #107318 - matthiaskrgr:rollup-776kd81, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #97373 (impl DispatchFromDyn for Cell and UnsafeCell)
 - #106625 (Remove backwards compat for LLVM 12 coverage format)
 - #106779 (Avoid __cxa_thread_atexit_impl on Emscripten)
 - #106811 (Append .dwp to the binary filename instead of replacing the existing extension.)
 - #106836 (Remove optimistic spinning from `mpsc::SyncSender`)
 - #106946 (implement Hash for proc_macro::LineColumn)
 - #107074 (remove unnecessary check for opaque types)
 - #107287 (Improve fn pointer notes)
 - #107304 (Use `can_eq` to compare types for default assoc type error)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-01-26 09:14:05 +00:00
Matthias Krüger
d667105681
Rollup merge of #106946 - dtolnay:hashlinecolumn, r=m-ou-se
implement Hash for proc_macro::LineColumn

For use in `HashMap<LineColumn, TokenTree>` or `HashMap<LineColumn, Comment>`, for example.

[Here is an example of one case complicated by the absence of this impl.](71bc45e417/src/comments.rs (L25-L34))

Tracking issue: https://github.com/rust-lang/rust/issues/54725
2023-01-26 07:53:24 +01:00
Matthias Krüger
35a8d6fea4
Rollup merge of #106836 - ibraheemdev:sync-sender-spin, r=Amanieu
Remove optimistic spinning from `mpsc::SyncSender`

Per https://github.com/rust-lang/rust/pull/106701#issuecomment-1381649679.
Closes #106804

r? `@Amanieu`
2023-01-26 07:53:23 +01:00
Matthias Krüger
cc92bdb9c9
Rollup merge of #106779 - RReverser:patch-2, r=Mark-Simulacrum
Avoid __cxa_thread_atexit_impl on Emscripten

 - Fixes https://github.com/rust-lang/rust/issues/91628.
 - Fixes https://github.com/emscripten-core/emscripten/issues/15722.

See discussion in both issues.

The TL;DR is that weak linkage causes LLVM to produce broken Wasm, presumably due to pointer mismatch. The code is casting a void pointer to a function pointer with specific signature, but Wasm is very strict about function pointer compatibility, so the resulting code is invalid.

Ideally LLVM should catch this earlier in the process rather than emit invalid Wasm, but it currently doesn't and this is an easy and valid fix, given that Emcripten doesn't have `__cxa_thread_atexit_impl` these days anyway.

Unfortunately, I can't add a regression test as even after looking into this issue for a long time, I couldn't reproduce it with any minimal Rust example, only with extracted LLVM IR or on a large project involving Rust + C++.
2023-01-26 07:53:22 +01:00
Matthias Krüger
e0d71f500c
Rollup merge of #97373 - dimpolo:cell_dispatch_from_dyn, r=dtolnay
impl DispatchFromDyn for Cell and UnsafeCell

After some fruitful discussion on [Internals](https://internals.rust-lang.org/t/impl-dispatchfromdyn-for-cell-2/16520) here's my first PR to rust-lang/rust 🎉

Please let me know if there's something I missed.

This adds `DispatchFromDyn` impls for `Cell`, `UnsafeCell` and `SyncUnsafeCell`.
An existing test is also expanded to test the `Cell` impl (which requires the `UnsafeCell` impl)

The different `RefCell` types can not implement `DispatchFromDyn` since they have more than one (non ZST) field.

&nbsp;

**Edit:**
### What:
These changes allow one to make types like `MyRc`(code below), to be object safe method receivers after implementing `DispatchFromDyn` and `Deref` for them.

This allows for code like this:
```rust
struct MyRc<T: ?Sized>(Cell<NonNull<RcBox<T>>>);

/* impls for DispatchFromDyn, CoerceUnsized and Deref for MyRc*/

trait Trait {
    fn foo(self: MyRc<Self>);
}

let impls_trait = ...;
let rc = MyRc::new(impls_trait) as MyRc<dyn Trait>;
rc.foo();
```

Note: `Cell` and `UnsafeCell` won't directly become valid method receivers since they don't implement `Deref`. Making use of these changes requires a wrapper type and nightly features.

### Why:
A custom pointer type with interior mutability allows one to store extra information in the pointer itself.
These changes allow for such a type to be a method receiver.

### Examples:
My use case is a cycle aware custom `Rc` implementation that when dropping a cycle marks some references dangling.

On the [forum](https://internals.rust-lang.org/t/impl-dispatchfromdyn-for-cell/14762/8) andersk mentioned that they track if a `Gc` reference is rooted with an extra bit in the reference itself.
2023-01-26 07:53:21 +01:00
Matthias Krüger
8ae5116fae
Rollup merge of #106407 - mejrs:attr_check, r=compiler-errors
Improve proc macro attribute diagnostics

Closes https://github.com/rust-lang/rust/issues/102923
2023-01-26 06:15:23 +01:00
Matthias Krüger
22e62a4fca
Rollup merge of #106944 - Nilstrieb:there-once-was-a-diagnostic, r=WaffleLapkin
Suggest using a lock for `*Cell: Sync` bounds

I mostly did this for `OnceCell<T>` at first because users will be confused to see that the `OnceCell<T>` in `std` isn't `Sync` but then extended it to `Cell<T>` and `RefCell<T>` as well.
2023-01-25 22:19:52 +01:00
Dylan DPC
24066910ca
Rollup merge of #107223 - ChayimFriedman2:patch-5, r=WaffleLapkin
`sub_ptr()` is equivalent to `usize::try_from().unwrap_unchecked()`, not `usize::from().unwrap_unchecked()`

`usize::from()` gives a `usize`, not `Result<usize>`, and `usize: From<isize>` is not implemented.
2023-01-25 17:01:43 +05:30
Dylan DPC
0c53b215de
Rollup merge of #106823 - m-ou-se:format-args-as-str-guarantees, r=dtolnay
Allow fmt::Arguments::as_str() to return more Some(_).

This adjusts the documentation to allow optimization of format_args!() to be visible through fmt::Arguments::as_str().

This allows for future changes like https://github.com/rust-lang/rust/pull/106824.
2023-01-25 17:01:42 +05:30
Dylan DPC
9e6873f788
Rollup merge of #106767 - chbaker0:disable-unstable-features, r=Mark-Simulacrum
Allow setting CFG_DISABLE_UNSTABLE_FEATURES to 0

Two locations check whether this build-time environment variable is defined. Allowing it to be explicitly disabled with a "0" value is useful, especially for integrating with external build systems.
2023-01-25 17:01:41 +05:30
dimi
a2d1cb2c22 impl DispatchFromDyn for Cell and UnsafeCell 2023-01-24 12:06:12 +01:00
Chayim Refael Friedman
236f8231a6
sub_ptr() is equivalent to usize::try_from().unwrap_unchecked(), not usize::from().unwrap_unchecked().
`usize::from()` gives a `usize`, not `Result<usize>`, and `usize: From<isize>` is not implemented.
2023-01-23 14:42:32 +02:00
Yuki Okushi
8709c395a6
Rollup merge of #107109 - est31:thin_box_link, r=Mark-Simulacrum
ThinBox: Add intra-doc-links for Metadata
2023-01-23 19:30:00 +09:00
Dylan DPC
28081a6aa6
Rollup merge of #106854 - steffahn:drop_linear_arc_rebased, r=Mark-Simulacrum
Add `Arc::into_inner` for safely discarding `Arc`s without calling the destructor on the inner type.

ACP: rust-lang/libs-team#162

Reviving #79665.

I want to get this merged this time; this does not contain changes (apart from very minor changes in comments/docs).

See #79665 for further description of the PR. The only “unresolved” points that led to that PR being closed, AFAICT, were

* The desire to also implement a `Rc::into_inner` function
  * however, this can very well also happen as a subsequent PR
* Possible need for further discussion on the naming “`into_inner`” (?)
  * `into_inner` seems fine to me; also, this PR introduces unstable API, and names can be changed later, too
* ~~I don't know if a tracking issue for the feature flag is supposed to be opened before or after this PR gets merged (if *before*, then I can add the issue number to the `#[unstable…]` attribute)~~ There is a [tracking issue](https://github.com/rust-lang/rust/issues/106894) now.

I say “unresolved” in quotation marks because from my point of view, if reviewers agree, the PR can be merged immediately and as-is :-)
2023-01-23 11:52:04 +05:30
bors
d3322e2773 Auto merge of #106981 - joboet:std_remove_box_syntax, r=thomcc
Do not use box syntax in `std`

See #94970 and #49733. About half of the `box` instances in `std` do not even need to allocate, the other half can simply be replaced with `Box::new`.

`@rustbot` label +T-libs
r? rust-lang/libs
2023-01-23 01:05:56 +00:00
Matthias Krüger
2f7a3a1f0a
Rollup merge of #107180 - nvzqz:rm-fmt-ref, r=joshtriplett
Remove unnecessary `&format!`

These were likely from before the `PartialEq<str>` impl for `&String`.
2023-01-22 11:43:09 +01:00
Matthias Krüger
17b9f2a7ed
Rollup merge of #107114 - Erk-:add-absolute-note-to-path-join, r=m-ou-se
Add note about absolute paths to Path::join

The note already exists on `PathBuf::push`, but I think it is good to have it on `Path::join` as well since it can cause issues if you are not careful with your input.
2023-01-22 11:43:06 +01:00
Michael Goulet
d1405c82b8
Rollup merge of #106144 - tgross35:patch-1, r=Mark-Simulacrum
Improve the documentation of `black_box`

There don't seem to be many great resources on how `black_box` should be used, so I added some information here
2023-01-21 23:20:59 -05:00
Nikolai Vazquez
734a91358b Remove unnecessary &format!
These were likely from before the `PartialEq<str>` impl for `&String`.
2023-01-21 22:06:42 -05:00
Frank Steffahn
33696fa9ca Add Arc::into_inner for safely discarding Arcs without calling the destructor on the inner type.
Mainly rebased and squashed from PR rust-lang/rust#79665,
furthermore includes minor changes in comments.
2023-01-22 01:43:25 +09:00
Michael Goulet
68b390ae2a
Rollup merge of #104672 - Voultapher:unify-sort-modules, r=thomcc
Unify stable and unstable sort implementations in same core module

This moves the stable sort implementation to the core::slice::sort module. By virtue of being in core it can't access `Vec`. The two `Vec` used by merge sort, `buf` and `runs`, are modelled as custom types that implement the very limited required `Vec` interface with the help of provided allocation and free functions. This is done to allow future re-use of functions and logic between stable and unstable sort. Such as `insert_head`.

This is in preparation of #100856 and #104116. It only moves code, it *doesn't* change any of the sort related logic. This unlocks the ability to share `insert_head`, `insert_tail`, `swap_if_less` `merge` and more.

Tagging ````@Mark-Simulacrum```` I hope this allows progress on #100856, by moving `merge_sort` here I hope future changes will be easier to review.
2023-01-20 21:33:21 -05:00
Valdemar Erk
d8f8adfe3d add example of joining with a absolute path 2023-01-20 12:03:43 +01:00
Valdemar Erk
ec3da87582 Add note about absolute paths to Path::join 2023-01-20 11:16:38 +01:00
est31
4127988317 ThinBox: Add intra-doc-links for Metadata 2023-01-20 08:07:45 +01:00
Matthias Krüger
66a9006759
Rollup merge of #107067 - tmiasko:custom-mir-storage-statements, r=oli-obk
Custom MIR: Support storage statements

r? `@oli-obk` `@JakobDegen`
2023-01-20 07:16:11 +01:00
Matthias Krüger
35d488f23d
Rollup merge of #107053 - devnexen:sigstringrepr_haiku, r=thomcc
signal update string representation for haiku.
2023-01-20 07:16:10 +01:00
Nilstrieb
6d0c91fda3 Add rustc_on_unimplemented on Sync for cell types
Suggest using a lock instead.
2023-01-19 21:09:25 +01:00
Nilstrieb
e1f630f23d Add OnceCell<T>: !Sync impl for diagnostics 2023-01-19 20:14:21 +01:00
bors
79335f1ac4 Auto merge of #107064 - GuillaumeGomez:rollup-pbgu6r3, r=GuillaumeGomez
Rollup of 5 pull requests

Successful merges:

 - #105977 (Transform async `ResumeTy` in generator transform)
 - #106927 (make `CastError::NeedsDeref` create a `MachineApplicable` suggestion)
 - #106931 (document + UI test `E0208` and make its output more user-friendly)
 - #107027 (Remove extra removal from test path)
 - #107037 (Fix Dominators::rank_partial_cmp to match documentation)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-01-19 11:12:31 +00:00
Tomasz Miąsko
ca3d55e32d Custom MIR: Support storage statements 2023-01-19 11:53:33 +01:00
bors
705a96d39b Auto merge of #106989 - clubby789:is-zero-num, r=scottmcm
Implement `alloc::vec::IsZero` for `Option<$NUM>` types

Fixes #106911

Mirrors the `NonZero$NUM` implementations with an additional `assert_zero_valid`.
`None::<i32>` doesn't stricly satisfy `IsZero` but for the purpose of allocating we can produce more efficient codegen.
2023-01-19 08:04:26 +00:00
Arpad Borsos
96931a787a
Transform async ResumeTy in generator transform
- Eliminates all the `get_context` calls that async lowering created.
- Replace all `Local` `ResumeTy` types with `&mut Context<'_>`.

The `Local`s that have their types replaced are:
- The `resume` argument itself.
- The argument to `get_context`.
- The yielded value of a `yield`.

The `ResumeTy` hides a `&mut Context<'_>` behind an unsafe raw pointer, and the
`get_context` function is being used to convert that back to a `&mut Context<'_>`.

Ideally the async lowering would not use the `ResumeTy`/`get_context` indirection,
but rather directly use `&mut Context<'_>`, however that would currently
lead to higher-kinded lifetime errors.
See <https://github.com/rust-lang/rust/issues/105501>.

The async lowering step and the type / lifetime inference / checking are
still using the `ResumeTy` indirection for the time being, and that indirection
is removed here. After this transform, the generator body only knows about `&mut Context<'_>`.
2023-01-19 09:03:05 +01:00
David Carlier
ae9e66bafb signal update string representation for haiku. 2023-01-18 23:06:59 +00:00
clubby789
50e9f2e6e8 Update IsZero documentation 2023-01-18 15:48:53 +00:00
clubby789
b94a29a25f Implement alloc::vec::IsZero for Option<$NUM> types 2023-01-18 15:15:15 +00:00
Dylan DPC
1ff4a1259d
Rollup merge of #106950 - the8472:fix-splice-miri, r=cuviper
Don't do pointer arithmetic on pointers to deallocated memory

vec::Splice can invalidate the slice::Iter inside vec::Drain. So we replace them with dangling pointers which, unlike ones to deallocated memory, are allowed.

Fixes miri test failures.
Fixes https://github.com/rust-lang/miri/issues/2759
2023-01-18 15:55:38 +05:30
Dylan DPC
548ae602fc
Rollup merge of #106441 - mllken:abstract-socket-noref, r=joshtriplett
relax reference requirement on SocketAddrExt::from_abstract_name

Reference: https://github.com/rust-lang/rust/issues/85410#issuecomment-1369544671
2023-01-18 15:55:37 +05:30
Dylan DPC
d6ea99d2ed
Rollup merge of #103702 - WaffleLapkin:lift-sized-bounds-from-pointer-methods-where-applicable, r=m-ou-se
Lift `T: Sized` bounds from some `strict_provenance` pointer methods

This PR removes requirement for `T` (pointee type) to be `Sized` to call `pointer::{addr, expose_addr, with_addr, map_addr}`. These functions don't use `T`'s size, so there is no reason for them to require this. Updated public API:

cc ``@Gankra,`` #95228
r? libs-api
2023-01-18 15:55:36 +05:30
Matthias Krüger
788671c1c6
Rollup merge of #106997 - Sp00ph:introselect, r=scottmcm
Add heapsort fallback in `select_nth_unstable`

Addresses #102451 and #106933.

`slice::select_nth_unstable` uses a quick select implementation based on the same pattern defeating quicksort algorithm that `slice::sort_unstable` uses. `slice::sort_unstable` uses a recursion limit and falls back to heapsort if there were too many bad pivot choices, to ensure O(n log n) worst case running time (known as introsort). However, `slice::select_nth_unstable` does not have such a fallback strategy, which leads to it having a worst case running time of O(n²) instead. #102451 links to a playground which generates pathological inputs that show this quadratic behavior. On my machine, a randomly generated slice of length `1 << 19` takes ~200µs to calculate its median, whereas a pathological input of the same length takes over 2.5s. This PR adds an iteration limit to `select_nth_unstable`, falling back to heapsort, which ensures an O(n log n) worst case running time (introselect). With this change, there was no noticable slowdown for the random input, but the same pathological input now takes only ~1.2ms. In the future it might be worth implementing something like Median of Medians or Fast Deterministic Selection instead, which guarantee O(n) running time for all possible inputs. I've left this as a `FIXME` for now and only implemented the heapsort fallback to minimize the needed code changes.

I still think we should clarify in the `select_nth_unstable` docs that the worst case running time isn't currently O(n) (the original reason that #102451 was opened), but I think it's a lot better to be able to guarantee O(n log n) instead of O(n²) for the worst case.
2023-01-18 06:59:22 +01:00
Matthias Krüger
47ccca0c86
Rollup merge of #106992 - joboet:alloc_remove_box_syntax, r=thomcc
Remove unused `#![feature(box_syntax)]` in `alloc`
2023-01-18 06:59:21 +01:00
The 8472
47014b1bb9 Don't do pointer arithmetic on pointers to deallocated memory
vec::Splice can invalidate the slice::Iter inside vec::Drain.
So we replace them with dangling pointers which, unlike ones to
deallocated memory, are allowed.
2023-01-17 22:01:33 +01:00
Matthias Krüger
0ed2549802
Rollup merge of #106889 - scottmcm:windows-mut, r=cuviper
Mention the lack of `windows_mut` in `windows`

This is a common request, going back to at least 2015 (#23783), so mention in the docs that it can't be done and offer a workaround using <https://doc.rust-lang.org/std/cell/struct.Cell.html#method.as_slice_of_cells>.

(See also URLO threads like <https://internals.rust-lang.org/t/a-windows-mut-method-on-slice/16941/10?u=scottmcm>.)
2023-01-17 20:21:27 +01:00
Markus Everling
273c6c3913 Add heapsort fallback in select_nth_unstable 2023-01-17 19:38:37 +01:00
joboet
be9c363066
refactor[alloc]: remove unused box syntax feature 2023-01-17 18:55:44 +01:00
Dylan DPC
1b2d595c14
Rollup merge of #106922 - ChayimFriedman2:patch-5, r=workingjubilee
Avoid unsafe code in `to_ascii_[lower/upper]case()`
2023-01-17 20:33:04 +05:30