Skip to content

Commit 1bf57ed

Browse files
committed
proc_macro_srv: temporary abi fix (rust-lang/rust#84717)
1 parent 3a13699 commit 1bf57ed

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

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

+14
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ macro_rules! with_api {
112112
Literal {
113113
fn drop($self: $S::Literal);
114114
fn clone($self: &$S::Literal) -> $S::Literal;
115+
fn from_str(s: &str) -> Result<$S::Literal, ()>;
115116
fn debug_kind($self: &$S::Literal) -> String;
116117
fn symbol($self: &$S::Literal) -> String;
117118
fn suffix($self: &$S::Literal) -> Option<String>;
@@ -318,6 +319,19 @@ impl<T: Unmark> Unmark for Option<T> {
318319
}
319320
}
320321

322+
impl<T: Mark, E: Mark> Mark for Result<T, E> {
323+
type Unmarked = Result<T::Unmarked, E::Unmarked>;
324+
fn mark(unmarked: Self::Unmarked) -> Self {
325+
unmarked.map(T::mark).map_err(E::mark)
326+
}
327+
}
328+
impl<T: Unmark, E: Unmark> Unmark for Result<T, E> {
329+
type Unmarked = Result<T::Unmarked, E::Unmarked>;
330+
fn unmark(self) -> Self::Unmarked {
331+
self.map(T::unmark).map_err(E::unmark)
332+
}
333+
}
334+
321335
macro_rules! mark_noop {
322336
($($ty:ty),* $(,)?) => {
323337
$(

crates/proc_macro_srv/src/proc_macro/mod.rs

+17
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ pub struct LexError {
3737
_inner: (),
3838
}
3939

40+
impl LexError {
41+
fn new() -> Self {
42+
LexError { _inner: () }
43+
}
44+
}
45+
4046
impl TokenStream {
4147
/// Returns an empty `TokenStream` containing no token trees.
4248
pub fn new() -> TokenStream {
@@ -925,6 +931,17 @@ impl fmt::Debug for Literal {
925931
}
926932
}
927933

934+
impl FromStr for Literal {
935+
type Err = LexError;
936+
937+
fn from_str(src: &str) -> Result<Self, LexError> {
938+
match bridge::client::Literal::from_str(src) {
939+
Ok(literal) => Ok(Literal(literal)),
940+
Err(()) => Err(LexError::new()),
941+
}
942+
}
943+
}
944+
928945
pub mod tracked_env {
929946
use std::env::{self, VarError};
930947
use std::ffi::OsStr;

crates/proc_macro_srv/src/rustc_server.rs

+3
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,9 @@ impl server::Ident for Rustc {
521521
}
522522

523523
impl server::Literal for Rustc {
524+
fn from_str(&mut self, s: &str) -> Result<Self::Literal, ()> {
525+
unimplemented!()
526+
}
524527
fn debug_kind(&mut self, _literal: &Self::Literal) -> String {
525528
// r-a: debug_kind and suffix are unsupported; corresponding client code has been changed to not call these.
526529
// They must still be present to be ABI-compatible and work with upstream proc_macro.

0 commit comments

Comments
 (0)