From f3f400677847e65e7e07e6d12f00247bdd3acb0a Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Fri, 5 Jul 2024 17:04:27 -0700 Subject: [PATCH 1/4] lolsob --- tests/ui/c-variadic/generics-shouldnt-work.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tests/ui/c-variadic/generics-shouldnt-work.rs diff --git a/tests/ui/c-variadic/generics-shouldnt-work.rs b/tests/ui/c-variadic/generics-shouldnt-work.rs new file mode 100644 index 0000000000000..557d2aabcf0b6 --- /dev/null +++ b/tests/ui/c-variadic/generics-shouldnt-work.rs @@ -0,0 +1,16 @@ +//@ compile-flags: --edition 2021 +use core::ffi; + +extern "C" { + fn printf(ptr: *const ffi::c_char, ...) -> ffi::c_int; +} + +fn generic_printf(c: &ffi::CStr, arg: T) { + unsafe { printf(c.as_ptr(), arg) }; +} + +fn main() { + generic_printf(c"%d", 2u8); + generic_printf(c"%f", 3.333_f32); + generic_printf(c"%s", vec![6, 2, 8, 3, 1, 8, 5, 3, 0]); +} From 70ba943621334aa9ef4141ecab7e6e2e554020d4 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Fri, 5 Jul 2024 17:11:41 -0700 Subject: [PATCH 2/4] ban varargs --- compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 1138642c56d61..9fddfce8a49d8 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -428,6 +428,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let ptr_ty = self.resolve_vars_if_possible(ptr_ty); variadic_error(tcx.sess, arg.span, arg_ty, &ptr_ty.to_string()); } + // generics? in C variadic? naaah + ty::Adt(_def, gen_args) if gen_args.len() > 0 => { + bug!("what the ferris are you doing") + } _ => {} } } From 3639f813caaa7671ce57e32dbe886f0a01f49598 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Fri, 5 Jul 2024 17:20:14 -0700 Subject: [PATCH 3/4] ban harder --- .../rustc_hir_typeck/src/fn_ctxt/checks.rs | 1 + tests/ui/c-variadic/generics-shouldnt-work.rs | 1 + .../c-variadic/generics-shouldnt-work.stderr | 193 ++++++++++++++++++ 3 files changed, 195 insertions(+) create mode 100644 tests/ui/c-variadic/generics-shouldnt-work.stderr diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 9fddfce8a49d8..df584dd2c4269 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -432,6 +432,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ty::Adt(_def, gen_args) if gen_args.len() > 0 => { bug!("what the ferris are you doing") } + ty::Param(_) => bug!("what the ferris are you doing"), _ => {} } } diff --git a/tests/ui/c-variadic/generics-shouldnt-work.rs b/tests/ui/c-variadic/generics-shouldnt-work.rs index 557d2aabcf0b6..ef1e69403dea3 100644 --- a/tests/ui/c-variadic/generics-shouldnt-work.rs +++ b/tests/ui/c-variadic/generics-shouldnt-work.rs @@ -1,4 +1,5 @@ //@ compile-flags: --edition 2021 +//@ failure-status: 101 use core::ffi; extern "C" { diff --git a/tests/ui/c-variadic/generics-shouldnt-work.stderr b/tests/ui/c-variadic/generics-shouldnt-work.stderr new file mode 100644 index 0000000000000..6130832d82dac --- /dev/null +++ b/tests/ui/c-variadic/generics-shouldnt-work.stderr @@ -0,0 +1,193 @@ +error: internal compiler error: compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs:435:37: what the ferris are you doing + +thread 'rustc' panicked at compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs:435:37: +Box +stack backtrace: + 0: std::panicking::begin_panic:: + at ./library/std/src/panicking.rs:733:5 + 1: std::panic::panic_any:: + at ./library/std/src/panic.rs:264:5 + 2: ::emit_producing_guarantee + at ./compiler/rustc_errors/src/diagnostic.rs:86:9 + 3: >::emit + at ./compiler/rustc_errors/src/diagnostic.rs:1317:9 + 4: ::bug:: + at ./compiler/rustc_errors/src/lib.rs:1140:9 + 5: {closure#0} + at ./compiler/rustc_middle/src/util/bug.rs:37:38 + 6: {closure#0}, !> + at ./compiler/rustc_middle/src/ty/context/tls.rs:158:23 + 7: with_context_opt, !>, !> + at ./compiler/rustc_middle/src/ty/context/tls.rs:101:18 + 8: rustc_middle::ty::context::tls::with_opt::::{closure#0}, !> + at ./compiler/rustc_middle/src/ty/context/tls.rs:156:5 + 9: rustc_middle::util::bug::opt_span_bug_fmt:: + at ./compiler/rustc_middle/src/util/bug.rs:31:5 + 10: rustc_middle::util::bug::bug_fmt + at ./compiler/rustc_middle/src/util/bug.rs:15:5 + 11: check_argument_types + 12: confirm_builtin_call + at ./compiler/rustc_hir_typeck/src/callee.rs:516:9 + 13: check_call + 14: check_expr_kind + at ./compiler/rustc_hir_typeck/src/expr.rs:322:45 + 15: {closure#0} + at ./compiler/rustc_hir_typeck/src/expr.rs:227:18 + 16: maybe_grow + at /home/jubilee/.cargo/registry/src/index.crates.io-6f17d22bba15001f/stacker-0.1.15/src/lib.rs:55:9 + 17: ensure_sufficient_stack + at ./compiler/rustc_data_structures/src/stack.rs:17:5 + 18: check_expr_with_expectation_and_args + at ./compiler/rustc_hir_typeck/src/expr.rs:223:18 + 19: check_expr_with_expectation + at ./compiler/rustc_hir_typeck/src/expr.rs:169:9 + 20: {closure#0} + at ./compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs:1736:44 + 21: map<&rustc_hir::hir::Expr, (&rustc_hir::hir::Expr, rustc_middle::ty::Ty), rustc_hir_typeck::fn_ctxt::checks::{impl#0}::check_block_with_expected::{closure#0}::{closure_env#0}> + at ./library/core/src/option.rs:1103:29 + 22: {closure#0} + at ./compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs:1736:17 + 23: with_breakable_ctxt + at ./compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs:1544:22 + 24: check_block_with_expected + at ./compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs:1728:26 + 25: check_expr_kind + at ./compiler/rustc_hir_typeck/src/expr.rs:321:41 + 26: {closure#0} + at ./compiler/rustc_hir_typeck/src/expr.rs:227:18 + 27: maybe_grow + at /home/jubilee/.cargo/registry/src/index.crates.io-6f17d22bba15001f/stacker-0.1.15/src/lib.rs:55:9 + 28: ensure_sufficient_stack + at ./compiler/rustc_data_structures/src/stack.rs:17:5 + 29: check_expr_with_expectation_and_args + at ./compiler/rustc_hir_typeck/src/expr.rs:223:18 + 30: check_expr_with_expectation + at ./compiler/rustc_hir_typeck/src/expr.rs:169:9 + 31: check_expr + at ./compiler/rustc_hir_typeck/src/expr.rs:142:9 + 32: check_stmt + at ./compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs:1678:17 + 33: {closure#0} + at ./compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs:1730:17 + 34: with_breakable_ctxt + at ./compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs:1544:22 + 35: check_block_with_expected + at ./compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs:1728:26 + 36: check_expr_kind + at ./compiler/rustc_hir_typeck/src/expr.rs:321:41 + 37: {closure#0} + at ./compiler/rustc_hir_typeck/src/expr.rs:227:18 + 38: maybe_grow + at /home/jubilee/.cargo/registry/src/index.crates.io-6f17d22bba15001f/stacker-0.1.15/src/lib.rs:55:9 + 39: ensure_sufficient_stack + at ./compiler/rustc_data_structures/src/stack.rs:17:5 + 40: check_expr_with_expectation_and_args + at ./compiler/rustc_hir_typeck/src/expr.rs:223:18 + 41: check_expr_with_expectation + at ./compiler/rustc_hir_typeck/src/expr.rs:169:9 + 42: check_expr_with_hint + at ./compiler/rustc_hir_typeck/src/expr.rs:121:9 + 43: check_return_expr + at ./compiler/rustc_hir_typeck/src/expr.rs:843:30 + 44: check_fn + at ./compiler/rustc_hir_typeck/src/check.rs:138:5 + 45: {closure#0} + at ./compiler/rustc_hir_typeck/src/lib.rs:162:9 + 46: typeck_with_fallback + at ./compiler/rustc_hir_typeck/src/lib.rs:117:1 + 47: {closure#0} + at ./compiler/rustc_query_impl/src/plumbing.rs:281:9 + [... omitted 22 frames ...] + 48: query_ensure>> + at ./compiler/rustc_middle/src/query/plumbing.rs:161:9 + 49: typeck + at ./compiler/rustc_middle/src/query/plumbing.rs:196:9 + 50: {closure#4} + at ./compiler/rustc_hir_analysis/src/lib.rs:201:13 + 51: {closure#0} + at ./compiler/rustc_middle/src/hir/map/mod.rs:334:82 + 52: {closure#0}<&rustc_span::def_id::LocalDefId, &[rustc_span::def_id::LocalDefId], rustc_middle::hir::map::{impl#3}::par_body_owners::{closure_env#0}> + at ./compiler/rustc_data_structures/src/sync/parallel.rs:182:34 + 53: call_once<(), rustc_data_structures::sync::parallel::enabled::par_for_each_in::{closure#0}::{closure#0}::{closure_env#0}<&rustc_span::def_id::LocalDefId, &[rustc_span::def_id::LocalDefId], rustc_middle::hir::map::{impl#3}::par_body_owners::{closure_env#0}>> + at ./library/core/src/panic/unwind_safe.rs:272:9 + 54: do_call>>, ()> + at ./library/std/src/panicking.rs:553:40 + 55: try<(), core::panic::unwind_safe::AssertUnwindSafe>>> + at ./library/std/src/panicking.rs:517:19 + 56: run<(), rustc_data_structures::sync::parallel::enabled::par_for_each_in::{closure#0}::{closure#1}::{closure_env#0}<&rustc_span::def_id::LocalDefId, &[rustc_span::def_id::LocalDefId], rustc_middle::hir::map::{impl#3}::par_body_owners::{closure_env#0}>> + at ./compiler/rustc_data_structures/src/sync/parallel.rs:28:9 + 57: {closure#1}<&rustc_span::def_id::LocalDefId, &[rustc_span::def_id::LocalDefId], rustc_middle::hir::map::{impl#3}::par_body_owners::{closure_env#0}> + at ./compiler/rustc_data_structures/src/sync/parallel.rs:186:21 + 58: for_each>> + at ./library/core/src/slice/iter/macros.rs:254:21 + 59: {closure#0}<&rustc_span::def_id::LocalDefId, &[rustc_span::def_id::LocalDefId], rustc_middle::hir::map::{impl#3}::par_body_owners::{closure_env#0}> + at ./compiler/rustc_data_structures/src/sync/parallel.rs:185:17 + 60: parallel_guard<(), rustc_data_structures::sync::parallel::enabled::par_for_each_in::{closure_env#0}<&rustc_span::def_id::LocalDefId, &[rustc_span::def_id::LocalDefId], rustc_middle::hir::map::{impl#3}::par_body_owners::{closure_env#0}>> + at ./compiler/rustc_data_structures/src/sync/parallel.rs:44:15 + 61: par_for_each_in<&rustc_span::def_id::LocalDefId, &[rustc_span::def_id::LocalDefId], rustc_middle::hir::map::{impl#3}::par_body_owners::{closure_env#0}> + at ./compiler/rustc_data_structures/src/sync/parallel.rs:178:9 + 62: par_body_owners + at ./compiler/rustc_middle/src/hir/map/mod.rs:334:9 + 63: check_crate + at ./compiler/rustc_hir_analysis/src/lib.rs:198:5 + 64: run_required_analyses + at ./compiler/rustc_interface/src/passes.rs:784:5 + 65: analysis + at ./compiler/rustc_interface/src/passes.rs:823:5 + 66: {closure#0} + at ./compiler/rustc_query_impl/src/plumbing.rs:281:9 + [... omitted 22 frames ...] + 67: query_get_at>> + at ./compiler/rustc_middle/src/query/plumbing.rs:145:17 + 68: analysis + at ./compiler/rustc_middle/src/query/plumbing.rs:423:31 + 69: analysis + at ./compiler/rustc_middle/src/query/plumbing.rs:414:17 + 70: {closure#5} + at ./compiler/rustc_driver_impl/src/lib.rs:445:48 + 71: {closure#1}> + at ./compiler/rustc_middle/src/ty/context.rs:1296:37 + 72: {closure#0}>, core::result::Result<(), rustc_span::ErrorGuaranteed>> + at ./compiler/rustc_middle/src/ty/context/tls.rs:82:9 + 73: try_with, rustc_middle::ty::context::tls::enter_context::{closure_env#0}>, core::result::Result<(), rustc_span::ErrorGuaranteed>>, core::result::Result<(), rustc_span::ErrorGuaranteed>> + at ./library/std/src/thread/local.rs:283:12 + 74: with, rustc_middle::ty::context::tls::enter_context::{closure_env#0}>, core::result::Result<(), rustc_span::ErrorGuaranteed>>, core::result::Result<(), rustc_span::ErrorGuaranteed>> + at ./library/std/src/thread/local.rs:260:9 + 75: enter_context>, core::result::Result<(), rustc_span::ErrorGuaranteed>> + at ./compiler/rustc_middle/src/ty/context/tls.rs:79:5 + 76: enter> + at ./compiler/rustc_middle/src/ty/context.rs:1296:9 + 77: {closure#1} + at ./compiler/rustc_driver_impl/src/lib.rs:445:13 + 78: enter, rustc_span::ErrorGuaranteed>> + at ./compiler/rustc_interface/src/queries.rs:202:19 + 79: {closure#0} + at ./compiler/rustc_driver_impl/src/lib.rs:389:22 + 80: {closure#1}, rustc_driver_impl::run_compiler::{closure_env#0}> + at ./compiler/rustc_interface/src/interface.rs:502:27 + 81: {closure#0}, rustc_driver_impl::run_compiler::{closure_env#0}>, core::result::Result<(), rustc_span::ErrorGuaranteed>> + at ./compiler/rustc_interface/src/util.rs:154:13 + 82: {closure#0}, rustc_driver_impl::run_compiler::{closure_env#0}>, core::result::Result<(), rustc_span::ErrorGuaranteed>>, core::result::Result<(), rustc_span::ErrorGuaranteed>> + at ./compiler/rustc_interface/src/util.rs:106:21 + 83: set, rustc_driver_impl::run_compiler::{closure_env#0}>, core::result::Result<(), rustc_span::ErrorGuaranteed>>, core::result::Result<(), rustc_span::ErrorGuaranteed>>, core::result::Result<(), rustc_span::ErrorGuaranteed>> + at /home/jubilee/.cargo/registry/src/index.crates.io-6f17d22bba15001f/scoped-tls-1.0.1/src/lib.rs:137:9 + 84: create_session_globals_then, rustc_interface::util::run_in_thread_with_globals::{closure#0}::{closure#0}::{closure_env#0}, rustc_driver_impl::run_compiler::{closure_env#0}>, core::result::Result<(), rustc_span::ErrorGuaranteed>>, core::result::Result<(), rustc_span::ErrorGuaranteed>>> + at ./compiler/rustc_span/src/lib.rs:134:5 + 85: {closure#0}, rustc_driver_impl::run_compiler::{closure_env#0}>, core::result::Result<(), rustc_span::ErrorGuaranteed>>, core::result::Result<(), rustc_span::ErrorGuaranteed>> + at ./compiler/rustc_interface/src/util.rs:105:17 +note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. + +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 make sure that you have updated to the latest nightly + +note: rustc 1.81.0-dev running on x86_64-unknown-linux-gnu + +note: compiler flags: -Z threads=1 -Z simulate-remapped-rust-src-base=/rustc/FAKE_PREFIX -Z translate-remapped-path-to-local-path=no -Z ignore-directory-in-diagnostics-source-blocks=/home/jubilee/.cargo -Z ignore-directory-in-diagnostics-source-blocks=/home/jubilee/rust/rustc/vendor -C codegen-units=1 -Z ui-testing -Z deduplicate-diagnostics=no -Z write-long-types-to-disk=no -C strip=debuginfo -C prefer-dynamic -C rpath -C debuginfo=0 + +query stack during panic: +#0 [typeck] type-checking `generic_printf` +#1 [analysis] running analysis passes on this crate +end of query stack +error: aborting due to 1 previous error + From 429696f9e6a26d97fbbf9e1f3a051f93ee972cb2 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Fri, 5 Jul 2024 17:26:04 -0700 Subject: [PATCH 4/4] die monster, you dont belong in this world --- tests/ui/abi/mir/mir_codegen_calls_variadic.rs | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 tests/ui/abi/mir/mir_codegen_calls_variadic.rs diff --git a/tests/ui/abi/mir/mir_codegen_calls_variadic.rs b/tests/ui/abi/mir/mir_codegen_calls_variadic.rs deleted file mode 100644 index 0c1a59b38d3eb..0000000000000 --- a/tests/ui/abi/mir/mir_codegen_calls_variadic.rs +++ /dev/null @@ -1,18 +0,0 @@ -//@ run-pass - -#[link(name = "rust_test_helpers", kind = "static")] -extern "C" { - fn rust_interesting_average(_: i64, ...) -> f64; -} - -fn test(a: i64, b: i64, c: i64, d: i64, e: i64, f: T, g: U) -> i64 { - unsafe { - rust_interesting_average( - 6, a, a as f64, b, b as f64, c, c as f64, d, d as f64, e, e as f64, f, g, - ) as i64 - } -} - -fn main() { - assert_eq!(test(10, 20, 30, 40, 50, 60_i64, 60.0_f64), 70); -}