From 09ded918c492821d5b7a69004738c38ff4a0624d Mon Sep 17 00:00:00 2001 From: robojumper Date: Sun, 31 May 2020 21:22:08 +0200 Subject: proc_macro: fix current nightly/future stable ABI incompatibility --- crates/ra_proc_macro_srv/src/proc_macro/bridge/client.rs | 14 ++++++++++---- crates/ra_proc_macro_srv/src/proc_macro/bridge/closure.rs | 3 +++ crates/ra_proc_macro_srv/src/proc_macro/bridge/mod.rs | 8 ++++++-- crates/ra_proc_macro_srv/src/rustc_server.rs | 13 ++++++++++--- 4 files changed, 29 insertions(+), 9 deletions(-) (limited to 'crates/ra_proc_macro_srv/src') diff --git a/crates/ra_proc_macro_srv/src/proc_macro/bridge/client.rs b/crates/ra_proc_macro_srv/src/proc_macro/bridge/client.rs index 4b5dc7fd0..cb4b3bdb0 100644 --- a/crates/ra_proc_macro_srv/src/proc_macro/bridge/client.rs +++ b/crates/ra_proc_macro_srv/src/proc_macro/bridge/client.rs @@ -18,7 +18,7 @@ macro_rules! define_handles { } impl HandleCounters { - // FIXME(eddyb) use a reference to the `static COUNTERS`, intead of + // FIXME(eddyb) use a reference to the `static COUNTERS`, instead of // a wrapper `fn` pointer, once `const fn` can reference `static`s. extern "C" fn get() -> &'static Self { static COUNTERS: HandleCounters = HandleCounters { @@ -205,10 +205,16 @@ impl Clone for Literal { } } -// FIXME(eddyb) `Literal` should not expose internal `Debug` impls. impl fmt::Debug for Literal { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str(&self.debug()) + f.debug_struct("Literal") + // format the kind without quotes, as in `kind: Float` + // .field("kind", &format_args!("{}", &self.debug_kind())) + .field("symbol", &self.symbol()) + // format `Some("...")` on one line even in {:#?} mode + // .field("suffix", &format_args!("{:?}", &self.suffix())) + .field("span", &self.span()) + .finish() } } @@ -339,7 +345,7 @@ impl Bridge<'_> { #[repr(C)] #[derive(Copy, Clone)] pub struct Client { - // FIXME(eddyb) use a reference to the `static COUNTERS`, intead of + // FIXME(eddyb) use a reference to the `static COUNTERS`, instead of // a wrapper `fn` pointer, once `const fn` can reference `static`s. pub(super) get_handle_counters: extern "C" fn() -> &'static HandleCounters, pub(super) run: extern "C" fn(Bridge<'_>, F) -> Buffer, diff --git a/crates/ra_proc_macro_srv/src/proc_macro/bridge/closure.rs b/crates/ra_proc_macro_srv/src/proc_macro/bridge/closure.rs index b8addff4a..273a97715 100644 --- a/crates/ra_proc_macro_srv/src/proc_macro/bridge/closure.rs +++ b/crates/ra_proc_macro_srv/src/proc_macro/bridge/closure.rs @@ -11,6 +11,9 @@ pub struct Closure<'a, A, R> { struct Env; +// impl<'a, A, R> !Sync for Closure<'a, A, R> {} +// impl<'a, A, R> !Send for Closure<'a, A, R> {} + impl<'a, A, R, F: FnMut(A) -> R> From<&'a mut F> for Closure<'a, A, R> { fn from(f: &'a mut F) -> Self { unsafe extern "C" fn call R>(env: &mut Env, arg: A) -> R { diff --git a/crates/ra_proc_macro_srv/src/proc_macro/bridge/mod.rs b/crates/ra_proc_macro_srv/src/proc_macro/bridge/mod.rs index 6ae3926b2..aeb05aad4 100644 --- a/crates/ra_proc_macro_srv/src/proc_macro/bridge/mod.rs +++ b/crates/ra_proc_macro_srv/src/proc_macro/bridge/mod.rs @@ -108,8 +108,9 @@ macro_rules! with_api { Literal { fn drop($self: $S::Literal); fn clone($self: &$S::Literal) -> $S::Literal; - // FIXME(eddyb) `Literal` should not expose internal `Debug` impls. - fn debug($self: &$S::Literal) -> String; + fn debug_kind($self: &$S::Literal) -> String; + fn symbol($self: &$S::Literal) -> String; + fn suffix($self: &$S::Literal) -> Option; fn integer(n: &str) -> $S::Literal; fn typed_integer(n: &str, kind: &str) -> $S::Literal; fn float(n: &str) -> $S::Literal; @@ -222,6 +223,9 @@ pub struct Bridge<'a> { dispatch: closure::Closure<'a, Buffer, Buffer>, } +// impl<'a> !Sync for Bridge<'a> {} +// impl<'a> !Send for Bridge<'a> {} + #[forbid(unsafe_code)] #[allow(non_camel_case_types)] mod api_tags { diff --git a/crates/ra_proc_macro_srv/src/rustc_server.rs b/crates/ra_proc_macro_srv/src/rustc_server.rs index f481d70b2..cc32d5a6d 100644 --- a/crates/ra_proc_macro_srv/src/rustc_server.rs +++ b/crates/ra_proc_macro_srv/src/rustc_server.rs @@ -463,9 +463,16 @@ impl server::Ident for Rustc { } impl server::Literal for Rustc { - // FIXME(eddyb) `Literal` should not expose internal `Debug` impls. - fn debug(&mut self, literal: &Self::Literal) -> String { - format!("{:?}", literal) + fn debug_kind(&mut self, _literal: &Self::Literal) -> String { + // r-a: debug_kind and suffix are unsupported; corresponding client code has been changed to not call these. + // They must still be present to be ABI-compatible and work with upstream proc_macro. + "".to_owned() + } + fn symbol(&mut self, literal: &Self::Literal) -> String { + literal.text.to_string() + } + fn suffix(&mut self, _literal: &Self::Literal) -> Option { + None } fn integer(&mut self, n: &str) -> Self::Literal { -- cgit v1.2.3 From dbb940fa7d040c7b46a8fba8d222fc9fac812bea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Wed, 1 Jul 2020 18:08:45 +0300 Subject: Colorize more test fixtures --- crates/ra_proc_macro_srv/src/tests/mod.rs | 6 ++---- crates/ra_proc_macro_srv/src/tests/utils.rs | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'crates/ra_proc_macro_srv/src') diff --git a/crates/ra_proc_macro_srv/src/tests/mod.rs b/crates/ra_proc_macro_srv/src/tests/mod.rs index 82cefbb29..8e6f28abd 100644 --- a/crates/ra_proc_macro_srv/src/tests/mod.rs +++ b/crates/ra_proc_macro_srv/src/tests/mod.rs @@ -11,7 +11,7 @@ fn test_derive_serialize_proc_macro() { "serde_derive", "Serialize", "1.0", - r##"struct Foo {}"##, + r"struct Foo {}", include_str!("fixtures/test_serialize_proc_macro.txt"), ); } @@ -22,9 +22,7 @@ fn test_derive_serialize_proc_macro_failed() { "serde_derive", "Serialize", "1.0", - r##" - struct {} -"##, + r"struct {}", r##" SUBTREE $ IDENT compile_error 4294967295 diff --git a/crates/ra_proc_macro_srv/src/tests/utils.rs b/crates/ra_proc_macro_srv/src/tests/utils.rs index 8d85f2d8a..dcb00671f 100644 --- a/crates/ra_proc_macro_srv/src/tests/utils.rs +++ b/crates/ra_proc_macro_srv/src/tests/utils.rs @@ -44,12 +44,12 @@ pub fn assert_expand( crate_name: &str, macro_name: &str, version: &str, - fixture: &str, + ra_fixture: &str, expect: &str, ) { let path = fixtures::dylib_path(crate_name, version); let expander = dylib::Expander::new(&path).unwrap(); - let fixture = parse_string(fixture).unwrap(); + let fixture = parse_string(ra_fixture).unwrap(); let res = expander.expand(macro_name, &fixture.subtree, None).unwrap(); assert_eq_text!(&format!("{:?}", res), &expect.trim()); -- cgit v1.2.3 From 4b7f473223a939b702b89b6ef4db59bdbfff32d4 Mon Sep 17 00:00:00 2001 From: kjeremy Date: Wed, 8 Jul 2020 09:45:29 -0400 Subject: Clippy perf warnings --- crates/ra_proc_macro_srv/src/dylib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_proc_macro_srv/src') diff --git a/crates/ra_proc_macro_srv/src/dylib.rs b/crates/ra_proc_macro_srv/src/dylib.rs index aa84e951c..1addbbd54 100644 --- a/crates/ra_proc_macro_srv/src/dylib.rs +++ b/crates/ra_proc_macro_srv/src/dylib.rs @@ -45,7 +45,7 @@ fn find_registrar_symbol(file: &Path) -> io::Result> { // https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/dlsym.3.html // Unlike other dyld API's, the symbol name passed to dlsym() must NOT be // prepended with an underscore. - if s.name.starts_with("_") { + if s.name.starts_with('_') { &s.name[1..] } else { &s.name -- cgit v1.2.3