Unresolved trait import...?

Hello !

I have written two rust libraries, namely polyx and fractios. polyx tests and runs perfectly fine. Then, fractios depends on polyx and imports some of its structs, functions and traits. fractios has access to polyx thanks to a github link set in the Cargo.toml file.

In polyx is defined a public module traits which contains a public trait PolyxNum. Problem: I cannot import this trait in fractios. Functions and structs imports work fine, but not traits. Weirdly enough, VSCode's rust-analyzer tells me the import is unresolved (like the compiler does) but still indicates the definition of the public trait PolyxNum when I hover the error (see picture below).

To be honest, I do not really know what keywords to use in a research bar to hope to find a topic about this issue. I tried things like "unresolved trait import (from local crate)" but got nothing that helped me. Thank you for taking your time to help me !

For context: What is the compilation error? E.g. with cargo check in the terminal (for the fractios crate). (Or maybe just click that “Click for full compiler diagnostics” button ^^) If the trait really cannot be imported, then you’d see it in the compiler error, along with probably some suggested fixes, if it exists in another path or so.

I can’t reproduce the issue.

If I do

git clone https://github.com/Silzinc/fractios.git
cd fractios
echo 'use polyx::traits::PolyxNum;' >> src/lib.rs
cargo check

I get no error message

warning: unused import: `polyx::traits::PolyxNum`
  --> src/lib.rs:15:5
15 | use polyx::traits::PolyxNum;
   |     ^^^^^^^^^^^^^^^^^^^^^^^
   = note: `#[warn(unused_imports)]` on by default

Edit: On second read, I’m noticing the thing I cloned even already contained the use line in question in the ops.rs, so the echo … >> … step is unnecessary.

The error comes from the compiler and effectively appears when cargo check runs. Also, There are some other traits like HasNorm that have no problem being imported.

Sorry for being unclear. I was asking for the full compiler error, which might contain more information than the snippet the IDE presents.

Also, with what I wrote above regarding the inability to reproduce the issue, I’d appreciate any hint as to what you’re doing differently – e.g. your polyx repo may or may not be a different one? What does the Cargo.toml look like, in case there is a difference? Is the issue persisting over cargo clean? What is the last thing you changed?

Also, you indicate both using a github link in Cargo.toml, but also say you’ve considered “unresolved trait import (from local crate)” as a search term – I wouldn’t call a dependency on GitHub to be “local”, per say, no?

1 Like

First thing first, here comes the compiler message embedded in VSCode:
Capture d’écran du 2023-10-05 23-15-33
The Cargo.toml file looks like this:
Capture d’écran du 2023-10-05 23-18-05
I also tried replacing the git link by a local path to the crate, that did not work either. That's why I mentionned local crate somehow.

This Cargo.toml used to work fine until I reworked the trait system of polyx. It seems fractios can only import the traits it already could import before, such as HasNorm, but not the new ones (PolyxNum and Primitive in this case).

Uh, now it suddenly works. I will definitely look like a liar that solved a stupid mistake he does not want to tell but that's what happened. I have no clue at all...

git dependencies are versioned by git commit IDs (the version is ignored unless you cargo publish). Try running cargo update, to have Cargo start using the latest revision in that repository. This will modify the Cargo.lock file which is where exact versions used in the build are recorded.

To request a more specific version via Cargo.toml, you can specify rev = "commit id here" or branch = "branch name here".

1 Like

Ah, I will have to remember asking for Cargo.lock to debug other people’s problems reproducibly!! :innocent:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.