proc_macro: remove Context trait, and put span methods directly on Server

This commit is contained in:
Nika Layzell 2022-06-25 12:11:44 -04:00
parent 55f052d9c9
commit 2456ff8928
2 changed files with 13 additions and 17 deletions

View File

@ -372,7 +372,7 @@ impl<'a, 'b> Rustc<'a, 'b> {
fn lit(&mut self, kind: token::LitKind, symbol: Symbol, suffix: Option<Symbol>) -> Literal {
Literal {
lit: token::Lit::new(kind, symbol, suffix),
span: server::Context::call_site(self),
span: server::Server::call_site(self),
}
}
}
@ -550,7 +550,7 @@ impl server::Group for Rustc<'_, '_> {
Group {
delimiter,
stream: stream.unwrap_or_default(),
span: DelimSpan::from_single(server::Context::call_site(self)),
span: DelimSpan::from_single(server::Server::call_site(self)),
flatten: false,
}
}
@ -582,7 +582,7 @@ impl server::Group for Rustc<'_, '_> {
impl server::Punct for Rustc<'_, '_> {
fn new(&mut self, ch: char, spacing: Spacing) -> Self::Punct {
Punct::new(ch, spacing == Spacing::Joint, server::Context::call_site(self))
Punct::new(ch, spacing == Spacing::Joint, server::Server::call_site(self))
}
fn as_char(&mut self, punct: Self::Punct) -> char {
@ -918,7 +918,7 @@ impl server::Span for Rustc<'_, '_> {
}
}
impl server::Context for Rustc<'_, '_> {
impl server::Server for Rustc<'_, '_> {
fn def_site(&mut self) -> Self::Span {
self.def_site
}

View File

@ -30,13 +30,6 @@ macro_rules! associated_fn {
($($item:tt)*) => ($($item)*;)
}
/// Helper methods defined by `Server` types not invoked over RPC.
pub trait Context: Types {
fn def_site(&mut self) -> Self::Span;
fn call_site(&mut self) -> Self::Span;
fn mixed_site(&mut self) -> Self::Span;
}
macro_rules! declare_server_traits {
($($name:ident {
$(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)?;)*
@ -45,23 +38,26 @@ macro_rules! declare_server_traits {
$(associated_fn!(fn $method(&mut self, $($arg: $arg_ty),*) $(-> $ret_ty)?);)*
})*
pub trait Server: Types + Context $(+ $name)* {}
impl<S: Types + Context $(+ $name)*> Server for S {}
pub trait Server: Types $(+ $name)* {
fn def_site(&mut self) -> Self::Span;
fn call_site(&mut self) -> Self::Span;
fn mixed_site(&mut self) -> Self::Span;
}
}
}
with_api!(Self, self_, declare_server_traits);
pub(super) struct MarkedTypes<S: Types>(S);
impl<S: Context> Context for MarkedTypes<S> {
impl<S: Server> Server for MarkedTypes<S> {
fn def_site(&mut self) -> Self::Span {
<_>::mark(Context::def_site(&mut self.0))
<_>::mark(Server::def_site(&mut self.0))
}
fn call_site(&mut self) -> Self::Span {
<_>::mark(Context::call_site(&mut self.0))
<_>::mark(Server::call_site(&mut self.0))
}
fn mixed_site(&mut self) -> Self::Span {
<_>::mark(Context::mixed_site(&mut self.0))
<_>::mark(Server::mixed_site(&mut self.0))
}
}