-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Invalid code suggested when encountering unsatisfied trait bounds in derive macro code #104884
Comments
@rustbot claim |
@jonasbb do you know how to create a minimal case without I give a fix and verified it's OK with my local testing, but I'm struggle to construct a minimal case without |
@chenyukang I assume this reproduces when using the same setup of derive macro implementing a trait while the implementation is missing bounds. I don't know if it is relevant that the derive macro produces a trait. Something along these lines, with the proc macro crate omitted. // main crate
trait FooBar {
fn dostuff(self);
}
#[derive(...)]
struct Struct<T>(T);
// derive macro expanded code
impl<T> FooBar for Struct<T> {
fn dostuff(self) {
use std::collections::BinaryHeap;
let mut bh = BinaryHeap::new();
bh.push(self.0);
}
} |
yes, it's caused by derive macro. |
emm,met this error 😒 error: can't use a procedural macro from the same crate that defines it |
…, r=TaKO8Ki Avoid Invalid code suggested when encountering unsatisfied trait bounds in derive macro code Fixes rust-lang#104884
…, r=TaKO8Ki Avoid Invalid code suggested when encountering unsatisfied trait bounds in derive macro code Fixes rust-lang#104884
Given the following code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=0345475f1b234a0cf26f97bfb712cceb
The current output is:
The last part of the suggestion
#[derive(serde::Serialize, T: std::cmp::Ord)]
is not valid Rust code and therefore should not be suggested like this.This problem occurs on the Playground on both stable and nightly with basically identical error messages. serde v1.0.147 requires
T: Ord
such thatBinaryHeap
will beSerialize
. Otherwise the problem does not seem serde specific.The text was updated successfully, but these errors were encountered: