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 erased region to a region VID #131050

Closed
cycle-five opened this issue Sep 30, 2024 · 9 comments · Fixed by #134798
Closed

ICE: Cannot convert erased region to a region VID #131050

cycle-five opened this issue Sep 30, 2024 · 9 comments · Fixed by #134798
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@cycle-five
Copy link

cycle-five commented Sep 30, 2024

Code

mcve:

use std::future::Future;

fn invalid_future() -> impl Future {}

fn create_complex_future() -> impl Future<Output = impl ReturnsSend> {
    async { &|| async { invalid_future().await } }
}

fn coerce_impl_trait() -> impl Future<Output = impl Send> {
    create_complex_future()
}

trait ReturnsSend {}

impl<F, R> ReturnsSend for F
where
    F: Fn() -> R,
    R: Send,
{
}
original

/// Implementation for [CasinoContext]
impl CasinoContext {
    /// Create a new instance of `[CasinoContext]` given a database pool.
    fn new(db: SqlitePool) -> Self {
        Self { db: Arc::new(db) }
    }

    /// Get all transactions for a user.
    async fn get_transactions(&self, user_id: i64) -> Result<Vec<Transaction>, sqlx::Error> {
        let transactions = sqlx::query_as!(
                Transaction,
                r#"SELECT * FROM transaction WHERE user_id = $1"#,
                user_id
            )
            .fetch_all(&*self.db)
            .await?;
        Ok(transactions)
    }

    /// Get all transactions for a user.
    async fn get_transactions_all(&self) -> Result<Vec<Transaction>, sqlx::Error> {
        let transactions = sqlx::query_as!(
                Transaction,
                r#"SELECT * FROM transaction ORDER BY created_at desc"#,
            )
            .fetch_all(&*self.db)
            .await?;
        Ok(transactions)
    }

    /// Get a user by their id.
    async fn get_user(&self, user_id: i64) -> Result<Vec<User>, sqlx::Error> {
        let user = sqlx::query_as!(User, "SELECT * FROM user WHERE id = $1", user_id)
            .fetch_all(&*self.db)
            .await?;
        Ok(user)
    }

    /// Check if a user and/or email already exists.
    async fn check_username_email(&self, email: &str, username: &str) -> Result<(), sqlx::Error> {
        // We are entirely using the Errors to communicate what has happened here.
        // I think this is the idiomatic way to do this in Rust, since they are also
        // error states.
        let matches = sqlx::query!("SELECT COUNT(*) as cnt FROM user WHERE email = $1", email)
            .fetch_one(&*self.db)
            .await?;
        if matches.cnt > 0 {
            return Err(sqlx::Error::RowNotFound);
        }

        let matches = sqlx::query!(
            "SELECT COUNT(*) as cnt FROM user WHERE username = $1",
            username
        )
        .fetch_one(&*self.db)
        .await?;
        if matches.cnt > 0 {
            return Err(sqlx::Error::RowNotFound);
        }
        Ok(())
    }

    /// Create a new user.
    async fn create_user(&self, email: &str, username: &str) -> Result<CBUserId, sqlx::Error> {
        tracing::trace!("Creating user with email: {} and username: {}", email, username);
        // This shouldn't fail because we don't have any constraints on the email or username.
        // Do we want to constrain these in the database?
        // Should be checking for existing users with the same email or username?
        let user_id = sqlx::query_as!(
            CBUserId,
            "INSERT INTO user (email, username) VALUES ($1, $2) RETURNING id",
            email,
            username
        )
        .fetch_one(&*self.db)
        .await?;
        Ok(user_id)
    }

    /// Create a new transaction, these are the purchases of coins from the casinos.
    async fn create_transaction(
        &self,
        user_id: i64,
        casino_id: i64,
        cost: i64,
        benefit: i64,
        notes: Option<String>,
    ) -> Result<Transaction, sqlx::Error> {
        let transaction = sqlx::query_as!(
            Transaction,
            r#"INSERT INTO "transaction" (user_id, casino_id, cost, benefit, notes) VALUES ($1, $2, $3, $4, $5) RETURNING *"#,
            user_id,
            casino_id,
            cost,
            benefit,
            notes
        )
        .fetch_one(&*self.db)
        .await?;
        Ok(transaction)
    }

    //TODO: Create a redemption entry.

    /// Process a request to get all transactions for a user.
    async fn process_get_transaction(&self, user_id: i64) -> Result<impl Reply, Rejection> {
        let transactions = self.get_transactions(user_id).await.map_err(Sqlx)?;
        Ok(warp::reply::json(&TransactionsReplyBody { body: transactions }))
    }

    /// Process a request to get a user by their id.
    async fn process_get_user(&self, user_id: i64) -> Result<impl Reply, Rejection> {
        let user = self.get_user(user_id).await.map_err(Sqlx)?;
        Ok(warp::reply::json(&UserReplyBody { body: user }))
    }

    /// Process a request to create a new user.
    async fn process_post_user(
        &self,
        email: &str,
        username: &str,
    ) -> Result<impl Reply, Rejection> {
        self.check_username_email(email, username)
            .await
            .map_err(Sqlx)?;
        let user_id = self.create_user(email, username).await.map_err(Sqlx)?;
        Ok(warp::reply::json(&user_id))
    }

