Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler error when calling closure incorrectly using fn_traits feature #105936

Closed
TesseractCat opened this issue Dec 20, 2022 · 2 comments · Fixed by #105966
Closed

Compiler error when calling closure incorrectly using fn_traits feature #105936

TesseractCat opened this issue Dec 20, 2022 · 2 comments · Fixed by #105966
Assignees
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@TesseractCat
Copy link

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

@TesseractCat TesseractCat added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 20, 2022
@PatchMixolydic
Copy link
Contributor

PatchMixolydic commented Dec 20, 2022

It seems that the cannot use call notation diagnostic was changed to an ICE in this commit, which was part of #99943.

@compiler-errors compiler-errors self-assigned this Dec 20, 2022
@compiler-errors
Copy link
Member

I don't know why I delayed that as a bug -- do I ever do anything logically? no.

I'll see what diagnostics regress when we continue to emit that error, lol.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 22, 2022
Re-enable `Fn` trait call notation error for non-tuple argument

I have no idea why I delayed this bug... but also there doesn't seem to be a UI test that actually shows a change, so maybe that's why.

Fixes rust-lang#105936
@bors bors closed this as completed in 6a215ab Dec 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants