Skip to content

Commit 75f9ecf

Browse files
Add diagnostic::on_unimplemented attribute on rust >=1.78 (#437)
* Add the following diagnostics to hopefully lead people in the right direction when seeing trait problems related to ctxs and derives error[E0277]: the trait bound `FieldF: deku::DekuReader<'_, _>` is not satisfied --> examples/example.rs:37:14 | 37 | field_f: FieldF, | ^^^^^^ the trait `deku::DekuReader<'_, _>` is not implemented for `FieldF` | = note: implement by adding #[derive(DekuRead)] to `FieldF` = note: make sure the `ctx` sent into the function matches `FieldF`'s `ctx` = help: the following other types implement trait `deku::DekuReader<'a, Ctx>`: <() as deku::DekuReader<'_, Ctx>> <(A, B) as deku::DekuReader<'a, Ctx>> <(A, B, C) as deku::DekuReader<'a, Ctx>> <(A, B, C, D) as deku::DekuReader<'a, Ctx>> <(A, B, C, D, E) as deku::DekuReader<'a, Ctx>> <(A, B, C, D, E, F) as deku::DekuReader<'a, Ctx>> <(A, B, C, D, E, F, G) as deku::DekuReader<'a, Ctx>> <(A, B, C, D, E, F, G, H) as deku::DekuReader<'a, Ctx>> and 152 others * Rust Release: https://blog.rust-lang.org/2024/05/02/Rust-1.78.0.html * Rust MR: rust-lang/rust#119888
1 parent e92700a commit 75f9ecf

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ deku_derive = { version = "^0.16.0", path = "deku-derive", default-features = fa
3131
bitvec = { version = "1.0.1", default-features = false }
3232
log = { version = "0.4.17", optional = true }
3333
no_std_io = { version = "0.5.0", default-features = false, features = ["alloc"] }
34+
rustversion = "1.0.15"
3435

3536
[dev-dependencies]
3637
rstest = "0.18.0"

src/lib.rs

+28
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,13 @@ use crate::reader::Reader;
378378
use crate::writer::Writer;
379379

380380
/// "Reader" trait: read bytes and bits from [`no_std_io::Read`]er
381+
#[rustversion::attr(
382+
since(1.78),
383+
diagnostic::on_unimplemented(
384+
note = "implement by adding #[derive(DekuRead)] to `{Self}`",
385+
note = "make sure the `ctx` sent into the function matches `{Self}`'s `ctx`",
386+
)
387+
)]
381388
pub trait DekuReader<'a, Ctx = ()> {
382389
/// Construct type from `reader` implementing [`no_std_io::Read`], with ctx.
383390
///
@@ -409,6 +416,13 @@ pub trait DekuReader<'a, Ctx = ()> {
409416

410417
/// "Reader" trait: implemented on DekuRead struct and enum containers. A `container` is a type which
411418
/// doesn't need any context information.
419+
#[rustversion::attr(
420+
since(1.78),
421+
diagnostic::on_unimplemented(
422+
note = "implement by adding #[derive(DekuRead)] to `{Self}`",
423+
note = "make sure the `ctx` sent into the function matches `{Self}`'s `ctx`",
424+
)
425+
)]
412426
pub trait DekuContainerRead<'a>: DekuReader<'a, ()> {
413427
/// Construct type from Reader implementing [`no_std_io::Read`].
414428
/// * **input** - Input given as "Reader" and bit offset
@@ -450,6 +464,13 @@ pub trait DekuContainerRead<'a>: DekuReader<'a, ()> {
450464
}
451465

452466
/// "Writer" trait: write from type to bytes
467+
#[rustversion::attr(
468+
since(1.78),
469+
diagnostic::on_unimplemented(
470+
note = "implement by adding #[derive(DekuRead)] to `{Self}`",
471+
note = "make sure the `ctx` sent into the function matches `{Self}`'s `ctx`",
472+
)
473+
)]
453474
pub trait DekuWriter<Ctx = ()> {
454475
/// Write type to bytes
455476
fn to_writer<W: no_std_io::Write>(
@@ -461,6 +482,13 @@ pub trait DekuWriter<Ctx = ()> {
461482

462483
/// "Writer" trait: implemented on DekuWrite struct and enum containers. A `container` is a type which
463484
/// doesn't need any context information.
485+
#[rustversion::attr(
486+
since(1.78),
487+
diagnostic::on_unimplemented(
488+
note = "implement by adding #[derive(DekuWrite)] to `{Self}`",
489+
note = "make sure the `ctx` sent into the function matches `{Self}`'s `ctx`",
490+
)
491+
)]
464492
pub trait DekuContainerWrite: DekuWriter<()> {
465493
/// Write struct/enum to Vec<u8>
466494
///

0 commit comments

Comments
 (0)