    /// Process a request to create a new transaction.
    async fn process_put_transaction(
        &self,
        user_id: i64,
        casino_id: i64,
        cost: i64,
        benefit: i64,
        notes: &Option<String>,
    ) -> Result<impl Reply, Rejection> {
        let transaction = self.create_transaction(user_id, casino_id, cost, benefit, notes.clone()).await.map_err(Sqlx)?;
        Ok(warp::reply::with_status(warp::reply::json(&transaction), StatusCode::CREATED))
    }
}

Meta

rustc --version --verbose:

rustc 1.83.0-nightly (7608018cb 2024-09-29)
binary: rustc
commit-hash: 7608018cbdac9e55d0d13529cf43adc33d53efcf
commit-date: 2024-09-29
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.0

Error output

error: error returned from database: (code: 1) near "transaction": syntax error
   --> src/lib.rs:127:28
    |
127 |           let transactions = sqlx::query_as!(
    |  ____________________________^
128 | |                 Transaction,
129 | |                 r#"SELECT * FROM transaction WHERE user_id = $1"#,
130 | |                 user_id
131 | |             )
    | |_____________^
    |
    = note: this error originates in the macro `$crate::sqlx_macros::expand_query` which comes from the expansion of the macro `sqlx::query_as` (in Nightly builds, run with -Z macro-backtrace for more info)

error: error returned from database: (code: 1) near "transaction": syntax error
   --> src/lib.rs:139:28
    |
139 |           let transactions = sqlx::query_as!(
    |  ____________________________^
140 | |                 Transaction,
141 | |                 r#"SELECT * FROM transaction ORDER BY created_at desc"#,
142 | |             )
    | |_____________^
    |
    = note: this error originates in the macro `$crate::sqlx_macros::expand_query` which comes from the expansion of the macro `sqlx::query_as` (in Nightly builds, run with -Z macro-backtrace for more info)

error: internal compiler error: compiler/rustc_borrowck/src/universal_regions.rs:907:36: cannot convert `'{erased}` to a region vid

