Why this fires¶
A qualified trait path doesn't resolve to a real exported trait. The module
may come from the project, an installed package, core, or std; its last
segment must name a pub trait actually declared there. This applies in a
generic bound, an impl header, and let value: impl module::Trait.
fn f<T: core::cmp::Bogus>(a: T) -> T { a }
// ^^^^^^^^^^^^^^^^^ error[TE824]: invalid qualified trait path `core::cmp::Bogus`The same check covers the trait position of an impl:
impl core::cmp::Bogus for Money { }
// ^^^^^^^^^^^^^^^^^ error[TE824]: invalid qualified trait path `core::cmp::Bogus`
impl contracts::PrivateCleanup for Money { }
// ^^^^^^^^^^^^^^^^^^^^^^^^^ error[TE824]: the trait is not publicFix it¶
Use the correct module and trait name and export a user trait when it crosses a module boundary:
fn f<T: core::cmp::Ord>(a: T) -> T { a } // or simply <T: Ord>
// contracts.zolo
pub trait Cleanup {
fn close(self)
}
// main.zolo — no `use contracts::Cleanup` is needed for a qualified path
let file: impl contracts::Cleanup = File.new("report.txt")Notes¶
- A bare unknown trait name (
<T: Foo>) isTE822, not TE824. - Private traits cannot be named across a module boundary; add
pubor keep the reference inside the declaring module. - Resolution uses the same sibling/project/package lookup rules as
use, so a path is not accepted merely because its final name matches a known trait.