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

Broken MIR (and diagnostics) using Higher-Rank Trait Bounds and associated types #80956

Closed
SkiFire13 opened this issue Jan 12, 2021 · 4 comments · Fixed by #88640
Closed

Broken MIR (and diagnostics) using Higher-Rank Trait Bounds and associated types #80956

SkiFire13 opened this issue Jan 12, 2021 · 4 comments · Fixed by #88640
Labels
A-associated-items Area: Associated items (types, constants & functions) A-borrow-checker Area: The borrow checker A-lifetimes Area: Lifetimes / regions C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. 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

@SkiFire13
Copy link
Contributor

Code

trait Bar {
    type Type;
}
struct Foo<'a>(&'a ());
impl<'a> Bar for Foo<'a> {
    type Type = ();
}

fn func<'a>(_: <Foo<'a> as Bar>::Type) {}
fn assert_is_func<A>(_: fn(A)) {}

fn test() where for<'a> <Foo<'a> as Bar>::Type: Sized {
    assert_is_func(func);
}

Playground link

Meta

rustc --version --verbose:

rustc 1.49.0 (e1884a8e3 2020-12-29)
binary: rustc
commit-hash: e1884a8e3c3e813aada8254edfa120e85bf5ffca
commit-date: 2020-12-29
host: x86_64-pc-windows-msvc
release: 1.49.0

Error output

warning: Error finalizing incremental compilation session directory `\\?\G:\WorkSpace\rust-playground\target\debug\incremental\rust_playground-13rqwjq2lprvw\s-fuvapvoonl-1e5eb07-working`: Impossibile trovare il file specificato. (os error 2)

warning: 4 warnings emitted

