Skip to content

Commit

Permalink
Merge #9047
Browse files Browse the repository at this point in the history
9047: fix: proc_macro_srv: temporary abi fix (rust-lang/rust#84717) r=lnicola a=lnicola

bors r+

Co-authored-by: cynecx <[email protected]>
  • Loading branch information
bors[bot] and cynecx authored May 29, 2021
2 parents 3fa3343 + 6fed8cc commit 079fa79
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crates/proc_macro_srv/src/proc_macro/bridge/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>;
Expand Down Expand Up @@ -318,6 +319,19 @@ impl<T: Unmark> Unmark for Option<T> {
}
}

impl<T: Mark, E: Mark> Mark for Result<T, E> {
type Unmarked = Result<T::Unmarked, E::Unmarked>;
fn mark(unmarked: Self::Unmarked) -> Self {
unmarked.map(T::mark).map_err(E::mark)
}
}
impl<T: Unmark, E: Unmark> Unmark for Result<T, E> {
type Unmarked = Result<T::Unmarked, E::Unmarked>;
fn unmark(self) -> Self::Unmarked {
self.map(T::unmark).map_err(E::unmark)
}
}

macro_rules! mark_noop {
($($ty:ty),* $(,)?) => {
$(
Expand Down
17 changes: 17 additions & 0 deletions crates/proc_macro_srv/src/proc_macro/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -925,6 +931,17 @@ impl fmt::Debug for Literal {
}
}

impl FromStr for Literal {
type Err = LexError;

fn from_str(src: &str) -> Result<Self, LexError> {
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;
Expand Down
3 changes: 3 additions & 0 deletions crates/proc_macro_srv/src/rustc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,9 @@ impl server::Ident for Rustc {
}

impl server::Literal for Rustc {
fn from_str(&mut self, _s: &str) -> Result<Self::Literal, ()> {
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.
Expand Down

0 comments on commit 079fa79

Please sign in to comment.