Skip to content

Compiler error when calling closure incorrectly using fn_traits feature #105936

Closed
@TesseractCat

Description

@TesseractCat

Code

#![feature(fn_traits, unboxed_closures, tuple_trait)]

use std::marker::Tuple;
use std::default::Default;

fn wrap<P: Tuple + Default, T>(
    func: impl Fn<P, Output = T>
) {
    let x: P = Default::default();
    // Should be: `func.call(x);`
    func(x);
}

fn foo() { }

fn main() {
    wrap(foo);
}

Meta

rustc --version --verbose:

rustc 1.68.0-nightly (0468a00ae 2022-12-17)
binary: rustc
commit-hash: 0468a00ae3fd6ef1a6a0f9eaf637d7aa9e604acc
commit-date: 2022-12-17
host: x86_64-pc-windows-msvc
release: 1.68.0-nightly
LLVM version: 15.0.6

Error output

error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error[E0059]: cannot use call notation; the first type parameter for the function trait is neither a tuple nor unit
  --> src\main.rs:11:5
   |
11 |     func(x);
   |     ^^^^^^^

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler\rustc_hir_typeck\src\fn_ctxt\_impl.rs:685:23

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler\rustc_hir_typeck\src\coercion.rs:174:49

error: internal compiler error: broken MIR in DefId(0:5 ~ triage[3bb5]::wrap) (Terminator { source_info: SourceInfo { span: src\main.rs:11:5: 11:12 (#0), scope: scope[1] }, kind: _3 = <impl Fn<P, Output = T> as Fn<P>>::call(move _4, move _5) -> [return: bb2, unwind: bb8] }): bad arg #1 (P <- (P,)): NoSolution
  --> src\main.rs:11:5
   |
11 |     func(x);
   |     ^^^^^^^
   |
   = note: delayed at compiler\rustc_borrowck\src\type_check\mod.rs:1580:17
Backtrace

thread 'rustc' panicked at 'Box<dyn Any>', compiler\rustc_errors\src\lib.rs:1610:13
stack backtrace:
   0:     0x7ffff9959de2 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hea3121a92230cef2
   1:     0x7ffff9995d0b - core::fmt::write::h0bc3f53e8dca163a
   2:     0x7ffff994c8fa - <std::io::IoSlice as core::fmt::Debug>::fmt::h7890ee78f4472cf6
   3:     0x7ffff9959b2b - std::sys::common::alloc::realloc_fallback::h2905b67a6dea1c71
   4:     0x7ffff995d459 - std::panicking::default_hook::h111ce7f1b363c3ab
   5:     0x7ffff995d0db - std::panicking::default_hook::h111ce7f1b363c3ab
   6:     0x7ffff28c4deb - rustc_driver[5e4fd5aa1121bb7c]::describe_lints
   7:     0x7ffff995ddc0 - std::panicking::rust_panic_with_hook::hfc6ef76eb93085aa
   8:     0x7ffff29054a3 - <rustc_errors[2f3e2ae2073fef46]::ErrorGuaranteed as core[c581a5698e0001c6]::fmt::Debug>::fmt
   9:     0x7ffff2903959 - <rustc_errors[2f3e2ae2073fef46]::ErrorGuaranteed as core[c581a5698e0001c6]::fmt::Debug>::fmt
  10:     0x7ffff28e1e29 - <rustc_errors[2f3e2ae2073fef46]::json::JsonEmitter as rustc_errors[2f3e2ae2073fef46]::emitter::Emitter>::should_show_explain
  11:     0x7ffff2900249 - <rustc_span[25fa311e2ce9dc22]::symbol::MacroRulesNormalizedIdent as rustc_errors[2f3e2ae2073fef46]::diagnostic::IntoDiagnosticArg>::into_diagnostic_arg
  12:     0x7fffefaa5b7d - <rustc_errors[2f3e2ae2073fef46]::HandlerInner>::emit_diagnostic
  13:     0x7fffefc4116d - rustc_interface[e09bab31b5025fb2]::passes::prepare_outputs
  14:     0x7fffefc5fe08 - <rustc_interface[e09bab31b5025fb2]::queries::Queries>::ongoing_codegen
  15:     0x7fffefa5434c - rustc_driver[5e4fd5aa1121bb7c]::args::arg_expand_all
  16:     0x7fffefa44983 - <rustc_span[25fa311e2ce9dc22]::DebuggerVisualizerFile>::new
  17:     0x7fffefa3a24d - <rustc_span[25fa311e2ce9dc22]::DebuggerVisualizerFile>::new
  18:     0x7ffff996fe9c - std::sys::windows::thread::Thread::new::h4025a5964e95cbad
  19:     0x7ff84f7e7c24 - BaseThreadInitThunk
  20:     0x7ff85162d721 - RtlUserThreadStart

Metadata

Metadata

Labels

C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions