rust/library/core/tests
bors 4cea2bc339 Auto merge of #113464 - waynr:remove-provider-trait, r=Amanieu
core/any: remove Provider trait, rename Demand to Request

This touches on two WIP features:

* `error_generic_member_access`
  * tracking issue: https://github.com/rust-lang/rust/issues/99301
  * RFC (WIP): https://github.com/rust-lang/rfcs/pull/2895
* `provide_any`
  * tracking issue: https://github.com/rust-lang/rust/issues/96024
  * RFC: https://github.com/rust-lang/rfcs/pull/3192

The changes in this PR are intended to address libs meeting feedback summarized by `@Amanieu` in https://github.com/rust-lang/rust/issues/96024#issuecomment-1554773172

The specific items this PR addresses so far are:

> We feel that the names "demand" and "request" are somewhat synonymous and would like only one of those to be used for better consistency.

I went with `Request` here since it sounds nicer, but I'm mildly concerned that at first glance it could be confused with the use of the word in networking context.

> The Provider trait should be deleted and its functionality should be merged into Error. We are happy to only provide an API that is only usable with Error. If there is demand for other uses then this can be provided through an external crate.

The net impact this PR has is that examples which previously looked like
```
    core::any::request_ref::<String>(&err).unwramp()
```

now look like
```
    (&err as &dyn core::error::Error).request_value::<String>().unwrap()
```

These are methods that based on the type hint when called return an `Option<T>` of that type. I'll admit I don't fully understand how that's done, but it involves `core::any::tags::Type` and `core::any::TaggedOption`, neither of which are exposed in the public API, to construct a `Request` which is then passed to the `Error.provide` method.

Something that I'm curious about is whether or not they are essential to the use of `Request` types (prior to this PR referred to as `Demand`) and if so does the fact that they are kept private imply that `Request`s are only meant to be constructed privately within the standard library? That's what it looks like to me.

These methods ultimately call into code that looks like:
```
/// Request a specific value by tag from the `Error`.
fn request_by_type_tag<'a, I>(err: &'a (impl Error + ?Sized)) -> Option<I::Reified>
where
    I: tags::Type<'a>,
{
    let mut tagged = core::any::TaggedOption::<'a, I>(None);
    err.provide(tagged.as_request());
    tagged.0
}
```

As far as the `Request` API is concerned, one suggestion I would like to make is that the previous example should look more like this:
```
/// Request a specific value by tag from the `Error`.
fn request_by_type_tag<'a, I>(err: &'a (impl Error + ?Sized)) -> Option<I::Reified>
where
    I: tags::Type<'a>,
{
    let tagged_request = core::any::Request<I>::new_tagged();
    err.provide(tagged_request);
    tagged.0
}
```
This makes it possible for anyone to construct a `Request` for use in their own projects without exposing an implementation detail like `TaggedOption` in the API surface.

Otherwise noteworthy is that I had to add `pub(crate)` on both `core::any::TaggedOption` and `core::any::tags` since `Request`s now need to be constructed in the `core::error` module. I considered moving `TaggedOption` into the `core::error` module but again I figured it's an implementation detail of `Request` and belongs closer to that.

At the time I am opening this PR, I have not yet looked into the following bit of feedback:

> We took a look at the generated code and found that LLVM is unable to optimize multiple .provide_* calls into a switch table because each call fetches the type id from Erased::type_id separately each time and the compiler doesn't know that these calls all return the same value. This should be fixed.

This is what I'll focus on next while waiting for feedback on the progress so far. I suspect that learning more about the type IDs will help me understand the need for `TaggedOption` a little better.
2023-08-14 18:18:03 +00:00
..
fmt
hash
iter Add Iterator::map_windows 2023-08-11 07:26:51 +08:00
net Fix SocketAddrV6: Display tests 2023-06-14 15:21:15 -04:00
num Auto merge of #92048 - Urgau:num-midpoint, r=scottmcm 2023-05-14 19:33:02 +00:00
ops
panic
alloc.rs
any.rs core/any: remove Provider trait 2023-08-13 13:07:53 -06:00
array.rs ignore core, alloc and test tests that require unwinding on panic=abort 2023-06-13 15:53:24 +02:00
ascii.rs
asserting.rs
atomic.rs
bool.rs
cell.rs
char.rs
clone.rs Bump to latest beta compiler 2023-05-30 08:00:10 -04:00
cmp.rs
const_ptr.rs
convert.rs
error.rs core/any: remove Provider trait 2023-08-13 13:07:53 -06:00
future.rs enable test_join test in Miri 2023-07-03 14:05:55 +02:00
intrinsics.rs
lazy.rs
lib.rs Auto merge of #113464 - waynr:remove-provider-trait, r=Amanieu 2023-08-14 18:18:03 +00:00
macros.rs
manually_drop.rs Flip cfg's for bootstrap bump 2023-07-12 21:38:55 -04:00
mem.rs Bump to latest beta compiler 2023-05-30 08:00:10 -04:00
nonzero.rs
ops.rs
option.rs
panic.rs
pattern.rs
pin_macro.rs
pin.rs
ptr.rs Extend unused_must_use to cover block exprs 2023-06-15 17:59:13 +08:00
result.rs
simd.rs
slice.rs Add more comprehensive tests for is_sorted and friends 2023-06-16 03:04:34 -04:00
str_lossy.rs
str.rs
task.rs
time.rs
tuple.rs
unicode.rs
waker.rs