Pular para o conteúdo
TE824 · Tipos · error

Caminho qualificado de trait inválido

Caminhos qualificados de trait precisam ser `core::<módulo>::<Trait>` ou `std::<módulo>::<Trait>`, nomeando um `pub trait` realmente declarado ali — tanto em bound genérico quanto em cabeçalho de `impl`.

Why this fires

A qualified trait path doesn't resolve to a real trait. Qualified trait paths must be core::<module>::<Trait> or std::<module>::<Trait>, naming a pub trait actually declared in that module. This applies both in a generic bound and in an impl header.

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 mymod::Foo for Money { }
//   ^^^^^^^^^^ error[TE824]: invalid qualified trait path `mymod::Foo`

Fix it

Use the correct module and trait name (e.g. core::cmp::Ord, core::ops::Add, core::fmt::Display, core::hash::Hash), or just the bare name since the std traits are in scope via the prelude:

fn f<T: core::cmp::Ord>(a: T) -> T { a }   // or simply  <T: Ord>

Notes

  • A bare unknown trait name (<T: Foo>) is TE822, not TE824.
  • Qualified paths to user-module traits are not supported yet — use the bare name (in scope via use) for those.

See also

Veja também

Buscar no Zolo

9 resultados

en