Open
Description
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Metadata
Assignees
Labels
Category: This is a bug.Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Status: This bug is tracked inside the repo by a `known-bug` test.Status: A Minimal Complete and Verifiable Example has been found for this issueRelevant to the compiler team, which will review and decide on the PR/issue.This issue may need triage. Remove it if it has been sufficiently triaged.