From 1bf57ed78be76a75d926e01f1838c0e602af01a7 Mon Sep 17 00:00:00 2001 From: cynecx Date: Tue, 25 May 2021 18:32:45 +0200 Subject: [PATCH] proc_macro_srv: temporary abi fix (rust-lang/rust#84717) --- .../proc_macro_srv/src/proc_macro/bridge/mod.rs | 14 ++++++++++++++ crates/proc_macro_srv/src/proc_macro/mod.rs | 17 +++++++++++++++++ crates/proc_macro_srv/src/rustc_server.rs | 3 +++ 3 files changed, 34 insertions(+) diff --git a/crates/proc_macro_srv/src/proc_macro/bridge/mod.rs b/crates/proc_macro_srv/src/proc_macro/bridge/mod.rs index e679026823aa..1797117c03f3 100644 --- a/crates/proc_macro_srv/src/proc_macro/bridge/mod.rs +++ b/crates/proc_macro_srv/src/proc_macro/bridge/mod.rs @@ -112,6 +112,7 @@ macro_rules! with_api { Literal { fn drop($self: $S::Literal); fn clone($self: &$S::Literal) -> $S::Literal; + fn from_str(s: &str) -> Result<$S::Literal, ()>; fn debug_kind($self: &$S::Literal) -> String; fn symbol($self: &$S::Literal) -> String; fn suffix($self: &$S::Literal) -> Option; @@ -318,6 +319,19 @@ impl Unmark for Option { } } +impl Mark for Result { + type Unmarked = Result; + fn mark(unmarked: Self::Unmarked) -> Self { + unmarked.map(T::mark).map_err(E::mark) + } +} +impl Unmark for Result { + type Unmarked = Result; + fn unmark(self) -> Self::Unmarked { + self.map(T::unmark).map_err(E::unmark) + } +} + macro_rules! mark_noop { ($($ty:ty),* $(,)?) => { $( diff --git a/crates/proc_macro_srv/src/proc_macro/mod.rs b/crates/proc_macro_srv/src/proc_macro/mod.rs index fc6e7344f74a..9a9732e3e143 100644 --- a/crates/proc_macro_srv/src/proc_macro/mod.rs +++ b/crates/proc_macro_srv/src/proc_macro/mod.rs @@ -37,6 +37,12 @@ pub struct LexError { _inner: (), } +impl LexError { + fn new() -> Self { + LexError { _inner: () } + } +} + impl TokenStream { /// Returns an empty `TokenStream` containing no token trees. pub fn new() -> TokenStream { @@ -925,6 +931,17 @@ impl fmt::Debug for Literal { } } +impl FromStr for Literal { + type Err = LexError; + + fn from_str(src: &str) -> Result { + match bridge::client::Literal::from_str(src) { + Ok(literal) => Ok(Literal(literal)), + Err(()) => Err(LexError::new()), + } + } +} + pub mod tracked_env { use std::env::{self, VarError}; use std::ffi::OsStr; diff --git a/crates/proc_macro_srv/src/rustc_server.rs b/crates/proc_macro_srv/src/rustc_server.rs index 5d765f6e2728..c85bb300d9d1 100644 --- a/crates/proc_macro_srv/src/rustc_server.rs +++ b/crates/proc_macro_srv/src/rustc_server.rs @@ -521,6 +521,9 @@ impl server::Ident for Rustc { } impl server::Literal for Rustc { + fn from_str(&mut self, s: &str) -> Result { + unimplemented!() + } 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.