Skip to content

Commit 9210fcc

Browse files
Merge #4676
4676: proc_macro: fix current nightly/future stable ABI incompatibility r=matklad a=robojumper With rust-lang/rust#72233, the proc_macro ABI has changed, leading to the `test_derive_serialize_proc_macro` test believing that `serde` wants to pass the struct name as a byte string literal instead of a string literal. Fixes #4866. Co-authored-by: robojumper <[email protected]>
2 parents 30245ea + 09ded91 commit 9210fcc

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

crates/ra_proc_macro_srv/src/proc_macro/bridge/client.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ macro_rules! define_handles {
1818
}
1919

2020
impl HandleCounters {
21-
// FIXME(eddyb) use a reference to the `static COUNTERS`, intead of
21+
// FIXME(eddyb) use a reference to the `static COUNTERS`, instead of
2222
// a wrapper `fn` pointer, once `const fn` can reference `static`s.
2323
extern "C" fn get() -> &'static Self {
2424
static COUNTERS: HandleCounters = HandleCounters {
@@ -205,10 +205,16 @@ impl Clone for Literal {
205205
}
206206
}
207207

208-
// FIXME(eddyb) `Literal` should not expose internal `Debug` impls.
209208
impl fmt::Debug for Literal {
210209
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
211-
f.write_str(&self.debug())
210+
f.debug_struct("Literal")
211+
// format the kind without quotes, as in `kind: Float`
212+
// .field("kind", &format_args!("{}", &self.debug_kind()))
213+
.field("symbol", &self.symbol())
214+
// format `Some("...")` on one line even in {:#?} mode
215+
// .field("suffix", &format_args!("{:?}", &self.suffix()))
216+
.field("span", &self.span())
217+
.finish()
212218
}
213219
}
214220

@@ -339,7 +345,7 @@ impl Bridge<'_> {
339345
#[repr(C)]
340346
#[derive(Copy, Clone)]
341347
pub struct Client<F> {
342-
// FIXME(eddyb) use a reference to the `static COUNTERS`, intead of
348+
// FIXME(eddyb) use a reference to the `static COUNTERS`, instead of
343349
// a wrapper `fn` pointer, once `const fn` can reference `static`s.
344350
pub(super) get_handle_counters: extern "C" fn() -> &'static HandleCounters,
345351
pub(super) run: extern "C" fn(Bridge<'_>, F) -> Buffer<u8>,

crates/ra_proc_macro_srv/src/proc_macro/bridge/closure.rs

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ pub struct Closure<'a, A, R> {
1111

1212
struct Env;
1313

14+
// impl<'a, A, R> !Sync for Closure<'a, A, R> {}
15+
// impl<'a, A, R> !Send for Closure<'a, A, R> {}
16+
1417
impl<'a, A, R, F: FnMut(A) -> R> From<&'a mut F> for Closure<'a, A, R> {
1518
fn from(f: &'a mut F) -> Self {
1619
unsafe extern "C" fn call<A, R, F: FnMut(A) -> R>(env: &mut Env, arg: A) -> R {

crates/ra_proc_macro_srv/src/proc_macro/bridge/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ macro_rules! with_api {
108108
Literal {
109109
fn drop($self: $S::Literal);
110110
fn clone($self: &$S::Literal) -> $S::Literal;
111-
// FIXME(eddyb) `Literal` should not expose internal `Debug` impls.
112-
fn debug($self: &$S::Literal) -> String;
111+
fn debug_kind($self: &$S::Literal) -> String;
112+
fn symbol($self: &$S::Literal) -> String;
113+
fn suffix($self: &$S::Literal) -> Option<String>;
113114
fn integer(n: &str) -> $S::Literal;
114115
fn typed_integer(n: &str, kind: &str) -> $S::Literal;
115116
fn float(n: &str) -> $S::Literal;
@@ -222,6 +223,9 @@ pub struct Bridge<'a> {
222223
dispatch: closure::Closure<'a, Buffer<u8>, Buffer<u8>>,
223224
}
224225

226+
// impl<'a> !Sync for Bridge<'a> {}
227+
// impl<'a> !Send for Bridge<'a> {}
228+
225229
#[forbid(unsafe_code)]
226230
#[allow(non_camel_case_types)]
227231
mod api_tags {

crates/ra_proc_macro_srv/src/rustc_server.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,16 @@ impl server::Ident for Rustc {
463463
}
464464

465465
impl server::Literal for Rustc {
466-
// FIXME(eddyb) `Literal` should not expose internal `Debug` impls.
467-
fn debug(&mut self, literal: &Self::Literal) -> String {
468-
format!("{:?}", literal)
466+
fn debug_kind(&mut self, _literal: &Self::Literal) -> String {
467+
// r-a: debug_kind and suffix are unsupported; corresponding client code has been changed to not call these.
468+
// They must still be present to be ABI-compatible and work with upstream proc_macro.
469+
"".to_owned()
470+
}
471+
fn symbol(&mut self, literal: &Self::Literal) -> String {
472+
literal.text.to_string()
473+
}
474+
fn suffix(&mut self, _literal: &Self::Literal) -> Option<String> {
475+
None
469476
}
470477

471478
fn integer(&mut self, n: &str) -> Self::Literal {

0 commit comments

Comments
 (0)