EmbarkStudios/rust-gpu

Panicking in a #[track_caller] function fails to compile

beepster4096 opened this issue · 2 comments

Expected Behaviour

Successful compilation

Example & Steps To Reproduce

#![no_std]

#[track_caller]
fn panic() {
    panic!("owo")
}

#[spirv_std::spirv(fragment)]
pub fn main() {
    panic();
}

produces

error: function pointer types are not allowed
   --> 
C:\Users\DrMeepster\.rustup\toolchains\nightly-2023-03-04-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\fmt\mod.rs:401:5
    |
401 |     pub const fn new_v1(pieces: &'a [&'static str], args: &'a [ArgumentV1<'a>]) -> Arguments<'a> {
    |     ^
    |

error: cannot cast between pointer types
       from `*struct core::option::Option<&[core::fmt::rt::v1::Argument]> { *[struct core::fmt::rt::v1::Argument { position: u32, 
format: struct core::fmt::rt::v1::FormatSpec { precision: struct core::fmt::rt::v1::Count { u32, u32 }, width: struct 
core::fmt::rt::v1::Count { u32, u32 }, flags: u32, fill: u32, align: u8 } }], u32 }`
         to `**struct fn(&[&'static str], &[core::fmt::ArgumentV1<'_>]) -> core::fmt::Arguments<'_> 
{core::fmt::Arguments::<'_>::new_v1} {  }`
   --> 
C:\Users\DrMeepster\.rustup\toolchains\nightly-2023-03-04-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\fmt\mod.rs:405:34
    |
405 |         Arguments { pieces, fmt: None, args }
    |                                  ^
    |

error: cannot cast between pointer types
       from `*[struct &str { *[u8], u32 }; 1]`
         to `*[struct &str { *[u8], u32 }]`
  --> 
C:\Users\DrMeepster\.rustup\toolchains\nightly-2023-03-04-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\panic.rs:57:38
   |
57 |         $crate::panicking::panic_fmt($crate::const_format_args!($($t)+))
   |                                      ^
   |

error: cannot cast between pointer types
       from `*struct ! {  }`
         to `*[struct core::fmt::ArgumentV1<'_> { value: *struct core::fmt::Opaque {  }, formatter: *fn(*struct core::fmt::Opaque {  }, 
*struct core::fmt::Formatter<'_> { buf: struct &mut dyn core::fmt::Write { *struct dyn core::fmt::Write {  }, *[u32; 3] }, width: 
struct core::option::Option<usize> { u32, u32 }, precision: struct core::option::Option<usize> { u32, u32 }, flags: u32, fill: u32, 
align: u8 }) -> bool }]`
  --> 
C:\Users\DrMeepster\.rustup\toolchains\nightly-2023-03-04-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\panic.rs:57:38
   |
57 |         $crate::panicking::panic_fmt($crate::const_format_args!($($t)+))
   |                                      ^
   |

System Info

  • Rust: 1.69.0-nightly (44cfafe2f 2023-03-03)
  • OS: Windows 11 10.0.22621
  • GPU: NVIDIA GeForce RTX 3070 Laptop

Backtrace

Backtrace

error: function pointer types are not allowed
   --> 
C:\Users\DrMeepster\.rustup\toolchains\nightly-2023-03-04-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\fmt\mod.rs:401:5
    |
401 |     pub const fn new_v1(pieces: &'a [&'static str], args: &'a [ArgumentV1<'a>]) -> Arguments<'a> {
    |     ^
    |
    = note: used by `core::fmt::ArgumentV1<'_>`
    = note: used by unnamed global (%31)
    = note: used by unnamed global (%32)
    = note: used by `&[core::fmt::ArgumentV1<'_>]`
    = note: used by `core::fmt::Arguments<'_>`
note: used from within `gpu::panic`
   --> 
C:\Users\DrMeepster\.rustup\toolchains\nightly-2023-03-04-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\panic.rs:57:38
    |
57  |         $crate::panicking::panic_fmt($crate::const_format_args!($($t)+))
    |                                      ^
note: called by `gpu::main`
   --> gpu\src\lib.rs:10:5
    |
10  |     panic();
    |     ^
note: called by `main`
   --> gpu\src\lib.rs:8:1
    |
8   | #[spirv_std::spirv(fragment)]
    | ^

