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

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

Closed
AsterixxxGallier opened this issue Aug 24, 2020 · 3 comments · Fixed by #83739
Closed

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

AsterixxxGallier opened this issue Aug 24, 2020 · 3 comments · Fixed by #83739
Labels
A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@AsterixxxGallier
Copy link

AsterixxxGallier commented Aug 24, 2020

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.

@AsterixxxGallier AsterixxxGallier 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 Aug 24, 2020
@jonas-schievink jonas-schievink added A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Aug 24, 2020
@spastorino
Copy link
Member

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

@spastorino spastorino added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Aug 26, 2020
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Sep 8, 2020
@varkor varkor self-assigned this Sep 29, 2020
@varkor
Copy link
Member

varkor commented Nov 16, 2020

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.

@varkor varkor removed their assignment Nov 16, 2020
@matthiaskrgr
Copy link
Member

This ICEs since 1.43.

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

@rustbot rustbot added the regression-from-stable-to-stable Performance or correctness regression from one stable version to another. label Dec 20, 2020
JohnTitor added a commit to JohnTitor/rust that referenced this issue Jun 21, 2021
Account for bad placeholder errors on consts/statics with trait objects

Fixes rust-lang#75889
r? `@estebank`
@bors bors closed this as completed in 1a1909a Jun 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
7 participants