Closed AtomicGamer9523 closed 1 year ago
@AtomicGamer9523 can you verify that this continues to fail on the latest nightly? I can't seem to reproduce your error!
@compiler-errors Was just able to replicate!
Cargo.toml:
[package]
name = "rustprojects"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tokio = { version = "1.20.1", features = ["full"] }
async-minecraft-ping = "0.8.0"
async-trait = "0.1"
futures = "0.3.21"
log = "0.4.17"
You're still using nightly from 2022-06-25 -- can you update with rustup update nightly
?
sure
@AtomicGamer9523 did you check if this fails on the latest nightly version of Rust?
You are right, this is no longer an issue
Code
main.rs: ```rust #![feature(type_alias_impl_trait)] #![feature(trait_alias)] mod executor; use executor::*; mod worker; use worker::*; // Amount of threads to use const POOL_SIZE: u32 = 12; #[tokio::main] async fn main() -> std::io::Result<()> { let mut pool = Executor::new(POOL_SIZE); let mut server_pinger = ServerPinger::new(); pool.setJob(|id,state|{ server_pinger.run(id,state); }); pool.run(); Ok(()) } async fn exec(id: u8, state: u8) { } ``` executor.rs: ```rust pub trait Service: Clone + core::fmt::Debug { fn run(&self, _: u8, _: u8); } type SyncJob = impl Fn(u8,u8) + Clone; pub trait SyncService: Clone {
fn setJob(&mut self, f: T);
}
#[derive(Clone)]
struct Worker {
pub id: u8,
pub state: u8,
jobs: u32,
finished: u32,
job: SyncJob
}
impl Worker {
fn new(id: u8, state: u8, jobs: u32, finished: u32, job: SyncJob) -> Self {
Self { id, state, jobs, finished, job }
}
fn dfault(id: u8, jobs: u32) -> Self {
Self::new(id, 0, jobs, 0, Box::new(|_,_|{}))
}
fn run(&mut self) {
for _ in 0..self.jobs {
(self.job)(self.id, self.state);
self.finished += 1;
}
}
}
#[derive(Clone)]
pub struct Executor {
workers: Vec
}
impl Executor {
pub fn new>(size: T) -> Self {
let size: u32 = size.into();
let equal_share: u32 = ( ( 256 / size ) as f64 ).floor() as u32;
let mut last_thread_jobs: u32 = equal_share;
if equal_share * size != 256 {
last_thread_jobs += 256 - size * equal_share;
}
let mut workers: Vec = Vec::new();
for i in 0..size {
if i == (size - 1) {
workers.push(Worker::dfault(i as u8,last_thread_jobs));
} else {
workers.push(Worker::dfault(i as u8,equal_share));
}
}
Self { workers }
}
pub fn run(&mut self) {
for worker in &mut self.workers {
worker.run();
}
}
}
#[allow(invalid_type_param_default)]
impl SyncService for Executor where T: Fn(u8,u8) + Clone {
fn setJob(&mut self, job: SyncJob) -> () {
for worker in &mut self.workers {
worker.job = job.clone();
}
}
}
```
worker.rs:
```rust
use crate::executor::{Service};
#[derive(Debug, Clone)]
pub struct ServerPinger {}
impl ServerPinger {
pub fn new() -> Self { Self {} }
}
impl Service for ServerPinger {
fn run(&self, id: u8, state: u8) {
println!("ServerPinger: {} {}", id, state);
}
}
```
Cargo.toml:
```toml
[package]
name = "rustprojects"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tokio = { version = "1.20.1", features = ["full"] }
async-minecraft-ping = "0.8.0"
async-trait = "0.1"
futures = "0.3.21"
log = "0.4.17"
```
Expected: Successful compilation
Instead, this happened:
Meta
rustc --version --verbose
:Backtrace
ENV: `RUST_BACKTRACE=full` ``` Compiling rpinger v0.1.0 (C:\Code\Hypernite\rpinger) warning: unused variable: `id` --> src\main.rs:26:15 | 26 | async fn exec(id: u8, state: u8) { | ^^ help: if this is intentional, prefix it with an underscore: `_id` | = note: `#[warn(unused_variables)]` on by default warning: unused variable: `state` --> src\main.rs:26:23 | 26 | async fn exec(id: u8, state: u8) { | ^^^^^ help: if this is intentional, prefix it with an underscore: `_state` warning: variable does not need to be mutable --> src\main.rs:15:9 | 15 | let mut server_pinger = ServerPinger::new(); | ----^^^^^^^^^^^^^ | | | help: remove this `mut` | = note: `#[warn(unused_mut)]` on by default warning: function `exec` is never used --> src\main.rs:26:10 | 26 | async fn exec(id: u8, state: u8) { | ^^^^ | = note: `#[warn(dead_code)]` on by default warning: trait method `setJob` should have a snake case name --> src\executor.rs:8:8 | 8 | fn setJob(&mut self, f: T); | ^^^^^^ help: convert the identifier to snake case: `set_job` | = note: `#[warn(non_snake_case)]` on by default warning: Error finalizing incremental compilation session directory `\\?\C:\Code\Hypernite\rpinger\target\debug\incremental\rpinger-xpvfty13xgi5\s-gf0o4padvr-gz8647-working`: The system cannot find the file specified. (os error 2) error: internal compiler error: no errors encountered even though `delay_span_bug` issued error: internal compiler error: VecMap([(OpaqueTypeKey { def_id: DefId(0:7 ~ rpinger[3d97]::executor::SyncJob::{opaque#0}), substs: [] }, OpaqueTypeDecl { hidden_type: OpaqueHiddenType { span: src\executor.rs:69:5: 69:45 (#0), ty: _ }, origin: TyAlias })]) | = note: delayed at compiler\rustc_infer\src\infer\opaque_types\table.rs:50:26 thread 'rustc' panicked at 'Box', compiler\rustc_errors\src\lib.rs:1425:13
stack backtrace:
0: 0x7ffb6c249f4f - ::fmt::h314f152bcc928f1c
1: 0x7ffb6c2844ea - core::fmt::write::hd8a9744d710fe910
2: 0x7ffb6c23c439 - ::fmt::h3de1d81d7076fcf3
3: 0x7ffb6c24d83b - std::panicking::default_hook::h4aa587652243f7e7
4: 0x7ffb6c24d4bb - std::panicking::default_hook::h4aa587652243f7e7
5: 0x7ffb190f7926 - rustc_driver[99189a5311142797]::pretty::print_after_hir_lowering
6: 0x7ffb6c24dfe2 - std::panicking::rust_panic_with_hook::ha35ad9f58eb637a9
7: 0x7ffb1d8f6f05 - ::fmt
8: 0x7ffb1d8f2829 - ::fmt
9: 0x7ffb1dc3d929 - rustc_query_system[78d2146506c7f639]::query::plumbing::incremental_verify_ich_cold
10: 0x7ffb1d8a3119 - ::fmt
11: 0x7ffb1d8a6d1c - ::drop
12: 0x7ffb190745f4 - ::visit_ident
13: 0x7ffb1907e79a - ::visit_ident
14: 0x7ffb191083fd - ::fmt
15: 0x7ffb191062d9 - ::fmt
16: 0x7ffb1908632d - ::visit_ident
17: 0x7ffb190ee056 - ::emit_raw_bytes
18: 0x7ffb190b0138 - ::fmt
19: 0x7ffb6c25e6bc - std::sys::windows::thread::Thread::new::h7abefeefa20aa848
20: 0x7ffbd7bc7034 - BaseThreadInitThunk
21: 0x7ffbd7d826a1 - RtlUserThreadStart
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md
note: rustc 1.64.0-nightly (20a6f3a8a 2022-06-25) running on x86_64-pc-windows-msvc
note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental
note: some of the compiler flags provided by cargo are hidden
query stack during panic:
end of query stack
warning: `rpinger` (bin "rpinger") generated 6 warnings
error: could not compile `rpinger`; 6 warnings emitted
```