error: internal compiler error: broken MIR in DefId(0:16 ~ rust_playground[48a5]::test) (Terminator { source_info: SourceInfo { span: src\lib.rs:13:5: 13:25 (#0), scope: scope[0] }, kind: _1 = assert_is_func::<<Foo<'_> as 
Bar>::Type>(move _2) -> [return: bb1, unwind: bb2] }): bad arg #0 (fn(()) <- for<'r> fn(<Foo<'r> as Bar>::Type)): NoSolution
  --> src\lib.rs:13:20
   |
13 |     assert_is_func(func);
   |                    ^^^^
   |
   = note: delayed at compiler\rustc_mir\src\borrow_check\type_check\mod.rs:253:27

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler\rustc_errors\src\lib.rs:974:13
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose 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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.49.0 (e1884a8e3 2020-12-29) running on x86_64-pc-windows-msvc

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type lib

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

query stack during panic:
end of query stack
error: could not compile `rust-playground`

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

Strangely the backtrace is empty (I got the error output section with RUST_BACKTRACE=1). Should I report that bug separately?

@SkiFire13 SkiFire13 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 Jan 12, 2021
@jyn514
Copy link
Member

jyn514 commented Jan 13, 2021

This also crashes on nightly, but it has a backtrace there (not that it's very helpful):

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler/rustc_errors/src/lib.rs:974:13
stack backtrace:
   0: rust_begin_unwind
             at /rustc/c5eae562935922f712edec56a45591bc2f8ded1c/library/std/src/panicking.rs:493:5
   1: std::panicking::begin_panic_fmt
             at /rustc/c5eae562935922f712edec56a45591bc2f8ded1c/library/std/src/panicking.rs:435:5
   2: rustc_errors::HandlerInner::flush_delayed
   3: <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop
   4: core::ptr::drop_in_place<rustc_session::parse::ParseSess>
   5: <alloc::rc::Rc<T> as core::ops::drop::Drop>::drop
   6: core::ptr::drop_in_place<rustc_interface::interface::Compiler>
   7: rustc_span::with_source_map
   8: rustc_interface::interface::create_compiler_and_run
   9: rustc_span::with_session_globals

@SkiFire13 can you see if using nightly gets you a backtrace?

@jyn514 jyn514 added A-associated-items Area: Associated items (types, constants & functions) A-lifetimes Area: Lifetimes / regions A-borrow-checker Area: The borrow checker labels Jan 13, 2021
@SkiFire13
Copy link
Contributor Author

I can't get a normal backtrace even on nightly, however I can get one with RUST_BACKTRACE=full (on both stable and nightly), but I don't think it will be very helpful:

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler\rustc_errors\src\lib.rs:974:13
stack backtrace:
   0:     0x7ffe7e17a24e - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h9b227e9f535b30ad
   1:     0x7ffe7e1a841b - core::fmt::write::h61d774f0fccca269
   2:     0x7ffe7e16bc68 - <std::io::IoSliceMut as core::fmt::Debug>::fmt::hd02efffdeb825e77
   3:     0x7ffe7e17f86d - std::panicking::take_hook::h071d302a205c6652
   4:     0x7ffe7e17f448 - std::panicking::take_hook::h071d302a205c6652
   5:     0x7ffe26f58c27 - rustc_driver::report_ice::h5fb666ac0b140095
   6:     0x7ffe7e180380 - std::panicking::rust_panic_with_hook::h3a6bf3c946dc3fd3
   7:     0x7ffe7e17fe51 - rust_begin_unwind
   8:     0x7ffe7e17ab8f - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h9b227e9f535b30ad
   9:     0x7ffe7e17fda9 - rust_begin_unwind
  10:     0x7ffe7e17fd5c - std::panicking::begin_panic_fmt::h4544c6b6ce1d7abc
  11:     0x7ffe2b670484 - rustc_errors::HandlerInner::delay_as_bug::h14efc84023f1ac5a
  12:     0x7ffe2b66ba14 - <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop::he0453085c4ee1c80
  13:     0x7ffe26f40194 - <rustc_driver::args::Error as core::fmt::Debug>::fmt::h9bf3232a4fe8dccd
  14:     0x7ffe26f45a90 - <rustc_driver::args::Error as core::fmt::Debug>::fmt::h9bf3232a4fe8dccd
  15:     0x7ffe26f4ad1a - <rustc_driver::args::Error as core::fmt::Debug>::fmt::h9bf3232a4fe8dccd
  16:     0x7ffe26f62acc - <rustc_driver::Compilation as core::fmt::Debug>::fmt::h33be7dbc37f75bef
  17:     0x7ffe26f5b2b4 - <rustc_driver::Compilation as core::fmt::Debug>::fmt::h33be7dbc37f75bef
  18:     0x7ffe26f6aa08 - <rustc_driver::Compilation as core::fmt::Debug>::fmt::h33be7dbc37f75bef
  19:     0x7ffe26f5d09e - <rustc_driver::Compilation as core::fmt::Debug>::fmt::h33be7dbc37f75bef
  20:     0x7ffe26f6f883 - <rustc_driver::Compilation as core::fmt::Debug>::fmt::h33be7dbc37f75bef
  21:     0x7ffe26edbe8d - <sha1::Sha1 as std::io::Write>::flush::hc1a90b50a4949fda
  22:     0x7ffe7e190537 - std::sys::windows::thread::Thread::new::h010378fec97bafdf
  23:     0x7ffeb4867034 - BaseThreadInitThunk
  24:     0x7ffeb4b7d0d1 - RtlUserThreadStart

@SNCPlay42
Copy link
Contributor

For delay_span_bugs you can get the backtrace for where they were originally issued with -Ztreat-err-as-bug:

% RUST_BACKTRACE=1 rustc +nightly --crate-type=lib -Ztreat-err-as-bug=1 issue.rs
error: internal compiler error: broken MIR in DefId(0:16 ~ issue[8787]::test) (Terminator { source_info: SourceInfo { span: issue.rs:13:5: 13:25 (#0), scope: scope[0] }, kind: _1 = assert_is_func::<<Foo<'_> as Bar>::Type>(move _2) -> [return: bb1, unwind: bb2] }): bad arg #0 (fn(()) <- for<'r> fn(<Foo<'r> as Bar>::Type)): NoSolution
  --> issue.rs:13:20
   |
13 |     assert_is_func(func);
   |                    ^^^^

thread 'rustc' panicked at 'aborting due to `-Z treat-err-as-bug=1`', compiler/rustc_errors/src/lib.rs:990:27
stack backtrace:
   0: std::panicking::begin_panic
   1: rustc_errors::HandlerInner::emit_diagnostic
   2: rustc_errors::HandlerInner::emit_diag_at_span
   3: rustc_errors::HandlerInner::span_bug
   4: rustc_errors::Handler::delay_span_bug
   5: rustc_mir::borrow_check::type_check::TypeChecker::typeck_mir
   6: rustc_mir::borrow_check::type_check::type_check
   7: rustc_mir::borrow_check::nll::compute_regions
   8: rustc_mir::borrow_check::do_mir_borrowck
   9: rustc_infer::infer::InferCtxtBuilder::enter
  10: rustc_mir::borrow_check::mir_borrowck
  11: core::ops::function::FnOnce::call_once
  12: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::mir_borrowck>::compute
  13: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  14: rustc_data_structures::stack::ensure_sufficient_stack
  15: rustc_query_system::query::plumbing::get_query_impl
  16: rustc_query_system::query::plumbing::ensure_query_impl
  17: rustc_session::utils::<impl rustc_session::session::Session>::time
  18: rustc_interface::passes::analysis
  19: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  20: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  21: rustc_data_structures::stack::ensure_sufficient_stack
  22: rustc_query_system::query::plumbing::get_query_impl
  23: rustc_interface::passes::QueryContext::enter
  24: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  25: rustc_span::with_source_map
  26: rustc_interface::interface::create_compiler_and_run
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose 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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.51.0-nightly (158f8d034 2020-12-29) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z treat-err-as-bug=1 --crate-type lib

query stack during panic:
#0 [mir_borrowck] borrow-checking `test`
#1 [analysis] running analysis passes on this crate
end of query stack

(Should we automatically capture backtraces of delay_span_bug when RUST_BACKTRACE is set?)

JohnTitor added a commit to JohnTitor/glacier that referenced this issue Jan 15, 2021
JohnTitor added a commit to JohnTitor/glacier that referenced this issue Jan 15, 2021
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Jan 15, 2021
@jackh726
Copy link
Member

I can see how this would be fixed by #85499, but we don't have a test like this. Marking as needs-test.

@jackh726 jackh726 added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Aug 29, 2021
@bors bors closed this as completed in 0e0ce83 Sep 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-borrow-checker Area: The borrow checker A-lifetimes Area: Lifetimes / regions C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. 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.

5 participants