Skip to content

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

Closed

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-bug
    I-ICE
    T-compiler
    on Aug 24, 2020
  2. added
    A-MIR
    I-prioritize
    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
    P-medium
    and removed
    I-prioritize
    on Aug 26, 2020
  5. added
    glacier
    on Sep 8, 2020
  6. self-assigned this
    on Sep 29, 2020
  7. 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.

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

    @matthiaskrgr
    Member

    This ICEs since 1.43.

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

  10. added
    regression-from-stable-to-stable
    on Dec 20, 2020
  11. 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-MIRC-bugI-ICEP-mediumT-compilerglacierregression-from-stable-to-stable

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions