Repository navigation
Fix mem::conjure_zst panic message to use any::type_name instead - #153073
Conversation
|
r? @joboet rustbot has assigned @joboet. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
|
cc @rust-lang/wg-const-eval |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| intrinsics::const_eval_select!( | ||
| @capture[T] { _marker: crate::marker::PhantomData<T> = crate::marker::PhantomData::<T> } -> (): | ||
| if const { | ||
| if size_of::<T>() != 0 { |
There was a problem hiding this comment.
It looks like you could use if size_of::<T>() != 0 first instead of having these repeated in const/non-const branches.
|
Reminder, once the PR becomes ready for a review, use |
This has the unfortunate effect of calling type_name even in const mode and then just ignoring the result... but I guess it is the easiest thing to do here. |
Since ZST-ness is known at compile time, the optimiser will in all likelihood remove all this for ZSTs anyway. |
|
Const-code doesn't get optimized, so there we will evaluate the intrinsic. But that's just a bit of unnecessary work in compilations that will fail due to a const-panic; doesn't seem worth much effort to fix that. |
|
I will have a look at it later today! |
This comment has been minimized.
This comment has been minimized.
|
Ralf/Joboet will say this as well, but make sure to squash all your commits into one commit! |
| let name = crate::any::type_name::<T>(); | ||
| const_assert!( | ||
| size_of::<T>() == 0, | ||
| "mem::conjure_zst invoked on a nonzero-sized type", | ||
| "mem::conjure_zst invoked on type {t}, which is not zero-sized", | ||
| t: &str = stringify!(T) | ||
| "mem::conjure_zst invoked on a non-zero-sized type", | ||
| "mem::conjure_zst invoked on type {name}, which is not zero-sized", | ||
| name: &str = name |
There was a problem hiding this comment.
| let name = crate::any::type_name::<T>(); | |
| const_assert!( | |
| size_of::<T>() == 0, | |
| "mem::conjure_zst invoked on a nonzero-sized type", | |
| "mem::conjure_zst invoked on type {t}, which is not zero-sized", | |
| t: &str = stringify!(T) | |
| "mem::conjure_zst invoked on a non-zero-sized type", | |
| "mem::conjure_zst invoked on type {name}, which is not zero-sized", | |
| name: &str = name | |
| const_assert!( | |
| size_of::<T>() == 0, | |
| "mem::conjure_zst invoked on a non-zero-sized type", | |
| "mem::conjure_zst invoked on type {name}, which is not zero-sized", | |
| name: &str = crate::any::type_name::<T>(), |
no need to call the intrinsic before the macro
(also GH seems to really destroy indentation with these suggestions... thanks GH)
f2a2a8b to
9092262
Compare
|
Looks good, thanks! |
…essage, r=RalfJung Fix mem::conjure_zst panic message to use any::type_name instead Use `crate::any::type_name::<T>()` instead of `stringify!(T)` in the runtime panic message of `conjure_zst` , so the actual type name (e.g. `i32`) is shown rather than the literal string `[T]`.
…essage, r=RalfJung Fix mem::conjure_zst panic message to use any::type_name instead Use `crate::any::type_name::<T>()` instead of `stringify!(T)` in the runtime panic message of `conjure_zst` , so the actual type name (e.g. `i32`) is shown rather than the literal string `[T]`.
…uwer Rollup of 11 pull requests Successful merges: - #151431 (Add new unstable attribute: `#[export_visibility = ...]`.) - #153012 (Stop using `LinkedGraph` in `lexical_region_resolve`) - #153179 (Force a CI LLVM stamp bump) - #150828 (Improved security section in rustdoc for `current_exe`) - #152673 (rustc_public: rewrite `bridge_impl` to reduce boilerplate) - #152674 (rustc_public: remove the `CrateDefItems` trait) - #153073 (Fix mem::conjure_zst panic message to use any::type_name instead) - #153117 (Remove mutation from macro path URL construction) - #153128 (Recover feature lang_items for emscripten) - #153138 (Print path root when printing path) - #153159 (Work around a false `err.emit();` type error in rust-analyzer)
…essage, r=RalfJung Fix mem::conjure_zst panic message to use any::type_name instead Use `crate::any::type_name::<T>()` instead of `stringify!(T)` in the runtime panic message of `conjure_zst` , so the actual type name (e.g. `i32`) is shown rather than the literal string `[T]`.
…uwer Rollup of 12 pull requests Successful merges: - #151143 (explicit tail calls: support indirect arguments) - #153012 (Stop using `LinkedGraph` in `lexical_region_resolve`) - #153175 (Clarify a confusing green-path function) - #153179 (Force a CI LLVM stamp bump) - #150828 (Improved security section in rustdoc for `current_exe`) - #152673 (rustc_public: rewrite `bridge_impl` to reduce boilerplate) - #152674 (rustc_public: remove the `CrateDefItems` trait) - #153073 (Fix mem::conjure_zst panic message to use any::type_name instead) - #153117 (Remove mutation from macro path URL construction) - #153128 (Recover feature lang_items for emscripten) - #153138 (Print path root when printing path) - #153159 (Work around a false `err.emit();` type error in rust-analyzer)
…uwer Rollup of 12 pull requests Successful merges: - #151143 (explicit tail calls: support indirect arguments) - #153012 (Stop using `LinkedGraph` in `lexical_region_resolve`) - #153175 (Clarify a confusing green-path function) - #153179 (Force a CI LLVM stamp bump) - #150828 (Improved security section in rustdoc for `current_exe`) - #152673 (rustc_public: rewrite `bridge_impl` to reduce boilerplate) - #152674 (rustc_public: remove the `CrateDefItems` trait) - #153073 (Fix mem::conjure_zst panic message to use any::type_name instead) - #153117 (Remove mutation from macro path URL construction) - #153128 (Recover feature lang_items for emscripten) - #153138 (Print path root when printing path) - #153159 (Work around a false `err.emit();` type error in rust-analyzer)
Rollup merge of #153073 - mehdiakiki:fix/conjure-zst-panic-message, r=RalfJung Fix mem::conjure_zst panic message to use any::type_name instead Use `crate::any::type_name::<T>()` instead of `stringify!(T)` in the runtime panic message of `conjure_zst` , so the actual type name (e.g. `i32`) is shown rather than the literal string `[T]`.
…uwer Rollup of 12 pull requests Successful merges: - rust-lang/rust#151143 (explicit tail calls: support indirect arguments) - rust-lang/rust#153012 (Stop using `LinkedGraph` in `lexical_region_resolve`) - rust-lang/rust#153175 (Clarify a confusing green-path function) - rust-lang/rust#153179 (Force a CI LLVM stamp bump) - rust-lang/rust#150828 (Improved security section in rustdoc for `current_exe`) - rust-lang/rust#152673 (rustc_public: rewrite `bridge_impl` to reduce boilerplate) - rust-lang/rust#152674 (rustc_public: remove the `CrateDefItems` trait) - rust-lang/rust#153073 (Fix mem::conjure_zst panic message to use any::type_name instead) - rust-lang/rust#153117 (Remove mutation from macro path URL construction) - rust-lang/rust#153128 (Recover feature lang_items for emscripten) - rust-lang/rust#153138 (Print path root when printing path) - rust-lang/rust#153159 (Work around a false `err.emit();` type error in rust-analyzer)
…uwer Rollup of 12 pull requests Successful merges: - rust-lang/rust#151143 (explicit tail calls: support indirect arguments) - rust-lang/rust#153012 (Stop using `LinkedGraph` in `lexical_region_resolve`) - rust-lang/rust#153175 (Clarify a confusing green-path function) - rust-lang/rust#153179 (Force a CI LLVM stamp bump) - rust-lang/rust#150828 (Improved security section in rustdoc for `current_exe`) - rust-lang/rust#152673 (rustc_public: rewrite `bridge_impl` to reduce boilerplate) - rust-lang/rust#152674 (rustc_public: remove the `CrateDefItems` trait) - rust-lang/rust#153073 (Fix mem::conjure_zst panic message to use any::type_name instead) - rust-lang/rust#153117 (Remove mutation from macro path URL construction) - rust-lang/rust#153128 (Recover feature lang_items for emscripten) - rust-lang/rust#153138 (Print path root when printing path) - rust-lang/rust#153159 (Work around a false `err.emit();` type error in rust-analyzer)
…uwer Rollup of 12 pull requests Successful merges: - rust-lang/rust#151143 (explicit tail calls: support indirect arguments) - rust-lang/rust#153012 (Stop using `LinkedGraph` in `lexical_region_resolve`) - rust-lang/rust#153175 (Clarify a confusing green-path function) - rust-lang/rust#153179 (Force a CI LLVM stamp bump) - rust-lang/rust#150828 (Improved security section in rustdoc for `current_exe`) - rust-lang/rust#152673 (rustc_public: rewrite `bridge_impl` to reduce boilerplate) - rust-lang/rust#152674 (rustc_public: remove the `CrateDefItems` trait) - rust-lang/rust#153073 (Fix mem::conjure_zst panic message to use any::type_name instead) - rust-lang/rust#153117 (Remove mutation from macro path URL construction) - rust-lang/rust#153128 (Recover feature lang_items for emscripten) - rust-lang/rust#153138 (Print path root when printing path) - rust-lang/rust#153159 (Work around a false `err.emit();` type error in rust-analyzer)
…rfonthey Stabilize `mem::conjure_zst` Tracking issue: rust-lang#95383 --- Stabilized API: ```rust pub const unsafe fn conjure_zst<T>() -> T; ``` The notable thing about this implementation is that if this function is called at run time (as opposed to in consteval), then the function will panic at run time (as opposed to at compile time) if `T` is not a ZST. If the function panics in consteval, the panic message is a fixed literal string. If the function panics at run time, the panic message includes the `type_name` of `T`. Note that [`type_name`](https://doc.rust-lang.org/nightly/std/any/fn.type_name.html) is currently [unstable in const](rust-lang#63084). --- Implementation history: * rust-lang#95385 (attempted to add the API without an ACP, and then the PR was closed) * rust-lang/libs-team#292 (The ACP. It has a lot of additional context and discussion, including the explanation of why this is needed) * rust-lang#146479 (the actual implementation) * rust-lang#153073 (changes the panic message) * rust-lang#155840 (internal implementation change)
Rollup merge of #161710 - theemathas:stab-conjure-zst, r=clarfonthey Stabilize `mem::conjure_zst` Tracking issue: #95383 --- Stabilized API: ```rust pub const unsafe fn conjure_zst<T>() -> T; ``` The notable thing about this implementation is that if this function is called at run time (as opposed to in consteval), then the function will panic at run time (as opposed to at compile time) if `T` is not a ZST. If the function panics in consteval, the panic message is a fixed literal string. If the function panics at run time, the panic message includes the `type_name` of `T`. Note that [`type_name`](https://doc.rust-lang.org/nightly/std/any/fn.type_name.html) is currently [unstable in const](#63084). --- Implementation history: * #95385 (attempted to add the API without an ACP, and then the PR was closed) * rust-lang/libs-team#292 (The ACP. It has a lot of additional context and discussion, including the explanation of why this is needed) * #146479 (the actual implementation) * #153073 (changes the panic message) * #155840 (internal implementation change)
Stabilize `mem::conjure_zst` Tracking issue: rust-lang/rust#95383 --- Stabilized API: ```rust pub const unsafe fn conjure_zst<T>() -> T; ``` The notable thing about this implementation is that if this function is called at run time (as opposed to in consteval), then the function will panic at run time (as opposed to at compile time) if `T` is not a ZST. If the function panics in consteval, the panic message is a fixed literal string. If the function panics at run time, the panic message includes the `type_name` of `T`. Note that [`type_name`](https://doc.rust-lang.org/nightly/std/any/fn.type_name.html) is currently [unstable in const](rust-lang/rust#63084). --- Implementation history: * rust-lang/rust#95385 (attempted to add the API without an ACP, and then the PR was closed) * rust-lang/libs-team#292 (The ACP. It has a lot of additional context and discussion, including the explanation of why this is needed) * rust-lang/rust#146479 (the actual implementation) * rust-lang/rust#153073 (changes the panic message) * rust-lang/rust#155840 (internal implementation change)
…nathanBrouwer Rollup of 12 pull requests Successful merges: - rust-lang#151143 (explicit tail calls: support indirect arguments) - rust-lang#153012 (Stop using `LinkedGraph` in `lexical_region_resolve`) - rust-lang#153175 (Clarify a confusing green-path function) - rust-lang#153179 (Force a CI LLVM stamp bump) - rust-lang#150828 (Improved security section in rustdoc for `current_exe`) - rust-lang#152673 (rustc_public: rewrite `bridge_impl` to reduce boilerplate) - rust-lang#152674 (rustc_public: remove the `CrateDefItems` trait) - rust-lang#153073 (Fix mem::conjure_zst panic message to use any::type_name instead) - rust-lang#153117 (Remove mutation from macro path URL construction) - rust-lang#153128 (Recover feature lang_items for emscripten) - rust-lang#153138 (Print path root when printing path) - rust-lang#153159 (Work around a false `err.emit();` type error in rust-analyzer)
…uwer Rollup of 12 pull requests Successful merges: - rust-lang/rust#151143 (explicit tail calls: support indirect arguments) - rust-lang/rust#153012 (Stop using `LinkedGraph` in `lexical_region_resolve`) - rust-lang/rust#153175 (Clarify a confusing green-path function) - rust-lang/rust#153179 (Force a CI LLVM stamp bump) - rust-lang/rust#150828 (Improved security section in rustdoc for `current_exe`) - rust-lang/rust#152673 (rustc_public: rewrite `bridge_impl` to reduce boilerplate) - rust-lang/rust#152674 (rustc_public: remove the `CrateDefItems` trait) - rust-lang/rust#153073 (Fix mem::conjure_zst panic message to use any::type_name instead) - rust-lang/rust#153117 (Remove mutation from macro path URL construction) - rust-lang/rust#153128 (Recover feature lang_items for emscripten) - rust-lang/rust#153138 (Print path root when printing path) - rust-lang/rust#153159 (Work around a false `err.emit();` type error in rust-analyzer)
Use
crate::any::type_name::<T>()instead ofstringify!(T)in theruntime panic message of
conjure_zst, so the actual type name (e.g.i32) is shown rather than the literal string[T].