[Beginner] Trait Dependency Cycle Error E0391
⚓ Rust 📅 2026-06-11 👤 surdeus 👁️ 1THIS IS A GENERAL ERRORS QUESTION, WHICH SHOULDN'T BE AFFECTED BY THE FACT THAT ITS AN EMBEDDED RUST PROJECT.
Hi im a beginner rustacean, I just finished THE BOOK, and am doing some embedded rust on the pico2. I was modifying the tmc2209-uart crate on crates.io to use the rp235x-hal uart functions/methods, when bam out of nowhere I get hit with this trait cyclical dependency error, that doesn't even make sense. I can't understand what the compiler is trying to tell me, and I don't find these links:- "note: see Overview of the compiler - Rust Compiler Development Guide and Queries: demand-driven compilation - Rust Compiler Development Guide for more information" very helpful.
the traits bit that is causing the error is this bit:
pub struct Tmc2209<D, P>
where
D: uart::UartDevice,
P: uart::ValidUartPinout<D>,
{
/// UART peripheral.
uart: uart::UartPeripheral<uart::Enabled, D, P>,
}
I'll post the full code in a separate post below ![]()
I am downright confused I would be grateful if the community could enlighten me.
the output of cargo check has been given below ![]()
Thank You
error[E0391]: cycle detected when computing the variances for items in this crate
|
note: ...which requires computing function signature of `driver::<impl at src/driver.rs:125:1: 128:33>::read_register`...
--> src/driver.rs:141:5
|
141 | pub fn read_register<R: ReadableRegister>(&mut self) -> Result<R, Error<_>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires type-checking `driver::<impl at src/driver.rs:125:1: 128:33>::read_register`...
--> src/driver.rs:141:5
|
141 | pub fn read_register<R: ReadableRegister>(&mut self) -> Result<R, Error<_>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires computing function signature of `driver::<impl at src/driver.rs:125:1: 128:33>::read_echo`...
--> src/driver.rs:222:5
|
222 | fn read_echo(&mut self, buf: &mut [u8]) -> Result<(), Error<_>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires type-checking `driver::<impl at src/driver.rs:125:1: 128:33>::read_echo`...
--> src/driver.rs:222:5
|
222 | fn read_echo(&mut self, buf: &mut [u8]) -> Result<(), Error<_>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires computing the variances of `error::Error::Echo`...
--> src/error.rs:33:5
|
33 | Echo(E),
| ^^^^
= note: ...which again requires computing the variances for items in this crate, completing the cycle
note: cycle used when computing the variances of `driver::Tmc2209`
--> src/driver.rs:42:1
|
42 | pub struct Tmc2209<D, P>
| ^^^^^^^^^^^^^^^^^^^^^^^^
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
For more information about this error, try `rustc --explain E0391`.
error: could not compile `tmc2209-pi` (lib) due to 1 previous error
4 posts - 2 participants
🏷️ Rust_feed