Skip to content

MIR has errors when type of const is Fn with placeholder type #75889

Closed
@AsterixxxGallier

Description

@AsterixxxGallier

I'll jump straight into the minimum verifiable example:

const /* or static */ FOO: dyn Fn() /* or just fn() */ -> _ = "this can be anything";

Try it out here.

Here is the standard error output:

   Compiling playground v0.0.1 (/playground)
warning: constant is never used: `FOO`
 --> src/lib.rs:1:1
  |
1 | const /* or static */ FOO: dyn Fn() -> _ = "this can be anything";
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: 1 warning emitted

error: internal compiler error: bad placeholder type
 --> src/lib.rs:1:40
  |
1 | const /* or static */ FOO: dyn Fn() -> _ = "this can be anything";
  |                                        ^

error: internal compiler error: mir_const_qualif: MIR had errors
 --> src/lib.rs:1:1
  |
1 | const /* or static */ FOO: dyn Fn() -> _ = "this can be anything";
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error: PromoteTemps: MIR had errors
 --> src/lib.rs:1:1
  |
1 | const /* or static */ FOO: dyn Fn() -> _ = "this can be anything";
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error: broken MIR in DefId(0:3 ~ playground[73cc]::FOO[0]) ("return type"): bad type [type error]
 --> src/lib.rs:1:1
  |
1 | const /* or static */ FOO: dyn Fn() -> _ = "this can be anything";
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error: broken MIR in DefId(0:3 ~ playground[73cc]::FOO[0]) (LocalDecl { mutability: Mut, local_info: None, internal: false, is_block_tail: None, ty: [type error], user_ty: None, source_info: SourceInfo { span: src/lib.rs:1:1: 1:67, scope: scope[0] } }): bad type [type error]
 --> src/lib.rs:1:1
  |
1 | const /* or static */ FOO: dyn Fn() -> _ = "this can be anything";
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:366:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.45.2 (d3fb005a3 2020-07-31) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type lib

note: some of the compiler flags provided by cargo are hidden

error: could not compile `playground`.

To learn more, run the command again with --verbose.

Being a complete beginner I don't really know what I can add to this report, and I have a workaround which I can use to avoid this problem. (I know what I can put in the place of _)

Edit:

static FOO: [dyn Fn() -> _; 0] = [];

(playground link)
gives

Global is external, but doesn't have external or weak linkage!
[0 x {}]* @_ZN10playground3FOO17h4cadae658a91597eE
LLVM ERROR: Broken module found, compilation aborted!

which seems not ideal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions