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

ICE: cannot convert ReEarlyBound(0, 'a) to a region vid #68532

Closed
95th opened this issue Jan 25, 2020 · 8 comments · Fixed by #72572
Closed

ICE: cannot convert ReEarlyBound(0, 'a) to a region vid #68532

95th opened this issue Jan 25, 2020 · 8 comments · Fixed by #72572
Assignees
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. 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) ❄️ P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@95th
Copy link
Contributor

95th commented Jan 25, 2020

I got an internal compiler error at commit 95th/btrs@f2eb533 . I dont know how to minimize it.

Relevant code is:

impl<'a> Handshake<'a> {
    const LEN: usize = 68;

    pub fn new(info_hash: &'a InfoHash, peer_id: &'a str) -> Self {
        Self {
            peer_id,
            info_hash,
            extensions: Default::default(),
        }
    }

    pub async fn send(&self, peer: &Peer) -> crate::Result<()> {
        let mut tcp = TcpStream::connect(peer.addr()).await?;
        self.write_bytes(&mut tcp).await?;

        let mut v = [0; Self::LEN];
        tcp.read_exact(&mut v).await?;

        println!("{:?}", v);
        Ok(())
    }
  ...

If I remove the const field and directly put the array size like below, the ICE goes away and I get the expected compilation error that [u8; 68] is not Debug.

       let mut v = [0; 68];
       ...
Backtrace:
~/btrs$ RUST_BACKTRACE=1 cargo check
    Checking btrs v0.1.0 (/home/95th/btrs)
error: internal compiler error: src/librustc_mir/borrow_check/nll/universal_regions.rs:764: cannot convert `ReEarlyBound(0, 'a)` to a region vid

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:931:9
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:77
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:61
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1028
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1412
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:65
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:50
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:188
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:205
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:468
  12: std::panicking::begin_panic
  13: rustc_errors::HandlerInner::bug
  14: rustc_errors::Handler::bug
  15: rustc::util::bug::opt_span_bug_fmt::{{closure}}
  16: rustc::ty::context::tls::with_opt::{{closure}}
  17: rustc::ty::context::tls::with_context_opt
  18: rustc::ty::context::tls::with_opt
  19: rustc::util::bug::opt_span_bug_fmt
  20: rustc::util::bug::bug_fmt
  21: rustc_mir::borrow_check::nll::universal_regions::UniversalRegionIndices::to_region_vid::{{closure}}
  22: rustc_mir::borrow_check::nll::universal_regions::UniversalRegionIndices::to_region_vid
  23: rustc_mir::borrow_check::nll::type_check::constraint_conversion::ConstraintConversion::convert_all
  24: rustc_mir::borrow_check::nll::type_check::TypeChecker::fully_perform_op
  25: rustc_mir::borrow_check::nll::type_check::type_check
  26: rustc_mir::borrow_check::nll::compute_regions
  27: rustc_mir::borrow_check::do_mir_borrowck
  28: rustc::ty::context::GlobalCtxt::enter_local
  29: rustc_mir::borrow_check::mir_borrowck
  30: rustc::ty::query::__query_compute::mir_borrowck
  31: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::mir_borrowck>::compute
  32: rustc::dep_graph::graph::DepGraph::with_task_impl
  33: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  34: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::ensure_query
  35: rustc_mir::transform::optimized_mir
  36: rustc::ty::query::__query_compute::optimized_mir
  37: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::optimized_mir>::compute
  38: rustc::dep_graph::graph::DepGraph::with_task_impl
  39: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  40: rustc_mir::interpret::eval_context::InterpCx<M>::load_mir
  41: rustc_mir::const_eval::const_eval_raw_provider
  42: rustc::ty::query::__query_compute::const_eval_raw
  43: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::const_eval_raw>::compute
  44: rustc::dep_graph::graph::DepGraph::with_task_impl
  45: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  46: rustc_mir::const_eval::const_eval_provider
  47: rustc::ty::query::__query_compute::const_eval
  48: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::const_eval>::compute
  49: rustc::dep_graph::graph::DepGraph::with_task_impl
  50: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  51: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  52: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  53: rustc_typeck::check::FnCtxt::check_decl_initializer
  54: rustc_typeck::check::FnCtxt::check_decl_local
  55: rustc_typeck::check::FnCtxt::check_stmt
  56: rustc_typeck::check::FnCtxt::check_block_with_expected
  57: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  58: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  59: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  60: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  61: rustc_typeck::check::FnCtxt::check_block_with_expected
  62: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  63: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  64: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_return_expr
  65: rustc_typeck::check::check_fn
  66: rustc_typeck::check::closure::<impl rustc_typeck::check::FnCtxt>::check_expr_closure
  67: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  68: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  69: rustc_typeck::check::FnCtxt::check_argument_types
  70: rustc_typeck::check::callee::<impl rustc_typeck::check::FnCtxt>::confirm_builtin_call
  71: rustc_typeck::check::callee::<impl rustc_typeck::check::FnCtxt>::check_call
  72: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  73: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  74: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_return_expr
  75: rustc_typeck::check::check_fn
  76: rustc::ty::context::tls::with_context::{{closure}}
  77: rustc_typeck::check::typeck_tables_of
  78: rustc::ty::query::__query_compute::typeck_tables_of
  79: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::typeck_tables_of>::compute
  80: rustc::dep_graph::graph::DepGraph::with_task_impl
  81: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  82: rustc::ty::query::__query_compute::typeck_tables_of
  83: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::typeck_tables_of>::compute
  84: rustc::dep_graph::graph::DepGraph::with_task_impl
  85: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  86: rustc_typeck::collect::checked_type_of
  87: rustc_typeck::collect::type_of
  88: rustc::ty::query::__query_compute::type_of
  89: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::type_of>::compute
  90: rustc::dep_graph::graph::DepGraph::with_task_impl
  91: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  92: rustc::hir::intravisit::walk_expr
  93: rustc::hir::intravisit::Visitor::visit_fn
  94: rustc::hir::intravisit::walk_impl_item
  95: rustc::hir::map::Map::visit_item_likes_in_module
  96: rustc_typeck::collect::collect_mod_item_types
  97: rustc::ty::query::__query_compute::collect_mod_item_types
  98: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::collect_mod_item_types>::compute
  99: rustc::dep_graph::graph::DepGraph::with_task_impl
 100: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
 101: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::ensure_query
 102: rustc_typeck::check_crate::{{closure}}::{{closure}}
 103: rustc::util::common::time
 104: rustc_typeck::check_crate
 105: rustc_interface::passes::analysis
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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.40.0 (73528e339 2019-12-16) running on x86_64-unknown-linux-gnu

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

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

query stack during panic:
#0 [mir_borrowck] processing `conn::Handshake::<'a>::send::{{closure}}#0::{{constant}}#0`
#1 [optimized_mir] processing `conn::Handshake::<'a>::send::{{closure}}#0::{{constant}}#0`
#2 [const_eval_raw] const-evaluating `conn::Handshake::<'a>::send::{{closure}}#0::{{constant}}#0`
#3 [const_eval] const-evaluating + checking `conn::Handshake::<'a>::send::{{closure}}#0::{{constant}}#0`
#4 [typeck_tables_of] processing `conn::Handshake::<'a>::send`
#5 [typeck_tables_of] processing `conn::Handshake::<'a>::send::{{closure}}#0`
#6 [type_of] processing `conn::Handshake::<'a>::send::{{closure}}#0`
#7 [collect_mod_item_types] collecting item types in module `conn`
#8 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error

error: could not compile `btrs`.
Version info
~/btrs$ rustc --version --verbose
rustc 1.40.0 (73528e339 2019-12-16)
binary: rustc
commit-hash: 73528e339aae0f17a15ffa49a8ac608f50c6cf14
commit-date: 2019-12-16
host: x86_64-unknown-linux-gnu
release: 1.40.0
LLVM version: 9.0
@95th
Copy link
Contributor Author

95th commented Jan 25, 2020

The ICE also goes away if I change [0; Self::LEN] to vec![0; Self::LEN]

@95th
Copy link
Contributor Author

95th commented Jan 25, 2020

Ok. I minimized it to just:

fn main() {}

struct A<'a>(&'a ());

impl<'a> A<'a> {
    const N: usize = 68;

    fn foo(&self) {
        let mut b = [0; Self::N];
    }
}

It ICEs on latest nightly: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=7cc81a6eead5acb39f6a3ca58131ed0f

@JohnTitor JohnTitor added A-mir Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html 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 25, 2020
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Jan 26, 2020
@pnkfelix
Copy link
Member

pnkfelix commented Feb 6, 2020

triage: P-high, assiging to self, removing nomination label

@pnkfelix pnkfelix self-assigned this Feb 6, 2020
@pnkfelix pnkfelix added P-high High priority and removed I-nominated labels Feb 6, 2020
@95th
Copy link
Contributor Author

95th commented Mar 4, 2020

Following example fails to compile:

pub struct A<T>(T);

impl<T> A<T> {
    pub const N: usize = 68;

    pub fn foo(&self) {
        let b = [0; Self::N];
        println!("{}", b.len());
    }
}
Error
error[E0277]: the size for values of type `T` cannot be known at compilation time
 --> src/main.rs:9:21
  |
3 | pub struct A<T>(T);
  | ------------------- required by `A`
4 | 
5 | impl<T> A<T> {
  |      - this type parameter needs to be `std::marker::Sized`
...
9 |         let b = [0; Self::N];
  |                     ^^^^^^^ doesn't have a size known at compile-time
  |
  = help: the trait `std::marker::Sized` is not implemented for `T`
  = note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>

Even if I add T: Sized, still issue:

    pub fn foo(&self) where T: Sized {
        let b = [0; Self::N];
        println!("{}", b.len());
    }

or

impl<T: Sized> A<T> {
    pub const N: usize = 68;

    pub fn foo(&self) {
        let b = [0; Self::N];
        println!("{}", b.len());
    }
}
Error
error[E0277]: the size for values of type `T` cannot be known at compilation time
 --> src/main.rs:9:21
  |
3 | pub struct A<T>(T);
  | ------------------- required by `A`
4 | 
5 | impl<T> A<T> {
  |      - this type parameter needs to be `std::marker::Sized`
...
9 |         let b = [0; Self::N];
  |                     ^^^^^^^ doesn't have a size known at compile-time
  |
  = help: the trait `std::marker::Sized` is not implemented for `T`
  = note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>

But this works:

pub struct A<T>(T);

impl<T> A<T> {
    pub const N: usize = 68;

    pub fn foo(&self) {
        let b = Self::N;
        println!("{}", b);
    }
}

@stormmq
Copy link

stormmq commented Apr 16, 2020

Also just got this; no idea how to minimize it and the trace doesn't seem useful:-

error: internal compiler error: src/librustc_mir/borrow_check/universal_regions.rs:754: cannot convert `ReEarlyBound(0, 'a)` to a region vid

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:880:9
stack backtrace:
   0:        0x10b21cf6f - <unknown>
   1:        0x10b251f5e - <unknown>
   2:        0x10b20e217 - <unknown>
   3:        0x10b22191a - <unknown>
   4:        0x10b22165c - <unknown>
   5:        0x10f9217f8 - <unknown>
   6:        0x10b222035 - <unknown>
   7:        0x1138bb5e6 - <unknown>
   8:        0x113576037 - <unknown>
   9:        0x113574cf7 - <unknown>
  10:        0x1132d71a0 - <unknown>
  11:        0x1132ccd66 - <unknown>
  12:        0x1132cccec - <unknown>
  13:        0x1132d70a8 - <unknown>
  14:        0x1138b473b - <unknown>
  15:        0x1122006ac - <unknown>
  16:        0x11220060a - <unknown>
  17:        0x1120bc13e - <unknown>
  18:        0x1124b6f24 - <unknown>
  19:        0x1121f0c88 - <unknown>
  20:        0x1123ef10e - <unknown>
  21:        0x1124aef9a - <unknown>
  22:        0x1123ec87a - <unknown>
  23:        0x1120b46ca - <unknown>
  24:        0x112449edb - <unknown>
  25:        0x112253042 - <unknown>
  26:        0x112477519 - <unknown>
  27:        0x11244a692 - <unknown>
  28:        0x1123fa81c - <unknown>
  29:        0x1120b4a8a - <unknown>
  30:        0x112449fcb - <unknown>
  31:        0x11225e0a2 - <unknown>
  32:        0x11244eca8 - <unknown>
  33:        0x1122c6593 - <unknown>
  34:        0x112431f70 - <unknown>
  35:        0x1120b4d46 - <unknown>
  36:        0x11244a098 - <unknown>
  37:        0x11225115b - <unknown>
  38:        0x11248e697 - <unknown>
  39:        0x112430eba - <unknown>
  40:        0x1120b5e26 - <unknown>
  41:        0x11244a458 - <unknown>
  42:        0x1122641e1 - <unknown>
  43:        0x112453853 - <unknown>
  44:        0x112430c2a - <unknown>
  45:        0x1131478ec - <unknown>
  46:        0x112f98608 - <unknown>
  47:        0x113316325 - <unknown>
  48:        0x112e81de4 - <unknown>
  49:        0x112e72cb2 - <unknown>
  50:        0x112c92577 - <unknown>
  51:        0x112c9a6fe - <unknown>
  52:        0x112bd1bf1 - <unknown>
  53:        0x112c9a18e - <unknown>
  54:        0x111c15ea1 - <unknown>
  55:        0x111c0014c - <unknown>
  56:        0x111d36462 - <unknown>
  57:        0x111cf789f - <unknown>
  58:        0x111c64518 - <unknown>
  59:        0x111c5932a - <unknown>
  60:        0x111c833db - <unknown>
  61:        0x111bed77f - <unknown>
  62:        0x111cd24ea - <unknown>
  63:        0x111c83850 - <unknown>
  64:        0x111bb6e98 - <unknown>
  65:        0x111d0e83d - <unknown>
  66:        0x111c13e91 - <unknown>
  67:        0x111d2be80 - <unknown>
  68:        0x10fb484ca - <unknown>
  69:        0x10f92b5c9 - <unknown>
  70:        0x10f985595 - <unknown>
  71:        0x10f961403 - <unknown>
  72:        0x10f993c3c - <unknown>
  73:        0x10f966068 - <unknown>
  74:        0x10f927e85 - <unknown>
  75:        0x10f968b7c - <unknown>
  76:        0x10b1fe56e - <unknown>
  77:        0x10b230376 - <unknown>
  78:     0x7fff71dcb2eb - <unknown>
  79:     0x7fff71dce249 - <unknown>

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.44.0-nightly (1057dc97a 2020-03-20) running on x86_64-apple-darwin

note: compiler flags: -C debuginfo=2 -C linker=x86_64-linux-musl-cc -C incremental --crate-type lib

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

query stack during panic:
#0 [mir_borrowck] borrow-checking `file_descriptors::directory::DirectoryEntryIterator::buffer::{{constant}}#0`
#1 [optimized_mir] processing `file_descriptors::directory::DirectoryEntryIterator::buffer::{{constant}}#0`
#2 [const_eval_raw] const-evaluating `file_descriptors::directory::DirectoryEntryIterator::buffer::{{constant}}#0`
#3 [const_eval_validated] const-evaluating + checking `file_descriptors::directory::DirectoryEntryIterator::buffer::{{constant}}#0`
#4 [const_eval_validated] const-evaluating + checking `file_descriptors::directory::DirectoryEntryIterator::buffer::{{constant}}#0`
#5 [check_item_well_formed] processing `file_descriptors::directory::DirectoryEntryIterator`
#6 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error

error: could not compile `linux-support`.

@stormmq
Copy link

stormmq commented Apr 16, 2020

If this is referring to the field buffer, it's defined as buffer: [u8; Self::BufferCapacity], where BufferCapacity is defined inside the impl as const BufferCapacity: usize = 2048;.

@stormmq
Copy link

stormmq commented Apr 16, 2020

Inlining BufferCapacity resolves the error, ie changing buffer's definition to buffer: [u8; 2048].

@JohnTitor
Copy link
Member

JohnTitor commented May 25, 2020

The ICE no longer happens with the latest nightly (note that the playground's nightly isn't the latest). That delay_span_bug was removed by #72362. Marked as E-needs-test.

@JohnTitor JohnTitor added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label May 25, 2020
JohnTitor added a commit to JohnTitor/rust that referenced this issue May 26, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue May 29, 2020
@bors bors closed this as completed in 89cb4d7 May 29, 2020
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. 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) ❄️ P-high High priority 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.

6 participants