Rust-GPU / Rust-GPU/rust-gpu

[Migrated] Panicking in a #[track_caller] function fails to compile

Open
#86 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
3.4k
Forks
125
PR merge metrics
No merged PRs in 30d

Description

Issue automatically imported from old repo: https://github.com/EmbarkStudios/rust-gpu/issues/1058
Old labels: t: bug
Originally creatd by beepster4096 on 2023-05-03T02:22:13Z


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)]
   | ^

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the example in gpu/src/lib.rs and compare the emitted diagnostics involving #[track_caller], core::fmt::mod.rs, and core::panic.rs. Trace the failure from the spirv fragment entry point through compilation; done means the example compiles successfully without the reported function-pointer and pointer-cast errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.