rust-lang / rust-lang/rust

error: internal compiler error: compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs:486:17: cannot relate region: LUB('{erased}, '{erased})

Open
#127,033 13 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug fixed-by-next-solver I-ICE S-bug-has-test T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I wasn't able to reduce this more

Code
#[derive(serde::Serialize, serde::Deserialize)]
pub struct MyRequest {}

#[derive(serde::Serialize, serde::Deserialize)]
pub struct MyResp {}
openraft::declare_raft_types!(
    pub MyTypeConfig:
        D = MyRequest,
        R = MyResp,
        NodeId = u64,
        Node = openraft::BasicNode,
        Entry = openraft::Entry<MyTypeConfig>,
        SnapshotData = std::io::Cursor<Vec<u8>>,
        AsyncRuntime = openraft::TokioRuntime,
);

pub struct MyLogReader {}

impl<C: openraft::RaftTypeConfig> openraft::storage::RaftLogReader<C> for MyLogReader {
    fn try_get_log_entries<RB: std::ops::RangeBounds<u64>>(
        &mut self,
        range: RB,
    ) -> impl std::future::Future<Output = Result<Vec<C::Entry>, openraft::StorageError<C::NodeId>>>
    {
        std::future::pending()
    }
}

use openraft::RaftTypeConfig;

pub struct MyLogStorage {
    node_id: <MyTypeConfig as RaftTypeConfig>::NodeId,
}

impl MyLogStorage {
    pub fn new(node_id: <MyTypeConfig as RaftTypeConfig>::NodeId) -> Self {
        Self { node_id }
    }
}

impl<C: openraft::RaftTypeConfig<NodeId = u64>> openraft::storage::RaftLogReader<C>
    for MyLogStorage
{
    fn try_get_log_entries<RB: std::ops::RangeBounds<u64> + std::fmt::Debug>(
        &mut self,
        range: RB,
    ) -> impl std::future::Future<Output = Result<Vec<C::Entry>, openraft::StorageError<C::NodeId>>>
    {
        std::future::pending()
    }
}

impl<C: openraft::RaftTypeConfig<NodeId = u64>> openraft::storage::RaftLogStorage<C>
    for MyLogStorage
{
    type LogReader = MyLogReader;

    fn get_log_state(
        &mut self,
    ) -> impl std::future::Future<
        Output = Result<openraft::LogState<C>, openraft::StorageError<C::NodeId>>,
    > {
        std::future::pending()
    }

    fn get_log_reader(&mut self) -> impl std::future::Future<Output = Self::LogReader> {
        std::future::pending()
    }

    fn save_vote(
        &mut self,
        vote: &openraft::Vote<C::NodeId>,
    ) -> impl std::future::Future<Output = Result<(), openraft::StorageError<C::NodeId>>> {
        todo!();
        async move {
            let vote = serde_json::to_vec(vote).unwrap();
            tokio::fs::write(&format!("{}.vote", self.node_id), vote).await;
            Ok(())
        }
    }

    fn read_vote(
        &mut self,
    ) -> impl std::future::Future<
        Output = Result<Option<openraft::Vote<C::NodeId>>, openraft::StorageError<C::NodeId>>,
    > {
        std::future::pending()
    }

    fn append<I: IntoIterator<Item = C::Entry> + Send>(
        &mut self,
        entries: I,
        callback: openraft::storage::LogFlushed<C>,
    ) -> impl std::future::Future<Output = Result<(), openraft::StorageError<C::NodeId>>> {
        std::future::pending()
    }

    fn truncate(
        &mut self,
        log_id: openraft::LogId<C::NodeId>,
    ) -> impl std::future::Future<Output = Result<(), openraft::StorageError<C::NodeId>>> {
        std::future::pending()
    }

    fn purge(
        &mut self,
        log_id: openraft::LogId<C::NodeId>,
    ) -> impl std::future::Future<Output = Result<(), openraft::StorageError<C::NodeId>>> {
        std::future::pending()
    }
}
[package]
name = "crash"
version = "0.1.0"
edition = "2021"

[lib]

[dependencies]
anyhow = "1.0.86"
openraft = { version = "0.9.11", features = ["tracing-log", "storage-v2", "serde"] }
serde = { version = "1.0.203", features = ["derive"] }
serde_json = "1.0.117"
tokio = { version = "1.38.0", features = ["full"] }

Meta

rustc --version --verbose:

rustc 1.79.0 (129f3b996 2024-06-10)
binary: rustc
commit-hash: 129f3b9964af4d4a709d1383930ade12dfe7c081
commit-date: 2024-06-10
host: aarch64-apple-darwin
release: 1.79.0
LLVM version: 18.1.7
Error output
[<output>](error: internal compiler error: compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs:486:17: cannot relate region: LUB('{erased}, '{erased}))
Backtrace

RUST_BACKTRACE=1 cargo b
   Compiling crash v0.1.0 (/Users/frja/dev/rust/rustc-crash)
warning: unused variable: `range`
  --> src/lib.rs:22:9
   |
