Skip to content

Commit fe5536b

Browse files
committed
Add diagnostic::on_unimplemented attribute on rust >=1.78
* 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 1079ada commit fe5536b

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
@@ -372,6 +372,13 @@ use crate::reader::Reader;
372372
use crate::writer::Writer;
373373

374374
/// "Reader" trait: read bytes and bits from [`no_std_io::Read`]er
375+
#[rustversion::attr(
376+
since(1.78),
377+
diagnostic::on_unimplemented(
378+
note = "implement by adding #[derive(DekuRead)] to `{Self}`",
379+
note = "make sure the `ctx` sent into the function matches `{Self}`'s `ctx`",
380+
)
381+
)]
375382
pub trait DekuReader<'a, Ctx = ()> {
376383
/// Construct type from `reader` implementing [`no_std_io::Read`], with ctx.
377384
///
@@ -403,6 +410,13 @@ pub trait DekuReader<'a, Ctx = ()> {
403410

404411
/// "Reader" trait: implemented on DekuRead struct and enum containers. A `container` is a type which
405412
/// doesn't need any context information.
413+
#[rustversion::attr(
414+
since(1.78),
415+
diagnostic::on_unimplemented(
416+
note = "implement by adding #[derive(DekuRead)] to `{Self}`",
417+
note = "make sure the `ctx` sent into the function matches `{Self}`'s `ctx`",
418+
)
419+
)]
406420
pub trait DekuContainerRead<'a>: DekuReader<'a, ()> {
407421
/// Construct type from Reader implementing [`no_std_io::Read`].
408422
/// * **input** - Input given as "Reader" and bit offset
@@ -444,6 +458,13 @@ pub trait DekuContainerRead<'a>: DekuReader<'a, ()> {
444458
}
445459

446460
/// "Writer" trait: write from type to bytes
461+
#[rustversion::attr(
462+
since(1.78),
463+
diagnostic::on_unimplemented(
464+
note = "implement by adding #[derive(DekuRead)] to `{Self}`",
465+
note = "make sure the `ctx` sent into the function matches `{Self}`'s `ctx`",
466+
)
467+
)]
447468
pub trait DekuWriter<Ctx = ()> {
448469
/// Write type to bytes
449470
fn to_writer<W: no_std_io::Write>(
@@ -455,6 +476,13 @@ pub trait DekuWriter<Ctx = ()> {
455476

456477
/// "Writer" trait: implemented on DekuWrite struct and enum containers. A `container` is a type which
457478
/// doesn't need any context information.
479+
#[rustversion::attr(
480+
since(1.78),
481+
diagnostic::on_unimplemented(
482+
note = "implement by adding #[derive(DekuWrite)] to `{Self}`",
483+
note = "make sure the `ctx` sent into the function matches `{Self}`'s `ctx`",
484+
)
485+
)]
458486
pub trait DekuContainerWrite: DekuWriter<()> {
459487
/// Write struct/enum to Vec<u8>
460488
///

0 commit comments

Comments
 (0)