thread 'rustc' panicked at compiler/rustc_borrowck/src/universal_regions.rs:907:36:
Box<dyn Any>
stack backtrace:
   0:     0x7d6a328d242a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h7265b42392dc0061
   1:     0x7d6a330033e6 - core::fmt::write::h2ec550f80b7defd0
   2:     0x7d6a341ba111 - std::io::Write::write_fmt::h36bfe942596e7c0c
   3:     0x7d6a328d2282 - std::sys::backtrace::BacktraceLock::print::h91696b5f38231729
   4:     0x7d6a328d47a1 - std::panicking::default_hook::{{closure}}::h9bab7dd14eb60554
   5:     0x7d6a328d45d4 - std::panicking::default_hook::hf96ee8bd37f2a078
   6:     0x7d6a3199f65f - std[809dc50e31fb3515]::panicking::update_hook::<alloc[75acf6d1be4cd817]::boxed::Box<rustc_driver_impl[a244f68c38eb9e43]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x7d6a328d4eb8 - std::panicking::rust_panic_with_hook::h78f8bdf8cf52544b
   8:     0x7d6a319d9811 - std[809dc50e31fb3515]::panicking::begin_panic::<rustc_errors[d1a36ca4270b0bc7]::ExplicitBug>::{closure#0}
   9:     0x7d6a319cc8b6 - std[809dc50e31fb3515]::sys::backtrace::__rust_end_short_backtrace::<std[809dc50e31fb3515]::panicking::begin_panic<rustc_errors[d1a36ca4270b0bc7]::ExplicitBug>::{closure#0}, !>
  10:     0x7d6a319cc879 - std[809dc50e31fb3515]::panicking::begin_panic::<rustc_errors[d1a36ca4270b0bc7]::ExplicitBug>
  11:     0x7d6a319e30a1 - <rustc_errors[d1a36ca4270b0bc7]::diagnostic::BugAbort as rustc_errors[d1a36ca4270b0bc7]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x7d6a32005b34 - rustc_middle[c34f140c15df42dd]::util::bug::opt_span_bug_fmt::<rustc_span[e7fc1a82842fb679]::span_encoding::Span>::{closure#0}
  13:     0x7d6a31feb87a - rustc_middle[c34f140c15df42dd]::ty::context::tls::with_opt::<rustc_middle[c34f140c15df42dd]::util::bug::opt_span_bug_fmt<rustc_span[e7fc1a82842fb679]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x7d6a31feb70b - rustc_middle[c34f140c15df42dd]::ty::context::tls::with_context_opt::<rustc_middle[c34f140c15df42dd]::ty::context::tls::with_opt<rustc_middle[c34f140c15df42dd]::util::bug::opt_span_bug_fmt<rustc_span[e7fc1a82842fb679]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x7d6a2f5cc9b0 - rustc_middle[c34f140c15df42dd]::util::bug::bug_fmt
  16:     0x7d6a335cf1b4 - <rustc_borrowck[d64214accbb30ce5]::type_check::TypeChecker>::push_region_constraints
  17:     0x7d6a33d39b09 - <rustc_borrowck[d64214accbb30ce5]::type_check::TypeChecker>::fully_perform_op::<(), rustc_borrowck[d64214accbb30ce5]::type_check::InstantiateOpaqueType>
  18:     0x7d6a33d39717 - <rustc_borrowck[d64214accbb30ce5]::type_check::relate_tys::NllTypeRelating>::relate_opaques
  19:     0x7d6a331e9f83 - <rustc_borrowck[d64214accbb30ce5]::type_check::relate_tys::NllTypeRelating as rustc_type_ir[34480bc390efd26e]::relate::TypeRelation<rustc_middle[c34f140c15df42dd]::ty::context::TyCtxt>>::tys
  20:     0x7d6a331f0e19 - <rustc_borrowck[d64214accbb30ce5]::type_check::TypeChecker>::typeck_mir
  21:     0x7d6a3402d8c0 - rustc_borrowck[d64214accbb30ce5]::type_check::type_check
  22:     0x7d6a330985c9 - rustc_borrowck[d64214accbb30ce5]::nll::compute_regions
  23:     0x7d6a33f8ff3c - rustc_borrowck[d64214accbb30ce5]::do_mir_borrowck
  24:     0x7d6a33f82187 - rustc_query_impl[cfbbd627f49a4903]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[cfbbd627f49a4903]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[c34f140c15df42dd]::query::erase::Erased<[u8; 8usize]>>
  25:     0x7d6a333b4194 - rustc_query_system[e532be48e014ea19]::query::plumbing::try_execute_query::<rustc_query_impl[cfbbd627f49a4903]::DynamicConfig<rustc_query_system[e532be48e014ea19]::query::caches::VecCache<rustc_span[e7fc1a82842fb679]::def_id::LocalDefId, rustc_middle[c34f140c15df42dd]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[cfbbd627f49a4903]::plumbing::QueryCtxt, true>
  26:     0x7d6a3338c7b4 - rustc_query_impl[cfbbd627f49a4903]::query_impl::mir_borrowck::get_query_incr::__rust_end_short_backtrace
  27:     0x7d6a338e1133 - rustc_middle[c34f140c15df42dd]::query::plumbing::query_get_at::<rustc_query_system[e532be48e014ea19]::query::caches::VecCache<rustc_span[e7fc1a82842fb679]::def_id::LocalDefId, rustc_middle[c34f140c15df42dd]::query::erase::Erased<[u8; 8usize]>>>
  28:     0x7d6a33e397cd - rustc_hir_analysis[c8e5db5b82070228]::collect::type_of::type_of_opaque
  29:     0x7d6a33e39633 - rustc_query_impl[cfbbd627f49a4903]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[cfbbd627f49a4903]::query_impl::type_of_opaque::dynamic_query::{closure#2}::{closure#0}, rustc_middle[c34f140c15df42dd]::query::erase::Erased<[u8; 8usize]>>
  30:     0x7d6a333905e6 - rustc_query_system[e532be48e014ea19]::query::plumbing::try_execute_query::<rustc_query_impl[cfbbd627f49a4903]::DynamicConfig<rustc_query_system[e532be48e014ea19]::query::caches::DefIdCache<rustc_middle[c34f140c15df42dd]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[cfbbd627f49a4903]::plumbing::QueryCtxt, true>
  31:     0x7d6a3413dbb9 - rustc_query_impl[cfbbd627f49a4903]::query_impl::type_of_opaque::get_query_incr::__rust_end_short_backtrace
  32:     0x7d6a334a8dc0 - rustc_middle[c34f140c15df42dd]::query::plumbing::query_get_at::<rustc_query_system[e532be48e014ea19]::query::caches::DefIdCache<rustc_middle[c34f140c15df42dd]::query::erase::Erased<[u8; 8usize]>>>
  33:     0x7d6a30ae4fc5 - rustc_hir_analysis[c8e5db5b82070228]::collect::type_of::type_of
  34:     0x7d6a33030670 - rustc_query_impl[cfbbd627f49a4903]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[cfbbd627f49a4903]::query_impl::type_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[c34f140c15df42dd]::query::erase::Erased<[u8; 8usize]>>
  35:     0x7d6a333905e6 - rustc_query_system[e532be48e014ea19]::query::plumbing::try_execute_query::<rustc_query_impl[cfbbd627f49a4903]::DynamicConfig<rustc_query_system[e532be48e014ea19]::query::caches::DefIdCache<rustc_middle[c34f140c15df42dd]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[cfbbd627f49a4903]::plumbing::QueryCtxt, true>
  36:     0x7d6a3338e0f6 - rustc_query_impl[cfbbd627f49a4903]::query_impl::type_of::get_query_incr::__rust_end_short_backtrace
  37:     0x7d6a334a8dc0 - rustc_middle[c34f140c15df42dd]::query::plumbing::query_get_at::<rustc_query_system[e532be48e014ea19]::query::caches::DefIdCache<rustc_middle[c34f140c15df42dd]::query::erase::Erased<[u8; 8usize]>>>
  38:     0x7d6a30acf718 - rustc_hir_analysis[c8e5db5b82070228]::check::wfcheck::check_well_formed
  39:     0x7d6a336836e7 - rustc_query_impl[cfbbd627f49a4903]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[cfbbd627f49a4903]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[c34f140c15df42dd]::query::erase::Erased<[u8; 1usize]>>
  40:     0x7d6a33686ee0 - rustc_query_system[e532be48e014ea19]::query::plumbing::try_execute_query::<rustc_query_impl[cfbbd627f49a4903]::DynamicConfig<rustc_query_system[e532be48e014ea19]::query::caches::VecCache<rustc_hir[591c87a2ef78e81c]::hir_id::OwnerId, rustc_middle[c34f140c15df42dd]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[cfbbd627f49a4903]::plumbing::QueryCtxt, true>
  41:     0x7d6a336868ce - rustc_query_impl[cfbbd627f49a4903]::query_impl::check_well_formed::get_query_incr::__rust_end_short_backtrace
  42:     0x7d6a33684497 - rustc_hir_analysis[c8e5db5b82070228]::check::wfcheck::check_mod_type_wf
  43:     0x7d6a336842d5 - rustc_query_impl[cfbbd627f49a4903]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[cfbbd627f49a4903]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[c34f140c15df42dd]::query::erase::Erased<[u8; 1usize]>>
  44:     0x7d6a33e786c4 - rustc_query_system[e532be48e014ea19]::query::plumbing::try_execute_query::<rustc_query_impl[cfbbd627f49a4903]::DynamicConfig<rustc_query_system[e532be48e014ea19]::query::caches::DefaultCache<rustc_span[e7fc1a82842fb679]::def_id::LocalModDefId, rustc_middle[c34f140c15df42dd]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[cfbbd627f49a4903]::plumbing::QueryCtxt, true>
  45:     0x7d6a33e7939b - rustc_query_impl[cfbbd627f49a4903]::query_impl::check_mod_type_wf::get_query_incr::__rust_end_short_backtrace
  46:     0x7d6a333adcbb - rustc_hir_analysis[c8e5db5b82070228]::check_crate
  47:     0x7d6a333aa957 - rustc_interface[88f4b8091d2ff47d]::passes::run_required_analyses
  48:     0x7d6a33d10a5e - rustc_interface[88f4b8091d2ff47d]::passes::analysis
  49:     0x7d6a33d10a31 - rustc_query_impl[cfbbd627f49a4903]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[cfbbd627f49a4903]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[c34f140c15df42dd]::query::erase::Erased<[u8; 1usize]>>
  50:     0x7d6a3406750d - rustc_query_system[e532be48e014ea19]::query::plumbing::try_execute_query::<rustc_query_impl[cfbbd627f49a4903]::DynamicConfig<rustc_query_system[e532be48e014ea19]::query::caches::SingleCache<rustc_middle[c34f140c15df42dd]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[cfbbd627f49a4903]::plumbing::QueryCtxt, true>
  51:     0x7d6a34066ffa - rustc_query_impl[cfbbd627f49a4903]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
  52:     0x7d6a33d20a9e - rustc_interface[88f4b8091d2ff47d]::interface::run_compiler::<core[35ecc2859a1cac9b]::result::Result<(), rustc_span[e7fc1a82842fb679]::ErrorGuaranteed>, rustc_driver_impl[a244f68c38eb9e43]::run_compiler::{closure#0}>::{closure#1}
  53:     0x7d6a33e22b10 - std[809dc50e31fb3515]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[88f4b8091d2ff47d]::util::run_in_thread_with_globals<rustc_interface[88f4b8091d2ff47d]::util::run_in_thread_pool_with_globals<rustc_interface[88f4b8091d2ff47d]::interface::run_compiler<core[35ecc2859a1cac9b]::result::Result<(), rustc_span[e7fc1a82842fb679]::ErrorGuaranteed>, rustc_driver_impl[a244f68c38eb9e43]::run_compiler::{closure#0}>::{closure#1}, core[35ecc2859a1cac9b]::result::Result<(), rustc_span[e7fc1a82842fb679]::ErrorGuaranteed>>::{closure#0}, core[35ecc2859a1cac9b]::result::Result<(), rustc_span[e7fc1a82842fb679]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[35ecc2859a1cac9b]::result::Result<(), rustc_span[e7fc1a82842fb679]::ErrorGuaranteed>>
  54:     0x7d6a33e2317a - <<std[809dc50e31fb3515]::thread::Builder>::spawn_unchecked_<rustc_interface[88f4b8091d2ff47d]::util::run_in_thread_with_globals<rustc_interface[88f4b8091d2ff47d]::util::run_in_thread_pool_with_globals<rustc_interface[88f4b8091d2ff47d]::interface::run_compiler<core[35ecc2859a1cac9b]::result::Result<(), rustc_span[e7fc1a82842fb679]::ErrorGuaranteed>, rustc_driver_impl[a244f68c38eb9e43]::run_compiler::{closure#0}>::{closure#1}, core[35ecc2859a1cac9b]::result::Result<(), rustc_span[e7fc1a82842fb679]::ErrorGuaranteed>>::{closure#0}, core[35ecc2859a1cac9b]::result::Result<(), rustc_span[e7fc1a82842fb679]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[35ecc2859a1cac9b]::result::Result<(), rustc_span[e7fc1a82842fb679]::ErrorGuaranteed>>::{closure#1} as core[35ecc2859a1cac9b]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  55:     0x7d6a33e2356b - std::sys::pal::unix::thread::Thread::new::thread_start::h632175f9045063b0
  56:     0x7d6a2e09ca94 - start_thread
                               at ./nptl/pthread_create.c:447:8
  57:     0x7d6a2e129c3c - clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
  58:                0x0 - <unknown>

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: please make sure that you have updated to the latest nightly

note: please attach the file at `/home/lothrop/src/casinobuddy.app/rustc-ice-2024-09-30T06_37_43-2821421.txt` to your bug report

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

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

query stack during panic:
#0 [mir_borrowck] borrow-checking `get_app`
#1 [type_of_opaque] computing type of opaque `get_app::{opaque#0}`
end of query stack
error: could not compile `casino-buddy` (lib) due to 2 previous errors
Backtrace

<backtrace>

@cycle-five cycle-five 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 Sep 30, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 30, 2024
@MohamedYassineBenomar
Copy link

This issue seems interesting! I would love to contribute or discuss further. 👍

@jieyouxu jieyouxu added the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Sep 30, 2024
@cyrgani
Copy link
Contributor

cyrgani commented Oct 2, 2024

A lot of types your code uses are not defined or imported. Please add their definitions so we can reproduce your issue, at least for CBUserId, Transaction, User and Sqlx. It wold also help if you included your Cargo.toml.
Thanks!

@cycle-five
Copy link
Author

cargo run
   Compiling casino-buddy v0.1.0 (/home/lothrop/src/casinobuddy.app)
error[E0308]: mismatched types
   --> src/lib.rs:167:12
    |
167 |         Ok(())
    |         -- ^^ expected `bool`, found `()`
    |         |
    |         arguments to this enum variant are incorrect
    |
help: the type constructed contains `()` due to the type of the argument passed
   --> src/lib.rs:167:9
    |
167 |         Ok(())
    |         ^^^--^
    |            |
    |            this argument influences the type of `Ok`
note: tuple variant defined here
   --> /home/lothrop/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/result.rs:531:5
    |
531 |     Ok(#[stable(feature = "rust1", since = "1.0.0")] T),
    |     ^^

error: internal compiler error: compiler/rustc_borrowck/src/universal_regions.rs:907:36: cannot convert `'{erased}` to a region vid

thread 'rustc' panicked at compiler/rustc_borrowck/src/universal_regions.rs:907:36:
Box<dyn Any>
stack backtrace:
   0:     0x798ceeee742a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::he860c317670a8ee8
   1:     0x798cef6033e6 - core::fmt::write::h85942acfab9fbb8e
   2:     0x798cf07c21d1 - std::io::Write::write_fmt::h02454f05ec1899d2
   3:     0x798ceeee7282 - std::sys::backtrace::BacktraceLock::print::h60a3ebc4bc614975
   4:     0x798ceeee97a1 - std::panicking::default_hook::{{closure}}::h14eeb32e0ebecbed
   5:     0x798ceeee95d4 - std::panicking::default_hook::h9fd211a2ee9131e9
   6:     0x798cedfacdaf - std[b68e0f2352f1225a]::panicking::update_hook::<alloc[ef3a1d1ce70fa9de]::boxed::Box<rustc_driver_impl[36095810a3387818]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x798ceeee9eb8 - std::panicking::rust_panic_with_hook::h292eb934d0cf1505
   8:     0x798cedfe6861 - std[b68e0f2352f1225a]::panicking::begin_panic::<rustc_errors[2eed1b0696d6b0ca]::ExplicitBug>::{closure#0}
   9:     0x798cedfd9906 - std[b68e0f2352f1225a]::sys::backtrace::__rust_end_short_backtrace::<std[b68e0f2352f1225a]::panicking::begin_panic<rustc_errors[2eed1b0696d6b0ca]::ExplicitBug>::{closure#0}, !>
  10:     0x798cedfd4de9 - std[b68e0f2352f1225a]::panicking::begin_panic::<rustc_errors[2eed1b0696d6b0ca]::ExplicitBug>
  11:     0x798cedff00f1 - <rustc_errors[2eed1b0696d6b0ca]::diagnostic::BugAbort as rustc_errors[2eed1b0696d6b0ca]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x798cee6164d4 - rustc_middle[7022e7fb49c033e3]::util::bug::opt_span_bug_fmt::<rustc_span[7f4dc1f2f3079c80]::span_encoding::Span>::{closure#0}
  13:     0x798cee5fc24a - rustc_middle[7022e7fb49c033e3]::ty::context::tls::with_opt::<rustc_middle[7022e7fb49c033e3]::util::bug::opt_span_bug_fmt<rustc_span[7f4dc1f2f3079c80]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x798cee5fc0db - rustc_middle[7022e7fb49c033e3]::ty::context::tls::with_context_opt::<rustc_middle[7022e7fb49c033e3]::ty::context::tls::with_opt<rustc_middle[7022e7fb49c033e3]::util::bug::opt_span_bug_fmt<rustc_span[7f4dc1f2f3079c80]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x798cebbd0f70 - rustc_middle[7022e7fb49c033e3]::util::bug::bug_fmt
  16:     0x798cefa18974 - <rustc_borrowck[337d9969af7d283c]::type_check::TypeChecker>::push_region_constraints
  17:     0x798cf0361a09 - <rustc_borrowck[337d9969af7d283c]::type_check::TypeChecker>::fully_perform_op::<(), rustc_borrowck[337d9969af7d283c]::type_check::InstantiateOpaqueType>
  18:     0x798cf0361617 - <rustc_borrowck[337d9969af7d283c]::type_check::relate_tys::NllTypeRelating>::relate_opaques
  19:     0x798cef7efe43 - <rustc_borrowck[337d9969af7d283c]::type_check::relate_tys::NllTypeRelating as rustc_type_ir[79d818fa2341b895]::relate::TypeRelation<rustc_middle[7022e7fb49c033e3]::ty::context::TyCtxt>>::tys
  20:     0x798cef7f76a4 - <rustc_borrowck[337d9969af7d283c]::type_check::TypeChecker>::typeck_mir
  21:     0x798cf06305c0 - rustc_borrowck[337d9969af7d283c]::type_check::type_check
  22:     0x798cef697109 - rustc_borrowck[337d9969af7d283c]::nll::compute_regions
  23:     0x798cf05820fd - rustc_borrowck[337d9969af7d283c]::do_mir_borrowck
  24:     0x798cf0574347 - rustc_query_impl[7d7be967dcb4ccf9]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[7d7be967dcb4ccf9]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7022e7fb49c033e3]::query::erase::Erased<[u8; 8usize]>>
  25:     0x798cef9de0d4 - rustc_query_system[c3f4099526c2cb10]::query::plumbing::try_execute_query::<rustc_query_impl[7d7be967dcb4ccf9]::DynamicConfig<rustc_query_system[c3f4099526c2cb10]::query::caches::VecCache<rustc_span[7f4dc1f2f3079c80]::def_id::LocalDefId, rustc_middle[7022e7fb49c033e3]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[7d7be967dcb4ccf9]::plumbing::QueryCtxt, true>
  26:     0x798cef980374 - rustc_query_impl[7d7be967dcb4ccf9]::query_impl::mir_borrowck::get_query_incr::__rust_end_short_backtrace
  27:     0x798cefe4a8f3 - rustc_middle[7022e7fb49c033e3]::query::plumbing::query_get_at::<rustc_query_system[c3f4099526c2cb10]::query::caches::VecCache<rustc_span[7f4dc1f2f3079c80]::def_id::LocalDefId, rustc_middle[7022e7fb49c033e3]::query::erase::Erased<[u8; 8usize]>>>
  28:     0x798cf0410e0d - rustc_hir_analysis[16c81de99e2bb6e2]::collect::type_of::type_of_opaque
  29:     0x798cf0410c65 - rustc_query_impl[7d7be967dcb4ccf9]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[7d7be967dcb4ccf9]::query_impl::type_of_opaque::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7022e7fb49c033e3]::query::erase::Erased<[u8; 8usize]>>
  30:     0x798cef9841a3 - rustc_query_system[c3f4099526c2cb10]::query::plumbing::try_execute_query::<rustc_query_impl[7d7be967dcb4ccf9]::DynamicConfig<rustc_query_system[c3f4099526c2cb10]::query::caches::DefIdCache<rustc_middle[7022e7fb49c033e3]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[7d7be967dcb4ccf9]::plumbing::QueryCtxt, true>
  31:     0x798cf0743979 - rustc_query_impl[7d7be967dcb4ccf9]::query_impl::type_of_opaque::get_query_incr::__rust_end_short_backtrace
  32:     0x798cefbda880 - rustc_middle[7022e7fb49c033e3]::query::plumbing::query_get_at::<rustc_query_system[c3f4099526c2cb10]::query::caches::DefIdCache<rustc_middle[7022e7fb49c033e3]::query::erase::Erased<[u8; 8usize]>>>
  33:     0x798ced147075 - rustc_hir_analysis[16c81de99e2bb6e2]::collect::type_of::type_of
  34:     0x798cef6308b0 - rustc_query_impl[7d7be967dcb4ccf9]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[7d7be967dcb4ccf9]::query_impl::type_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7022e7fb49c033e3]::query::erase::Erased<[u8; 8usize]>>
  35:     0x798cef9841a3 - rustc_query_system[c3f4099526c2cb10]::query::plumbing::try_execute_query::<rustc_query_impl[7d7be967dcb4ccf9]::DynamicConfig<rustc_query_system[c3f4099526c2cb10]::query::caches::DefIdCache<rustc_middle[7022e7fb49c033e3]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[7d7be967dcb4ccf9]::plumbing::QueryCtxt, true>
  36:     0x798cef981cb6 - rustc_query_impl[7d7be967dcb4ccf9]::query_impl::type_of::get_query_incr::__rust_end_short_backtrace
  37:     0x798cefbda880 - rustc_middle[7022e7fb49c033e3]::query::plumbing::query_get_at::<rustc_query_system[c3f4099526c2cb10]::query::caches::DefIdCache<rustc_middle[7022e7fb49c033e3]::query::erase::Erased<[u8; 8usize]>>>
  38:     0x798ced15a12d - rustc_hir_analysis[16c81de99e2bb6e2]::check::wfcheck::check_well_formed
  39:     0x798cefa0f287 - rustc_query_impl[7d7be967dcb4ccf9]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[7d7be967dcb4ccf9]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7022e7fb49c033e3]::query::erase::Erased<[u8; 1usize]>>
  40:     0x798cefa12a6e - rustc_query_system[c3f4099526c2cb10]::query::plumbing::try_execute_query::<rustc_query_impl[7d7be967dcb4ccf9]::DynamicConfig<rustc_query_system[c3f4099526c2cb10]::query::caches::VecCache<rustc_hir[38d481f48cb6880c]::hir_id::OwnerId, rustc_middle[7022e7fb49c033e3]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[7d7be967dcb4ccf9]::plumbing::QueryCtxt, true>
  41:     0x798cefa12478 - rustc_query_impl[7d7be967dcb4ccf9]::query_impl::check_well_formed::get_query_incr::__rust_end_short_backtrace
  42:     0x798cefa1003f - rustc_hir_analysis[16c81de99e2bb6e2]::check::wfcheck::check_mod_type_wf
  43:     0x798cefa0fe5f - rustc_query_impl[7d7be967dcb4ccf9]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[7d7be967dcb4ccf9]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7022e7fb49c033e3]::query::erase::Erased<[u8; 1usize]>>
  44:     0x798cf034ae94 - rustc_query_system[c3f4099526c2cb10]::query::plumbing::try_execute_query::<rustc_query_impl[7d7be967dcb4ccf9]::DynamicConfig<rustc_query_system[c3f4099526c2cb10]::query::caches::DefaultCache<rustc_span[7f4dc1f2f3079c80]::def_id::LocalModDefId, rustc_middle[7022e7fb49c033e3]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[7d7be967dcb4ccf9]::plumbing::QueryCtxt, true>
  45:     0x798cf034bb5b - rustc_query_impl[7d7be967dcb4ccf9]::query_impl::check_mod_type_wf::get_query_incr::__rust_end_short_backtrace
  46:     0x798cef9d7bd5 - rustc_hir_analysis[16c81de99e2bb6e2]::check_crate
  47:     0x798cef9d4885 - rustc_interface[42f1287f194b8703]::passes::run_required_analyses
  48:     0x798cf012efde - rustc_interface[42f1287f194b8703]::passes::analysis
  49:     0x798cf012efb1 - rustc_query_impl[7d7be967dcb4ccf9]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[7d7be967dcb4ccf9]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7022e7fb49c033e3]::query::erase::Erased<[u8; 1usize]>>
  50:     0x798cf066a80d - rustc_query_system[c3f4099526c2cb10]::query::plumbing::try_execute_query::<rustc_query_impl[7d7be967dcb4ccf9]::DynamicConfig<rustc_query_system[c3f4099526c2cb10]::query::caches::SingleCache<rustc_middle[7022e7fb49c033e3]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[7d7be967dcb4ccf9]::plumbing::QueryCtxt, true>
  51:     0x798cf066a2fa - rustc_query_impl[7d7be967dcb4ccf9]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
  52:     0x798cf032ff9e - rustc_interface[42f1287f194b8703]::interface::run_compiler::<core[c948a8f7e9c28281]::result::Result<(), rustc_span[7f4dc1f2f3079c80]::ErrorGuaranteed>, rustc_driver_impl[36095810a3387818]::run_compiler::{closure#0}>::{closure#1}
  53:     0x798cf03d5dd0 - std[b68e0f2352f1225a]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[42f1287f194b8703]::util::run_in_thread_with_globals<rustc_interface[42f1287f194b8703]::util::run_in_thread_pool_with_globals<rustc_interface[42f1287f194b8703]::interface::run_compiler<core[c948a8f7e9c28281]::result::Result<(), rustc_span[7f4dc1f2f3079c80]::ErrorGuaranteed>, rustc_driver_impl[36095810a3387818]::run_compiler::{closure#0}>::{closure#1}, core[c948a8f7e9c28281]::result::Result<(), rustc_span[7f4dc1f2f3079c80]::ErrorGuaranteed>>::{closure#0}, core[c948a8f7e9c28281]::result::Result<(), rustc_span[7f4dc1f2f3079c80]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[c948a8f7e9c28281]::result::Result<(), rustc_span[7f4dc1f2f3079c80]::ErrorGuaranteed>>
  54:     0x798cf03d643a - <<std[b68e0f2352f1225a]::thread::Builder>::spawn_unchecked_<rustc_interface[42f1287f194b8703]::util::run_in_thread_with_globals<rustc_interface[42f1287f194b8703]::util::run_in_thread_pool_with_globals<rustc_interface[42f1287f194b8703]::interface::run_compiler<core[c948a8f7e9c28281]::result::Result<(), rustc_span[7f4dc1f2f3079c80]::ErrorGuaranteed>, rustc_driver_impl[36095810a3387818]::run_compiler::{closure#0}>::{closure#1}, core[c948a8f7e9c28281]::result::Result<(), rustc_span[7f4dc1f2f3079c80]::ErrorGuaranteed>>::{closure#0}, core[c948a8f7e9c28281]::result::Result<(), rustc_span[7f4dc1f2f3079c80]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[c948a8f7e9c28281]::result::Result<(), rustc_span[7f4dc1f2f3079c80]::ErrorGuaranteed>>::{closure#1} as core[c948a8f7e9c28281]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  55:     0x798cf03d682b - std::sys::pal::unix::thread::Thread::new::thread_start::hf2e33d153b68a619
  56:     0x798cea69ca94 - start_thread
                               at ./nptl/pthread_create.c:447:8
  57:     0x798cea729c3c - clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
  58:                0x0 - <unknown>

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: please make sure that you have updated to the latest nightly

note: please attach the file at `/home/lothrop/src/casinobuddy.app/rustc-ice-2024-10-05T17_47_46-138434.txt` to your bug report

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

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

query stack during panic:
#0 [mir_borrowck] borrow-checking `get_app`
#1 [type_of_opaque] computing type of opaque `get_app::{opaque#0}`
end of query stack
For more information about this error, try `rustc --explain E0308`.
error: could not compile `casino-buddy` (lib) due to 1 previous error

Hey, I just ran into this again, here's the code and the crash at the time it happened.
https://gist.github.com/cycle-five/4c7c2ac988f3f4058a601ab95f02cfaf
https://gist.github.com/cycle-five/d19ea0482c034dec1e52705dd2e19c5e

@cyrgani
Copy link
Contributor

cyrgani commented Oct 5, 2024

Reduced:

struct Exact<P>(P);

impl Filter for Exact<&'static ()> {}

fn path() -> Exact<&'static ()> {
    loop {}
}

fn query_as<D>() {}

async fn create_user() {
    query_as();
}

async fn post_user_filter() -> impl Filter {
    path().and_then(|| async { create_user().await })
}

async fn get_app() -> impl Filter {
    Or(post_user_filter().await)
}

trait Filter {
    fn and_then<F>(self, _fun: F) -> AndThen<Self, F> {
        loop {}
    }
}

struct Or<U>(U);

impl<U> Filter for Or<U> where U: Send {}

struct AndThen<T, F>(T, F);

impl<T, F, R> Filter for AndThen<T, F>
where
    F: Fn() -> R + Send,
    F::Output: Send,
{
}

Has quite a few similarities to #119095.

@rustbot label: -E-needs-mcve +S-has-mcve

@rustbot rustbot added S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example labels Oct 5, 2024
@cyrgani
Copy link
Contributor

cyrgani commented Oct 6, 2024

More reduction:

fn query_as<D>() {}

async fn create_user() {
    query_as();
}

async fn post_user_filter() -> impl Filter {
    AndThen(&(), || async { create_user().await })
}

async fn get_app() -> impl Send {
    post_user_filter().await
}

trait Filter {}

struct AndThen<T, F>(T, F);

impl<T, F, R> Filter for AndThen<T, F>
where
    F: Fn() -> R,
    R: Send,
{
}

@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Oct 12, 2024
@compiler-errors
Copy link
Member

compiler-errors commented Oct 16, 2024

Ideally this issue is minimized further, since this is really impossible to debug given its current tests:

@rustbot label: -S-bug-has-test -S-has-mcve

@rustbot rustbot removed the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Oct 16, 2024
@compiler-errors compiler-errors removed the S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue label Oct 16, 2024
@cyrgani
Copy link
Contributor

cyrgani commented Oct 16, 2024

Here is my next attempt at reducing it further and naming things more usefully:

use std::future::Future;

fn invalid_future() -> impl Future {}

fn create_complex_future() -> impl Future<Output = impl ReturnsSend> {
    async { &|| async { invalid_future().await } }
}

fn coerce_impl_trait() -> impl Future<Output = impl Send> {
    create_complex_future()
}

trait ReturnsSend {}

impl<F, R> ReturnsSend for F
where
    F: Fn() -> R,
    R: Send,
{
}

@cyrgani
Copy link
Contributor

cyrgani commented Oct 18, 2024

@rustbot label: +S-has-mcve

@rustbot rustbot added the S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue label Oct 18, 2024
@Noratrieb Noratrieb changed the title rustc crash ICE: Cannot convert erased region to a region VID Oct 28, 2024
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Nov 3, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 3, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 3, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Nov 3, 2024
Rollup merge of rust-lang#132543 - cyrgani:master, r=compiler-errors

add and update some crashtests

Adds tests for rust-lang#126268 and rust-lang#132126, updates it for rust-lang#131050.
@cyrgani
Copy link
Contributor

cyrgani commented Nov 3, 2024

@rustbot label: +S-bug-has-test

@rustbot rustbot added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Nov 3, 2024
@Noratrieb Noratrieb removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 9, 2024
@bors bors closed this as completed in 26fb78a Dec 27, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Dec 27, 2024
Rollup merge of rust-lang#134798 - compiler-errors:err-auto, r=jackh726

Make `ty::Error` implement all auto traits

I have no idea what's up with the crashes test I fixed--I really don't want to look into it since it has to do something with borrowck and multiple layers of opaques. I think the underlying idea of allowing error types to implement all auto traits is justified though.

Fixes rust-lang#134796
Fixes rust-lang#131050

r? lcnr
@lqd lqd marked this as a duplicate of #131603 Dec 28, 2024
poliorcetics pushed a commit to poliorcetics/rust that referenced this issue Dec 28, 2024
Make `ty::Error` implement all auto traits

I have no idea what's up with the crashes test I fixed--I really don't want to look into it since it has to do something with borrowck and multiple layers of opaques. I think the underlying idea of allowing error types to implement all auto traits is justified though.

Fixes rust-lang#134796
Fixes rust-lang#131050

r? lcnr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue 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.

8 participants