Closed
Description
original code:
// Compiler:
//
// Run-time:
// status: 0
// stdout: 3
#![feature(auto_traits, lang_items, no_core, start, intrinsics)]
#![no_std]
#![no_core]
/*
* Core
*/
// Because we don't have core yet.
#[lang = "sized"]
pub trait Sized {}
#[lang = "copy"]
trait Copy {
}
impl Copy for isize {}
#[lang = "receiver"]
trait Receiver {
}
#[lang = "freeze"]
pub(crate) unsafe auto trait Freeze {}
mod libc {
#[link(name = "c")]
extern "C" {
pub fn printf(format: *const i8, ...) -> i32;
}
}
/*
* Code
*/
#[start]
fn main(mut argc: isize, _argv: *const *const u8) -> isize {
let test: (isize, isize, isize) = (3, 1, 4);
unsafe {
libc::printf(b"%ld\n\0" as *const u8 as *const i8, test.0);
}
0
}
clippy will suggest:
warning: `as` casting between raw pointers without changing its mutability
--> ./compiler/rustc_codegen_gcc/tests/run/tuple.rs:48:22
|
48 | libc::printf(b"%ld\n\0" as *const u8 as *const i8, test.0);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `(b"%ld\n\0" as *const u8).cast::<i8>()`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_as_ptr
= note: requested on the command line with `-W clippy::ptr-as-ptr`
however the resulting code
// Compiler:
//
// Run-time:
// status: 0
// stdout: 3
#![feature(auto_traits, lang_items, no_core, start, intrinsics)]
#![no_std]
#![no_core]
/*
* Core
*/
// Because we don't have core yet.
#[lang = "sized"]
pub trait Sized {}
#[lang = "copy"]
trait Copy {
}
impl Copy for isize {}
#[lang = "receiver"]
trait Receiver {
}
#[lang = "freeze"]
pub(crate) unsafe auto trait Freeze {}
mod libc {
#[link(name = "c")]
extern "C" {
pub fn printf(format: *const i8, ...) -> i32;
}
}
/*
* Code
*/
#[start]
fn main(mut argc: isize, _argv: *const *const u8) -> isize {
let test: (isize, isize, isize) = (3, 1, 4);
unsafe {
libc::printf(b"%ld\n\0" as *const u8).cast::<i8>(), test.0);
}
0
}
crashes rustc 😅
warning: the feature `lang_items` is internal to the compiler or standard library
--> ./compiler/rustc_codegen_gcc/tests/run/tuple.rs:7:25
|
7 | #![feature(auto_traits, lang_items, no_core, start, intrinsics)]
| ^^^^^^^^^^
|
= note: using it is strongly discouraged
= note: `#[warn(internal_features)]` on by default
warning: the feature `intrinsics` is internal to the compiler or standard library
--> ./compiler/rustc_codegen_gcc/tests/run/tuple.rs:7:53
|
7 | #![feature(auto_traits, lang_items, no_core, start, intrinsics)]
| ^^^^^^^^^^
|
= note: using it is strongly discouraged
thread 'rustc' panicked at compiler/rustc_hir_typeck/src/method/suggest.rs:2544:57:
called `Option::unwrap()` on a `None` value
stack backtrace:
0: 0x7f3e4996385c - std::backtrace_rs::backtrace::libunwind::trace::h28a456392cd66d32
at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
1: 0x7f3e4996385c - std::backtrace_rs::backtrace::trace_unsynchronized::h5c84da83c00e15fa
at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
2: 0x7f3e4996385c - std::sys_common::backtrace::_print_fmt::hd30bc3b95bf09668
at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/std/src/sys_common/backtrace.rs:67:5
3: 0x7f3e4996385c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h2e74b6802afdb640
at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/std/src/sys_common/backtrace.rs:44:22
4: 0x7f3e499ca210 - core::fmt::rt::Argument::fmt::h7e35831c38d16bc1
at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/core/src/fmt/rt.rs:142:9
5: 0x7f3e499ca210 - core::fmt::write::h0f918a578c0be12d
at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/core/src/fmt/mod.rs:1116:17
6: 0x7f3e4995688f - std::io::Write::write_fmt::h9ee98c4e35089d59
at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/std/src/io/mod.rs:1763:15
7: 0x7f3e49963644 - std::sys_common::backtrace::_print::h3ed4b78d937ec356
at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/std/src/sys_common/backtrace.rs:47:5
8: 0x7f3e49963644 - std::sys_common::backtrace::print::h3e675480cae5f56e
at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/std/src/sys_common/backtrace.rs:34:9
9: 0x7f3e49966457 - std::panicking::default_hook::{{closure}}::h22a92b4c71d18a7d
10: 0x7f3e4996619a - std::panicking::default_hook::he8bab92e629ae59d
at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/std/src/panicking.rs:292:9
11: 0x7f3e4c644c75 - std[d67efca46d603186]::panicking::update_hook::<alloc[f3bb8eaa3dde22e3]::boxed::Box<rustc_driver_impl[d618f54c2be2346e]::install_ice_hook::{closure#0}>>::{closure#0}
12: 0x7f3e49966bf8 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h3c886f63fe2b7816
at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/alloc/src/boxed.rs:2021:9
13: 0x7f3e49966bf8 - std::panicking::rust_panic_with_hook::h6be1a3e0bc63054b
at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/std/src/panicking.rs:735:13
14: 0x7f3e49966906 - std::panicking::begin_panic_handler::{{closure}}::h5bd1e55345bdf2f4
at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/std/src/panicking.rs:601:13
15: 0x7f3e49963d76 - std::sys_common::backtrace::__rust_end_short_backtrace::h22bd371f50ea61e7
at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/std/src/sys_common/backtrace.rs:170:18
16: 0x7f3e49966682 - rust_begin_unwind
at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/std/src/panicking.rs:597:5
17: 0x7f3e499c6835 - core::panicking::panic_fmt::h75917a9680bc22eb
at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/core/src/panicking.rs:72:14
18: 0x7f3e499c68d3 - core::panicking::panic::h15b4be75acc6651d
at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/core/src/panicking.rs:127:5
19: 0x7f3e4c8131ad - <rustc_hir_typeck[a88ea1edd08f559a]::fn_ctxt::FnCtxt>::suggest_traits_to_import
20: 0x7f3e4c7fc783 - <rustc_hir_typeck[a88ea1edd08f559a]::fn_ctxt::FnCtxt>::report_no_match_method_error
21: 0x7f3e4c824533 - <rustc_hir_typeck[a88ea1edd08f559a]::fn_ctxt::FnCtxt>::report_method_error
22: 0x7f3e4ade15c9 - <rustc_hir_typeck[a88ea1edd08f559a]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
23: 0x7f3e4add1c7d - <rustc_hir_typeck[a88ea1edd08f559a]::fn_ctxt::FnCtxt>::check_argument_types
24: 0x7f3e4adc1c40 - <rustc_hir_typeck[a88ea1edd08f559a]::fn_ctxt::FnCtxt>::check_call
25: 0x7f3e4add801a - <rustc_hir_typeck[a88ea1edd08f559a]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
26: 0x7f3e4ae5e312 - <rustc_hir_typeck[a88ea1edd08f559a]::fn_ctxt::FnCtxt>::check_block_with_expected
27: 0x7f3e4add88da - <rustc_hir_typeck[a88ea1edd08f559a]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
28: 0x7f3e4ae5e442 - <rustc_hir_typeck[a88ea1edd08f559a]::fn_ctxt::FnCtxt>::check_block_with_expected
29: 0x7f3e4add88da - <rustc_hir_typeck[a88ea1edd08f559a]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
30: 0x7f3e4aa2f1f1 - rustc_hir_typeck[a88ea1edd08f559a]::check::check_fn
31: 0x7f3e4a979bc3 - rustc_hir_typeck[a88ea1edd08f559a]::typeck
32: 0x7f3e4ab91e67 - rustc_query_impl[cd9bb7d0d059f9d0]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[cd9bb7d0d059f9d0]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e5ef13c380fb2ac2]::query::erase::Erased<[u8; 8usize]>>
33: 0x7f3e4ab8bce2 - rustc_query_system[d3997528800dbdc6]::query::plumbing::try_execute_query::<rustc_query_impl[cd9bb7d0d059f9d0]::DynamicConfig<rustc_query_system[d3997528800dbdc6]::query::caches::VecCache<rustc_span[c5d4613e49b6ba27]::def_id::LocalDefId, rustc_middle[e5ef13c380fb2ac2]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[cd9bb7d0d059f9d0]::plumbing::QueryCtxt, false>
34: 0x7f3e4ab8d204 - rustc_query_impl[cd9bb7d0d059f9d0]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
35: 0x7f3e4bb830fe - rustc_hir_analysis[eefb1cd51e18fbfa]::check_crate
36: 0x7f3e4bb7866a - rustc_interface[9b2c388f81952165]::passes::analysis
37: 0x7f3e4bde00e7 - rustc_query_impl[cd9bb7d0d059f9d0]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[cd9bb7d0d059f9d0]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e5ef13c380fb2ac2]::query::erase::Erased<[u8; 1usize]>>
38: 0x7f3e4bddfcd6 - rustc_query_system[d3997528800dbdc6]::query::plumbing::try_execute_query::<rustc_query_impl[cd9bb7d0d059f9d0]::DynamicConfig<rustc_query_system[d3997528800dbdc6]::query::caches::SingleCache<rustc_middle[e5ef13c380fb2ac2]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[cd9bb7d0d059f9d0]::plumbing::QueryCtxt, false>
39: 0x7f3e4bddfa8d - rustc_query_impl[cd9bb7d0d059f9d0]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
40: 0x7f3e4bcf928d - std[d67efca46d603186]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[9b2c388f81952165]::util::run_in_thread_with_globals<rustc_interface[9b2c388f81952165]::interface::run_compiler<core[65b0b3042b233d3]::result::Result<(), rustc_span[c5d4613e49b6ba27]::ErrorGuaranteed>, rustc_driver_impl[d618f54c2be2346e]::run_compiler::{closure#1}>::{closure#0}, core[65b0b3042b233d3]::result::Result<(), rustc_span[c5d4613e49b6ba27]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[65b0b3042b233d3]::result::Result<(), rustc_span[c5d4613e49b6ba27]::ErrorGuaranteed>>
41: 0x7f3e4bcf8543 - <<std[d67efca46d603186]::thread::Builder>::spawn_unchecked_<rustc_interface[9b2c388f81952165]::util::run_in_thread_with_globals<rustc_interface[9b2c388f81952165]::interface::run_compiler<core[65b0b3042b233d3]::result::Result<(), rustc_span[c5d4613e49b6ba27]::ErrorGuaranteed>, rustc_driver_impl[d618f54c2be2346e]::run_compiler::{closure#1}>::{closure#0}, core[65b0b3042b233d3]::result::Result<(), rustc_span[c5d4613e49b6ba27]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[65b0b3042b233d3]::result::Result<(), rustc_span[c5d4613e49b6ba27]::ErrorGuaranteed>>::{closure#1} as core[65b0b3042b233d3]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
42: 0x7f3e49971b75 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h653bfcdacde55689
at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/alloc/src/boxed.rs:2007:9
43: 0x7f3e49971b75 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h546bbc1c1b1ae2df
at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/alloc/src/boxed.rs:2007:9
44: 0x7f3e49971b75 - std::sys::unix::thread::Thread::new::thread_start::ha44b87148468c512
at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/std/src/sys/unix/thread.rs:108:17
45: 0x7f3e497149eb - <unknown>
46: 0x7f3e497987cc - <unknown>
47: 0x0 - <unknown>
error: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md
note: please attach the file at `/home/matthias/vcs/github/rust/rustc-ice-2023-10-05T20:37:45.810195536Z-188188.txt` to your bug report
query stack during panic:
#0 [typeck] type-checking `main`
#1 [analysis] running analysis passes on this crate
end of query stack
warning: 2 warnings emitted