22 |         range: RB,
   |         ^^^^^ help: if this is intentional, prefix it with an underscore: `_range`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: unused variable: `range`
  --> src/lib.rs:46:9
   |
46 |         range: RB,
   |         ^^^^^ help: if this is intentional, prefix it with an underscore: `_range`

warning: unreachable expression
  --> src/lib.rs:75:9
   |
74 |           todo!();
   |           ------- any code following this expression is unreachable
75 | /         async move {
76 | |             let vote = serde_json::to_vec(vote).unwrap();
77 | |             tokio::fs::write(&format!("{}.vote", self.node_id), vote).await;
78 | |             Ok(())
79 | |         }
   | |_________^ unreachable expression
   |
   = note: `#[warn(unreachable_code)]` on by default

warning: unused variable: `vote`
  --> src/lib.rs:72:9
   |
72 |         vote: &openraft::Vote<C::NodeId>,
   |         ^^^^ help: if this is intentional, prefix it with an underscore: `_vote`

error: internal compiler error: compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs:486:17: cannot relate region: LUB('{erased}, '{erased})

thread 'rustc' panicked at compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs:486:17:
Box<dyn Any>
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   2: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   3: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   4: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
   5: rustc_middle::util::bug::bug_fmt
   6: <rustc_infer::infer::lexical_region_resolve::LexicalResolver>::lub_concrete_regions
   7: rustc_infer::infer::lexical_region_resolve::resolve
   8: <rustc_infer::infer::InferCtxt as rustc_trait_selection::regions::InferCtxtRegionExt>::resolve_regions
   9: <rustc_trait_selection::traits::engine::ObligationCtxt>::resolve_regions_and_report_errors
  10: rustc_hir_analysis::check::compare_impl_item::collect_return_position_impl_trait_in_trait_tys
      [... omitted 2 frames ...]
  11: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefIdCache<rustc_middle::query::erase::Erased<[u8; 8]>>>
  12: rustc_hir_analysis::collect::type_of::type_of
      [... omitted 2 frames ...]
  13: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefIdCache<rustc_middle::query::erase::Erased<[u8; 8]>>>
  14: <core::iter::adapters::map::Map<core::iter::adapters::flatten::FlatMap<core::slice::iter::Iter<rustc_span::def_id::DefId>, alloc::vec::Vec<rustc_hir_analysis::constrained_generic_params::Parameter>, rustc_hir_analysis::impl_wf_check::enforce_impl_params_are_constrained::{closure#0}>, <hashbrown::set::HashSet<rustc_hir_analysis::constrained_generic_params::Parameter, core::hash::BuildHasherDefault<rustc_hash::FxHasher>> as core::iter::traits::collect::Extend<rustc_hir_analysis::constrained_generic_params::Parameter>>::extend<core::iter::adapters::flatten::FlatMap<core::slice::iter::Iter<rustc_span::def_id::DefId>, alloc::vec::Vec<rustc_hir_analysis::constrained_generic_params::Parameter>, rustc_hir_analysis::impl_wf_check::enforce_impl_params_are_constrained::{closure#0}>>::{closure#0}> as core::iter::traits::iterator::Iterator>::fold::<(), core::iter::traits::iterator::Iterator::for_each::call<(rustc_hir_analysis::constrained_generic_params::Parameter, ()), <hashbrown::map::HashMap<rustc_hir_analysis::constrained_generic_params::Parameter, (), core::hash::BuildHasherDefault<rustc_hash::FxHasher>> as core::iter::traits::collect::Extend<(rustc_hir_analysis::constrained_generic_params::Parameter, ())>>::extend<core::iter::adapters::map::Map<core::iter::adapters::flatten::FlatMap<core::slice::iter::Iter<rustc_span::def_id::DefId>, alloc::vec::Vec<rustc_hir_analysis::constrained_generic_params::Parameter>, rustc_hir_analysis::impl_wf_check::enforce_impl_params_are_constrained::{closure#0}>, <hashbrown::set::HashSet<rustc_hir_analysis::constrained_generic_params::Parameter, core::hash::BuildHasherDefault<rustc_hash::FxHasher>> as core::iter::traits::collect::Extend<rustc_hir_analysis::constrained_generic_params::Parameter>>::extend<core::iter::adapters::flatten::FlatMap<core::slice::iter::Iter<rustc_span::def_id::DefId>, alloc::vec::Vec<rustc_hir_analysis::constrained_generic_params::Parameter>, rustc_hir_analysis::impl_wf_check::enforce_impl_params_are_constrained::{closure#0}>>::{closure#0}>>::{closure#0}>::{closure#0}>
  15: <hashbrown::map::HashMap<rustc_hir_analysis::constrained_generic_params::Parameter, (), core::hash::BuildHasherDefault<rustc_hash::FxHasher>> as core::iter::traits::collect::Extend<(rustc_hir_analysis::constrained_generic_params::Parameter, ())>>::extend::<core::iter::adapters::map::Map<core::iter::adapters::flatten::FlatMap<core::slice::iter::Iter<rustc_span::def_id::DefId>, alloc::vec::Vec<rustc_hir_analysis::constrained_generic_params::Parameter>, rustc_hir_analysis::impl_wf_check::enforce_impl_params_are_constrained::{closure#0}>, <hashbrown::set::HashSet<rustc_hir_analysis::constrained_generic_params::Parameter, core::hash::BuildHasherDefault<rustc_hash::FxHasher>> as core::iter::traits::collect::Extend<rustc_hir_analysis::constrained_generic_params::Parameter>>::extend<core::iter::adapters::flatten::FlatMap<core::slice::iter::Iter<rustc_span::def_id::DefId>, alloc::vec::Vec<rustc_hir_analysis::constrained_generic_params::Parameter>, rustc_hir_analysis::impl_wf_check::enforce_impl_params_are_constrained::{closure#0}>>::{closure#0}>>
  16: rustc_hir_analysis::impl_wf_check::check_impl_wf
  17: rustc_hir_analysis::check::wfcheck::check_well_formed
      [... omitted 2 frames ...]
  18: std::panicking::try::<core::result::Result<(), rustc_span::ErrorGuaranteed>, core::panic::unwind_safe::AssertUnwindSafe<rustc_data_structures::sync::parallel::disabled::try_par_for_each_in<&[rustc_hir::hir::ForeignItemId], rustc_span::ErrorGuaranteed, <rustc_middle::hir::ModuleItems>::par_foreign_items<rustc_hir_analysis::check::wfcheck::check_mod_type_wf::{closure#3}>::{closure#0}>::{closure#0}::{closure#0}::{closure#0}>>
  19: rustc_data_structures::sync::parallel::disabled::try_par_for_each_in::<&[rustc_hir::hir::ItemId], rustc_span::ErrorGuaranteed, <rustc_middle::hir::ModuleItems>::par_items<rustc_hir_analysis::check::wfcheck::check_mod_type_wf::{closure#0}>::{closure#0}>
  20: rustc_hir_analysis::check::wfcheck::check_mod_type_wf
      [... omitted 2 frames ...]
  21: std::panicking::try::<(), core::panic::unwind_safe::AssertUnwindSafe<rustc_data_structures::sync::parallel::disabled::par_for_each_in<&[rustc_hir::hir_id::OwnerId], <rustc_middle::hir::map::Map>::par_for_each_module<rustc_hir_analysis::check_crate::{closure#1}::{closure#0}>::{closure#0}>::{closure#0}::{closure#0}::{closure#0}>>
  22: rustc_data_structures::sync::parallel::disabled::par_for_each_in::<&[rustc_hir::hir_id::OwnerId], <rustc_middle::hir::map::Map>::par_for_each_module<rustc_hir_analysis::check_crate::{closure#1}::{closure#0}>::{closure#0}>
  23: rustc_hir_analysis::check_crate
  24: rustc_interface::passes::analysis
      [... omitted 2 frames ...]
  25: <rustc_middle::ty::context::GlobalCtxt>::enter::<rustc_driver_impl::run_compiler::{closure#0}::{closure#1}::{closure#3}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
  26: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#0}::{closure#1}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_span::ErrorGuaranteed>>
  27: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
  28: rustc_span::create_session_globals_then::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_interface::util::run_in_thread_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}::{closure#0}>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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.79.0 (129f3b996 2024-06-10) running on aarch64-apple-darwin

note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked -C incremental=[REDACTED]

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

query stack during panic:
#0 [collect_return_position_impl_trait_in_trait_tys] comparing an impl and trait method signature, inferring any hidden `impl Trait` types in the process
#1 [type_of] computing type of `<impl at src/lib.rs:53:1: 54:21>::{synthetic#2}`
#2 [check_well_formed] checking that `<impl at src/lib.rs:53:1: 54:21>` is well-formed
#3 [check_mod_type_wf] checking that types are well-formed in top-level module
#4 [analysis] running analysis passes on this crate
end of query stack
warning: unused variable: `entries`
  --> src/lib.rs:92:9
   |
92 |         entries: I,
   |         ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_entries`

warning: unused variable: `callback`
  --> src/lib.rs:93:9
   |
93 |         callback: openraft::storage::LogFlushed<C>,
   |         ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_callback`

warning: unused variable: `log_id`
   --> src/lib.rs:100:9
    |
100 |         log_id: openraft::LogId<C::NodeId>,
    |         ^^^^^^ help: if this is intentional, prefix it with an underscore: `_log_id`

warning: unused variable: `log_id`
   --> src/lib.rs:107:9
    |
107 |         log_id: openraft::LogId<C::NodeId>,
    |         ^^^^^^ help: if this is intentional, prefix it with an underscore: `_log_id`

warning: `crash` (lib) generated 8 warnings
error: could not compile `crash` (lib); 8 warnings emitted

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the ICE with the minimal crate and cargo build using the reported Rust 1.79.0 toolchain. Start at compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs:486 and the stack entry collect_return_position_impl_trait_in_trait_tys; done means the example no longer causes an internal compiler error.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.