Skip to content

regression: error[E0277]: the trait bound Entity: AdapterExt is not satisfied #142424

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

Closed
BoxyUwU opened this issue Jun 12, 2025 · 4 comments
Closed
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-proc-macros Area: Procedural macros C-bug Category: This is a bug. regression-from-stable-to-beta Performance or correctness regression from stable to beta.
Milestone

Comments

@BoxyUwU
Copy link
Member

BoxyUwU commented Jun 12, 2025

[INFO] [stdout] error[E0277]: the trait bound `Entity: AdapterExt` is not satisfied
[INFO] [stdout]   --> src/lib.rs:42:22
[INFO] [stdout]    |
[INFO] [stdout] 42 |         let entity = t.clone() as Rc<dyn AdapterExt>;
[INFO] [stdout]    |                      ^^^^^^^^^ the trait `AdapterExt` is not implemented for `Entity`
[INFO] [stdout]    |
[INFO] [stdout]    = note: required for the cast from `Rc<Entity>` to `Rc<dyn AdapterExt>`
@BoxyUwU BoxyUwU added regression-from-stable-to-beta Performance or correctness regression from stable to beta. C-bug Category: This is a bug. labels Jun 12, 2025
@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jun 12, 2025
@cuviper cuviper added this to the 1.88.0 milestone Jun 12, 2025
@theemathas
Copy link
Contributor

I am unable to reproduce this error on my computer.

The code in this crate is doing something extremely weird with macros, and I suspect that the error is nondeterministic.

The relevant code is:

#[derive(LeanBufferWrite)]
pub struct Entity {
    x: String,
    y: i64,
}

include!(concat!(env!("OUT_DIR"), "/Entity_lb_gen.rs"));

The LeanBufferWrite derive macro outputs an empty TokenStream. However, as part of its execution, the code writes to the Entity_lb_gen.rs file in OUT_DIR.

My guess for the cause of the error is: for some reason, the include!() in the above code executes concurrently with the LeanBufferWrite macro. And include!() happened to read the Entity_lb_gen.rs file after it's created, but before it's populated, so the include!() reads an empty file. As a result, the Entity type does not have code that implements the traits that it is supposed to implement.

I am unfortunately unable to verify if this guess is correct.

@rustbot labels +A-macros +A-proc-macros

@rustbot rustbot added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-proc-macros Area: Procedural macros labels Jun 13, 2025
@theemathas
Copy link
Contributor

theemathas commented Jun 13, 2025

I think I have verified the above guess.

I created a workspace containing the following:

build.rs

// Do nothing. This exists so OUT_DIR is set.
fn main() {}

src/lib.rs:

#![allow(dead_code)]

#[derive(bar::MyDerive)]
struct Thing;

include!(concat!(env!("OUT_DIR"), "/data"));

#[test]
fn wut() {
    println!("{}", X);
}

bar/src/lib.rs

use std::{env, fs, path::PathBuf};

use proc_macro::TokenStream;

#[proc_macro_derive(MyDerive)]
pub fn my_derive(_: TokenStream) -> TokenStream {
    let out_dir = env::var_os("OUT_DIR").unwrap();
    let out_file = PathBuf::from(out_dir).join("data");
    let contents = "\n".repeat(1000000) + "const X: i32 = 1;";
    fs::write(out_file, contents).unwrap();
    TokenStream::new()
}

Zipped code of all the files for your convenience: repro.zip

I then repeatedly compiled the code with the following command:

while true; do cargo clean && cargo +beta test --no-run || break; done

If you leave that running for a while, it will eventually produce an error with "cannot find value X in this scope".

The same behavior also occurs when compiling with stable rust instead of beta.

I conclude that the error found by crater isn't a regression. It is actually a nondeterministic error that rarely occurs.

@BoxyUwU
Copy link
Member Author

BoxyUwU commented Jun 13, 2025

incredible

@BoxyUwU BoxyUwU closed this as not planned Won't fix, can't repro, duplicate, stale Jun 13, 2025
@theemathas
Copy link
Contributor

It still kinda bugs me that I can't reliably reproduce this with a sleep() call. And also, the proc macro appears to be called twice with the same OUT_DIR. I'm not going to investigate further though.

@apiraino apiraino removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jun 13, 2025
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, ..) A-proc-macros Area: Procedural macros C-bug Category: This is a bug. regression-from-stable-to-beta Performance or correctness regression from stable to beta.
Projects
None yet
Development

No branches or pull requests

5 participants