Skip to content

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

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.

Activity

  1. added
    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.
    on Aug 24, 2020
  2. added
    A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Aug 24, 2020
  3. spastorino commented on Aug 26, 2020

    @spastorino
    Member

    Assigning P-medium as discussed as part of the Prioritization Working Group procedure and removing I-prioritize.

  4. added and removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Aug 26, 2020
  5. self-assigned this
    on Sep 29, 2020
  6. varkor commented on Nov 16, 2020

    @varkor
    Contributor

    There is a partial fix in #77431, though it regresses diagnostics. I think it ought not to be too much work to address this, but I do not have time at the moment.

  7. removed their assignment
    on Nov 16, 2020
  8. matthiaskrgr commented on Dec 20, 2020

    @matthiaskrgr
    Member

    This ICEs since 1.43.

    @rustbot modify labels: +regression-from-stable-to-stable

  9. added 2 commits that reference this issue on Jun 21, 2021
    cde49cf
    1a1909a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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