Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Debug derive macro error #94758

Open
carloabelli opened this issue Mar 9, 2022 · 2 comments
Open

Incorrect Debug derive macro error #94758

carloabelli opened this issue Mar 9, 2022 · 2 comments
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example

Comments

@carloabelli
Copy link

Code

[package]
name = "minimal"
version = "0.1.0"
edition = "2021"

[dependencies]
rkyv = "0.7"
use rkyv::{
    with::{AsOwned, With},
    Archive, Serialize,
};
use std::{any::type_name, borrow::Cow};

#[derive(Archive, Serialize)]
#[archive_attr(derive(Debug))]
struct Wrapper1(String);

#[derive(Archive, Serialize)]
//#[archive_attr(derive(Debug))] // <== error
struct Wrapper2<'a>(#[with(AsOwned)] Cow<'a, str>);

fn main() {
    println!("{}", type_name::<<String as Archive>::Archived>());
    println!(
        "{}",
        type_name::<<With<Cow<'_, str>, AsOwned> as Archive>::Archived>()
    );
}

Meta

rustc --version --verbose:

rustc 1.59.0 (9d1b2106e 2022-02-23)
binary: rustc
commit-hash: 9d1b2106e23b1abd32fce1f17267604a5102f57a
commit-date: 2022-02-23
host: x86_64-unknown-linux-gnu
release: 1.59.0
LLVM version: 13.0.0

Output

rkyv::string::ArchivedString
rkyv::string::ArchivedString

Error when the commented line is un-commented

error[E0277]: `<With<Cow<'_, str>, AsOwned> as Archive>::Archived` doesn't implement `Debug`
  --> src/main.rs:11:10
   |
11 | #[derive(Archive, Serialize)]
   |          ^^^^^^^ `<With<Cow<'_, str>, AsOwned> as Archive>::Archived` cannot be formatted using `{:?}` because it doesn't implement `Debug`
12 | #[archive_attr(derive(Debug))]
   |                       ----- in this derive macro expansion
   |
   = help: the trait `Debug` is not implemented for `<With<Cow<'_, str>, AsOwned> as Archive>::Archived`
   = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)

Despite the fact that <With<Cow<'_, str>, AsOwned> as Archive>::Archived is rkyv::string::ArchivedString which implements Debug.

@carloabelli
Copy link
Author

Maybe related to #94651?

@djkoloski
Copy link
Contributor

One workaround for this for the time being is to add:

#[archive(bound(archive = "<With<Cow<'a, str>, AsOwned> as Archive>::Archived: ::core::fmt::Debug"))]

Which explicitly tells the compiler that the archived version of Cow<'a, str> implements Debug. It isn't great but it keeps things moving.

@jyn514 jyn514 added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example labels Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
Projects
None yet
Development

No branches or pull requests

3 participants