error: cannot cast between pointer types
       from `*struct core::option::Option<&[core::fmt::rt::v1::Argument]> { *[struct core::fmt::rt::v1::Argument { position: u32, 
format: struct core::fmt::rt::v1::FormatSpec { precision: struct core::fmt::rt::v1::Count { u32, u32 }, width: struct 
core::fmt::rt::v1::Count { u32, u32 }, flags: u32, fill: u32, align: u8 } }], u32 }`
         to `**struct fn(&[&'static str], &[core::fmt::ArgumentV1<'_>]) -> core::fmt::Arguments<'_> 
{core::fmt::Arguments::<'_>::new_v1} {  }`
   --> 
C:\Users\DrMeepster\.rustup\toolchains\nightly-2023-03-04-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\fmt\mod.rs:405:34
    |
405 |         Arguments { pieces, fmt: None, args }
    |                                  ^
    |
note: used from within `<core::fmt::Arguments>::new_v1`
   --> 
C:\Users\DrMeepster\.rustup\toolchains\nightly-2023-03-04-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\fmt\mod.rs:405:34
    |
405 |         Arguments { pieces, fmt: None, args }
    |                                  ^
note: called by `gpu::panic`
   --> 
C:\Users\DrMeepster\.rustup\toolchains\nightly-2023-03-04-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\panic.rs:57:38
    |
57  |         $crate::panicking::panic_fmt($crate::const_format_args!($($t)+))
    |                                      ^
note: called by `gpu::main`
   --> gpu\src\lib.rs:10:5
    |
10  |     panic();
    |     ^
note: called by `main`
   --> gpu\src\lib.rs:8:1
    |
8   | #[spirv_std::spirv(fragment)]
    | ^

error: cannot cast between pointer types
       from `*[struct &str { *[u8], u32 }; 1]`
         to `*[struct &str { *[u8], u32 }]`
  --> 
C:\Users\DrMeepster\.rustup\toolchains\nightly-2023-03-04-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\panic.rs:57:38
   |
57 |         $crate::panicking::panic_fmt($crate::const_format_args!($($t)+))
   |                                      ^
   |
note: used from within `gpu::panic`
  --> 
C:\Users\DrMeepster\.rustup\toolchains\nightly-2023-03-04-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\panic.rs:57:38
   |
57 |         $crate::panicking::panic_fmt($crate::const_format_args!($($t)+))
   |                                      ^
note: called by `gpu::main`
  --> gpu\src\lib.rs:10:5
   |
10 |     panic();
   |     ^
note: called by `main`
  --> gpu\src\lib.rs:8:1
   |
8  | #[spirv_std::spirv(fragment)]
   | ^

error: cannot cast between pointer types
       from `*struct ! {  }`
         to `*[struct core::fmt::ArgumentV1<'_> { value: *struct core::fmt::Opaque {  }, formatter: *fn(*struct core::fmt::Opaque {  }, 
*struct core::fmt::Formatter<'_> { buf: struct &mut dyn core::fmt::Write { *struct dyn core::fmt::Write {  }, *[u32; 3] }, width: 
struct core::option::Option<usize> { u32, u32 }, precision: struct core::option::Option<usize> { u32, u32 }, flags: u32, fill: u32, 
align: u8 }) -> bool }]`
  --> 
C:\Users\DrMeepster\.rustup\toolchains\nightly-2023-03-04-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\panic.rs:57:38
   |
57 |         $crate::panicking::panic_fmt($crate::const_format_args!($($t)+))
   |                                      ^
   |
note: used from within `gpu::panic`
  --> 
C:\Users\DrMeepster\.rustup\toolchains\nightly-2023-03-04-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\panic.rs:57:38
   |
57 |         $crate::panicking::panic_fmt($crate::const_format_args!($($t)+))
   |                                      ^
note: called by `gpu::main`
  --> gpu\src\lib.rs:10:5
   |
10 |     panic();
   |     ^
note: called by `main`
  --> gpu\src\lib.rs:8:1
   |
8  | #[spirv_std::spirv(fragment)]
   | ^

eddyb commented

I had to change some of the panic detection in the most recent rustup PR (due to changes upstream):

You may want to retest after that lands, in case it fixes this issue (but if so, don't close it, as we'd still want to add a test in that case).

It looks like this is fixed in 0.8