libproc_macro => 2018

This commit is contained in:
Taiki Endo 2019-02-04 03:55:40 +09:00
parent fc6e9a2845
commit 18da195bab
9 changed files with 100 additions and 90 deletions

View File

@ -2,6 +2,7 @@
authors = ["The Rust Project Developers"]
name = "proc_macro"
version = "0.0.0"
edition = "2018"
[lib]
path = "lib.rs"

View File

@ -6,7 +6,7 @@ use std::ops::{Deref, DerefMut};
use std::slice;
#[repr(C)]
struct Slice<'a, T: 'a> {
struct Slice<'a, T> {
data: &'a [T; 0],
len: usize,
}
@ -42,7 +42,7 @@ pub struct Buffer<T: Copy> {
data: *mut T,
len: usize,
capacity: usize,
extend_from_slice: extern "C" fn(Buffer<T>, Slice<T>) -> Buffer<T>,
extend_from_slice: extern "C" fn(Buffer<T>, Slice<'_, T>) -> Buffer<T>,
drop: extern "C" fn(Buffer<T>),
}
@ -139,7 +139,7 @@ impl<T: Copy> From<Vec<T>> for Buffer<T> {
}
}
extern "C" fn extend_from_slice<T: Copy>(b: Buffer<T>, xs: Slice<T>) -> Buffer<T> {
extern "C" fn extend_from_slice<T: Copy>(b: Buffer<T>, xs: Slice<'_, T>) -> Buffer<T> {
let mut v = to_vec(b);
v.extend_from_slice(&xs);
Buffer::from(v)

View File

@ -66,7 +66,7 @@ macro_rules! define_handles {
impl<S: server::Types> DecodeMut<'_, '_, HandleStore<server::MarkedTypes<S>>>
for Marked<S::$oty, $oty>
{
fn decode(r: &mut Reader, s: &mut HandleStore<server::MarkedTypes<S>>) -> Self {
fn decode(r: &mut Reader<'_>, s: &mut HandleStore<server::MarkedTypes<S>>) -> Self {
s.$oty.take(handle::Handle::decode(r, &mut ()))
}
}
@ -80,7 +80,7 @@ macro_rules! define_handles {
impl<S: server::Types> Decode<'_, 's, HandleStore<server::MarkedTypes<S>>>
for &'s Marked<S::$oty, $oty>
{
fn decode(r: &mut Reader, s: &'s HandleStore<server::MarkedTypes<S>>) -> Self {
fn decode(r: &mut Reader<'_>, s: &'s HandleStore<server::MarkedTypes<S>>) -> Self {
&s.$oty[handle::Handle::decode(r, &mut ())]
}
}
@ -94,7 +94,10 @@ macro_rules! define_handles {
impl<S: server::Types> DecodeMut<'_, 's, HandleStore<server::MarkedTypes<S>>>
for &'s mut Marked<S::$oty, $oty>
{
fn decode(r: &mut Reader, s: &'s mut HandleStore<server::MarkedTypes<S>>) -> Self {
fn decode(
r: &mut Reader<'_>,
s: &'s mut HandleStore<server::MarkedTypes<S>>
) -> Self {
&mut s.$oty[handle::Handle::decode(r, &mut ())]
}
}
@ -108,7 +111,7 @@ macro_rules! define_handles {
}
impl<S> DecodeMut<'_, '_, S> for $oty {
fn decode(r: &mut Reader, s: &mut S) -> Self {
fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
$oty(handle::Handle::decode(r, s))
}
}
@ -130,7 +133,7 @@ macro_rules! define_handles {
impl<S: server::Types> DecodeMut<'_, '_, HandleStore<server::MarkedTypes<S>>>
for Marked<S::$ity, $ity>
{
fn decode(r: &mut Reader, s: &mut HandleStore<server::MarkedTypes<S>>) -> Self {
fn decode(r: &mut Reader<'_>, s: &mut HandleStore<server::MarkedTypes<S>>) -> Self {
s.$ity.copy(handle::Handle::decode(r, &mut ()))
}
}
@ -144,7 +147,7 @@ macro_rules! define_handles {
}
impl<S> DecodeMut<'_, '_, S> for $ity {
fn decode(r: &mut Reader, s: &mut S) -> Self {
fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
$ity(handle::Handle::decode(r, s))
}
}
@ -200,7 +203,7 @@ 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 {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.debug())
}
}
@ -212,7 +215,7 @@ impl Clone for SourceFile {
}
impl fmt::Debug for Span {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.debug())
}
}
@ -275,7 +278,7 @@ impl BridgeState<'_> {
///
/// N.B., while `f` is running, the thread-local state
/// is `BridgeState::InUse`.
fn with<R>(f: impl FnOnce(&mut BridgeState) -> R) -> R {
fn with<R>(f: impl FnOnce(&mut BridgeState<'_>) -> R) -> R {
BRIDGE_STATE.with(|state| {
state.replace(BridgeState::InUse, |mut state| {
// FIXME(#52812) pass `f` directly to `replace` when `RefMutL` is gone
@ -306,7 +309,7 @@ impl Bridge<'_> {
BRIDGE_STATE.with(|state| state.set(BridgeState::Connected(self), f))
}
fn with<R>(f: impl FnOnce(&mut Bridge) -> R) -> R {
fn with<R>(f: impl FnOnce(&mut Bridge<'_>) -> R) -> R {
BridgeState::with(|state| match state {
BridgeState::NotConnected => {
panic!("procedural macro API is used outside of a procedural macro");
@ -331,15 +334,15 @@ impl Bridge<'_> {
#[derive(Copy, Clone)]
pub struct Client<F> {
pub(super) get_handle_counters: extern "C" fn() -> &'static HandleCounters,
pub(super) run: extern "C" fn(Bridge, F) -> Buffer<u8>,
pub(super) run: extern "C" fn(Bridge<'_>, F) -> Buffer<u8>,
pub(super) f: F,
}
// FIXME(#53451) public to work around `Cannot create local mono-item` ICE,
// affecting not only the function itself, but also the `BridgeState` `thread_local!`.
pub extern "C" fn __run_expand1(
mut bridge: Bridge,
f: fn(::TokenStream) -> ::TokenStream,
mut bridge: Bridge<'_>,
f: fn(crate::TokenStream) -> crate::TokenStream,
) -> Buffer<u8> {
// The initial `cached_buffer` contains the input.
let mut b = bridge.cached_buffer.take();
@ -352,7 +355,7 @@ pub extern "C" fn __run_expand1(
// Put the `cached_buffer` back in the `Bridge`, for requests.
Bridge::with(|bridge| bridge.cached_buffer = b.take());
let output = f(::TokenStream(input)).0;
let output = f(crate::TokenStream(input)).0;
// Take the `cached_buffer` back out, for the output value.
b = Bridge::with(|bridge| bridge.cached_buffer.take());
@ -378,8 +381,8 @@ pub extern "C" fn __run_expand1(
b
}
impl Client<fn(::TokenStream) -> ::TokenStream> {
pub const fn expand1(f: fn(::TokenStream) -> ::TokenStream) -> Self {
impl Client<fn(crate::TokenStream) -> crate::TokenStream> {
pub const fn expand1(f: fn(crate::TokenStream) -> crate::TokenStream) -> Self {
Client {
get_handle_counters: HandleCounters::get,
run: __run_expand1,
@ -391,8 +394,8 @@ impl Client<fn(::TokenStream) -> ::TokenStream> {
// FIXME(#53451) public to work around `Cannot create local mono-item` ICE,
// affecting not only the function itself, but also the `BridgeState` `thread_local!`.
pub extern "C" fn __run_expand2(
mut bridge: Bridge,
f: fn(::TokenStream, ::TokenStream) -> ::TokenStream,
mut bridge: Bridge<'_>,
f: fn(crate::TokenStream, crate::TokenStream) -> crate::TokenStream,
) -> Buffer<u8> {
// The initial `cached_buffer` contains the input.
let mut b = bridge.cached_buffer.take();
@ -406,7 +409,7 @@ pub extern "C" fn __run_expand2(
// Put the `cached_buffer` back in the `Bridge`, for requests.
Bridge::with(|bridge| bridge.cached_buffer = b.take());
let output = f(::TokenStream(input), ::TokenStream(input2)).0;
let output = f(crate::TokenStream(input), crate::TokenStream(input2)).0;
// Take the `cached_buffer` back out, for the output value.
b = Bridge::with(|bridge| bridge.cached_buffer.take());
@ -432,8 +435,10 @@ pub extern "C" fn __run_expand2(
b
}
impl Client<fn(::TokenStream, ::TokenStream) -> ::TokenStream> {
pub const fn expand2(f: fn(::TokenStream, ::TokenStream) -> ::TokenStream) -> Self {
impl Client<fn(crate::TokenStream, crate::TokenStream) -> crate::TokenStream> {
pub const fn expand2(
f: fn(crate::TokenStream, crate::TokenStream) -> crate::TokenStream
) -> Self {
Client {
get_handle_counters: HandleCounters::get,
run: __run_expand2,
@ -448,17 +453,17 @@ pub enum ProcMacro {
CustomDerive {
trait_name: &'static str,
attributes: &'static [&'static str],
client: Client<fn(::TokenStream) -> ::TokenStream>,
client: Client<fn(crate::TokenStream) -> crate::TokenStream>,
},
Attr {
name: &'static str,
client: Client<fn(::TokenStream, ::TokenStream) -> ::TokenStream>,
client: Client<fn(crate::TokenStream, crate::TokenStream) -> crate::TokenStream>,
},
Bang {
name: &'static str,
client: Client<fn(::TokenStream) -> ::TokenStream>,
client: Client<fn(crate::TokenStream) -> crate::TokenStream>,
},
}
@ -466,7 +471,7 @@ impl ProcMacro {
pub const fn custom_derive(
trait_name: &'static str,
attributes: &'static [&'static str],
expand: fn(::TokenStream) -> ::TokenStream,
expand: fn(crate::TokenStream) -> crate::TokenStream,
) -> Self {
ProcMacro::CustomDerive {
trait_name,
@ -477,7 +482,7 @@ impl ProcMacro {
pub const fn attr(
name: &'static str,
expand: fn(::TokenStream, ::TokenStream) -> ::TokenStream,
expand: fn(crate::TokenStream, crate::TokenStream) -> crate::TokenStream,
) -> Self {
ProcMacro::Attr {
name,
@ -485,7 +490,10 @@ impl ProcMacro {
}
}
pub const fn bang(name: &'static str, expand: fn(::TokenStream) -> ::TokenStream) -> Self {
pub const fn bang(
name: &'static str,
expand: fn(crate::TokenStream) -> crate::TokenStream
) -> Self {
ProcMacro::Bang {
name,
client: Client::expand1(expand),

View File

@ -17,7 +17,7 @@ use std::panic;
use std::sync::atomic::AtomicUsize;
use std::sync::Once;
use std::thread;
use {Delimiter, Level, LineColumn, Spacing};
use crate::{Delimiter, Level, LineColumn, Spacing};
/// Higher-order macro describing the server RPC API, allowing automatic
/// generation of type-safe Rust APIs, both client-side and server-side.
@ -196,9 +196,9 @@ mod scoped_cell;
#[forbid(unsafe_code)]
pub mod server;
use self::buffer::Buffer;
pub use self::rpc::PanicMessage;
use self::rpc::{Decode, DecodeMut, Encode, Reader, Writer};
use buffer::Buffer;
pub use rpc::PanicMessage;
use rpc::{Decode, DecodeMut, Encode, Reader, Writer};
/// An active connection between a server and a client.
/// The server creates the bridge (`Bridge::run_server` in `server.rs`),

View File

@ -40,7 +40,7 @@ macro_rules! rpc_encode_decode {
}
impl<S> DecodeMut<'_, '_, S> for $ty {
fn decode(r: &mut Reader, s: &mut S) -> Self {
fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
let mut byte = 0x80;
let mut v = 0;
let mut shift = 0;
@ -61,7 +61,7 @@ macro_rules! rpc_encode_decode {
}
impl<S> DecodeMut<'_, '_, S> for $name {
fn decode(r: &mut Reader, s: &mut S) -> Self {
fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
$name {
$($field: DecodeMut::decode(r, s)),*
}
@ -119,7 +119,7 @@ impl<S> Encode<S> for () {
}
impl<S> DecodeMut<'_, '_, S> for () {
fn decode(_: &mut Reader, _: &mut S) -> Self {}
fn decode(_: &mut Reader<'_>, _: &mut S) -> Self {}
}
impl<S> Encode<S> for u8 {
@ -129,7 +129,7 @@ impl<S> Encode<S> for u8 {
}
impl<S> DecodeMut<'_, '_, S> for u8 {
fn decode(r: &mut Reader, _: &mut S) -> Self {
fn decode(r: &mut Reader<'_>, _: &mut S) -> Self {
let x = r[0];
*r = &r[1..];
x
@ -146,7 +146,7 @@ impl<S> Encode<S> for bool {
}
impl<S> DecodeMut<'_, '_, S> for bool {
fn decode(r: &mut Reader, s: &mut S) -> Self {
fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
match u8::decode(r, s) {
0 => false,
1 => true,
@ -162,7 +162,7 @@ impl<S> Encode<S> for char {
}
impl<S> DecodeMut<'_, '_, S> for char {
fn decode(r: &mut Reader, s: &mut S) -> Self {
fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
char::from_u32(u32::decode(r, s)).unwrap()
}
}
@ -174,7 +174,7 @@ impl<S> Encode<S> for NonZeroU32 {
}
impl<S> DecodeMut<'_, '_, S> for NonZeroU32 {
fn decode(r: &mut Reader, s: &mut S) -> Self {
fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
Self::new(u32::decode(r, s)).unwrap()
}
}
@ -251,7 +251,7 @@ impl<S> Encode<S> for String {
}
impl<S> DecodeMut<'_, '_, S> for String {
fn decode(r: &mut Reader, s: &mut S) -> Self {
fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
<&str>::decode(r, s).to_string()
}
}
@ -306,7 +306,7 @@ impl<S> Encode<S> for PanicMessage {
}
impl<S> DecodeMut<'_, '_, S> for PanicMessage {
fn decode(r: &mut Reader, s: &mut S) -> Self {
fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
match Option::<String>::decode(r, s) {
Some(s) => PanicMessage::String(s),
None => PanicMessage::Unknown,

View File

@ -131,7 +131,7 @@ pub trait ExecutionStrategy {
&self,
dispatcher: &mut impl DispatcherTrait,
input: Buffer<u8>,
run_client: extern "C" fn(Bridge, D) -> Buffer<u8>,
run_client: extern "C" fn(Bridge<'_>, D) -> Buffer<u8>,
client_data: D,
) -> Buffer<u8>;
}
@ -143,7 +143,7 @@ impl ExecutionStrategy for SameThread {
&self,
dispatcher: &mut impl DispatcherTrait,
input: Buffer<u8>,
run_client: extern "C" fn(Bridge, D) -> Buffer<u8>,
run_client: extern "C" fn(Bridge<'_>, D) -> Buffer<u8>,
client_data: D,
) -> Buffer<u8> {
let mut dispatch = |b| dispatcher.dispatch(b);
@ -168,7 +168,7 @@ impl ExecutionStrategy for CrossThread1 {
&self,
dispatcher: &mut impl DispatcherTrait,
input: Buffer<u8>,
run_client: extern "C" fn(Bridge, D) -> Buffer<u8>,
run_client: extern "C" fn(Bridge<'_>, D) -> Buffer<u8>,
client_data: D,
) -> Buffer<u8> {
use std::sync::mpsc::channel;
@ -206,7 +206,7 @@ impl ExecutionStrategy for CrossThread2 {
&self,
dispatcher: &mut impl DispatcherTrait,
input: Buffer<u8>,
run_client: extern "C" fn(Bridge, D) -> Buffer<u8>,
run_client: extern "C" fn(Bridge<'_>, D) -> Buffer<u8>,
client_data: D,
) -> Buffer<u8> {
use std::sync::{Arc, Mutex};
@ -273,7 +273,7 @@ fn run_server<
handle_counters: &'static client::HandleCounters,
server: S,
input: I,
run_client: extern "C" fn(Bridge, D) -> Buffer<u8>,
run_client: extern "C" fn(Bridge<'_>, D) -> Buffer<u8>,
client_data: D,
) -> Result<O, PanicMessage> {
let mut dispatcher = Dispatcher {
@ -289,7 +289,7 @@ fn run_server<
Result::decode(&mut &b[..], &mut dispatcher.handle_store)
}
impl client::Client<fn(::TokenStream) -> ::TokenStream> {
impl client::Client<fn(crate::TokenStream) -> crate::TokenStream> {
pub fn run<S: Server>(
&self,
strategy: &impl ExecutionStrategy,
@ -313,7 +313,7 @@ impl client::Client<fn(::TokenStream) -> ::TokenStream> {
}
}
impl client::Client<fn(::TokenStream, ::TokenStream) -> ::TokenStream> {
impl client::Client<fn(crate::TokenStream, crate::TokenStream) -> crate::TokenStream> {
pub fn run<S: Server>(
&self,
strategy: &impl ExecutionStrategy,

View File

@ -1,4 +1,4 @@
use Span;
use crate::Span;
/// An enum representing a diagnostic level.
#[unstable(feature = "proc_macro_diagnostic", issue = "54140")]
@ -80,7 +80,7 @@ macro_rules! diagnostic_child_methods {
/// Iterator over the children diagnostics of a `Diagnostic`.
#[derive(Debug, Clone)]
#[unstable(feature = "proc_macro_diagnostic", issue = "54140")]
pub struct Children<'a>(::std::slice::Iter<'a, Diagnostic>);
pub struct Children<'a>(std::slice::Iter<'a, Diagnostic>);
#[unstable(feature = "proc_macro_diagnostic", issue = "54140")]
impl<'a> Iterator for Children<'a> {
@ -161,22 +161,22 @@ impl Diagnostic {
/// Returns an iterator over the children diagnostics of `self`.
#[unstable(feature = "proc_macro_diagnostic", issue = "54140")]
pub fn children(&self) -> Children {
pub fn children(&self) -> Children<'_> {
Children(self.children.iter())
}
/// Emit the diagnostic.
#[unstable(feature = "proc_macro_diagnostic", issue = "54140")]
pub fn emit(self) {
fn to_internal(spans: Vec<Span>) -> ::bridge::client::MultiSpan {
let mut multi_span = ::bridge::client::MultiSpan::new();
fn to_internal(spans: Vec<Span>) -> crate::bridge::client::MultiSpan {
let mut multi_span = crate::bridge::client::MultiSpan::new();
for span in spans {
multi_span.push(span.0);
}
multi_span
}
let mut diag = ::bridge::client::Diagnostic::new(
let mut diag = crate::bridge::client::Diagnostic::new(
self.level,
&self.message[..],
to_internal(self.spans),

View File

@ -17,7 +17,8 @@
test(no_crate_inject, attr(deny(warnings))),
test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))))]
#![feature(nll)]
#![deny(rust_2018_idioms)]
#![feature(staged_api)]
#![feature(const_fn)]
#![feature(extern_types)]
@ -114,7 +115,7 @@ impl ToString for TokenStream {
/// with `Delimiter::None` delimiters and negative numeric literals.
#[stable(feature = "proc_macro_lib", since = "1.15.0")]
impl fmt::Display for TokenStream {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.to_string())
}
}
@ -122,7 +123,7 @@ impl fmt::Display for TokenStream {
/// Prints token in a form convenient for debugging.
#[stable(feature = "proc_macro_lib", since = "1.15.0")]
impl fmt::Debug for TokenStream {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("TokenStream ")?;
f.debug_list().entries(self.clone()).finish()
}
@ -183,7 +184,7 @@ impl Extend<TokenStream> for TokenStream {
/// Public implementation details for the `TokenStream` type, such as iterators.
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
pub mod token_stream {
use {bridge, Group, Ident, Literal, Punct, TokenTree, TokenStream};
use crate::{bridge, Group, Ident, Literal, Punct, TokenTree, TokenStream};
/// An iterator over `TokenStream`'s `TokenTree`s.
/// The iteration is "shallow", e.g., the iterator doesn't recurse into delimited groups,
@ -340,7 +341,7 @@ impl Span {
/// Prints a span in a form convenient for debugging.
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
impl fmt::Debug for Span {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
@ -398,7 +399,7 @@ impl SourceFile {
#[unstable(feature = "proc_macro_span", issue = "54725")]
impl fmt::Debug for SourceFile {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("SourceFile")
.field("path", &self.path())
.field("is_real", &self.is_real())
@ -483,7 +484,7 @@ impl TokenTree {
/// Prints token tree in a form convenient for debugging.
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
impl fmt::Debug for TokenTree {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// Each of these has the name in the struct type in the derived debug,
// so don't bother with an extra layer of indirection
match *self {
@ -542,7 +543,7 @@ impl ToString for TokenTree {
/// with `Delimiter::None` delimiters and negative numeric literals.
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
impl fmt::Display for TokenTree {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.to_string())
}
}
@ -667,14 +668,14 @@ impl ToString for Group {
/// with `Delimiter::None` delimiters.
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
impl fmt::Display for Group {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.to_string())
}
}
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
impl fmt::Debug for Group {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Group")
.field("delimiter", &self.delimiter())
.field("stream", &self.stream())
@ -763,14 +764,14 @@ impl ToString for Punct {
/// back into the same character.
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
impl fmt::Display for Punct {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.to_string())
}
}
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
impl fmt::Debug for Punct {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Punct")
.field("ch", &self.as_char())
.field("spacing", &self.spacing())
@ -842,14 +843,14 @@ impl ToString for Ident {
/// back into the same identifier.
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
impl fmt::Display for Ident {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.to_string())
}
}
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
impl fmt::Debug for Ident {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Ident")
.field("ident", &self.to_string())
.field("span", &self.span())
@ -1092,14 +1093,14 @@ impl ToString for Literal {
/// back into the same literal (except for possible rounding for floating point literals).
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
impl fmt::Display for Literal {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.to_string())
}
}
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
impl fmt::Debug for Literal {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// FIXME(eddyb) `Literal` should not expose internal `Debug` impls.
self.0.fmt(f)
}

View File

@ -4,7 +4,7 @@
//! This quasiquoter uses macros 2.0 hygiene to reliably access
//! items from `proc_macro`, to build a `proc_macro::TokenStream`.
use {Delimiter, Group, Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree};
use crate::{Delimiter, Group, Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree};
macro_rules! quote_tt {
(($($t:tt)*)) => { Group::new(Delimiter::Parenthesis, quote!($($t)*)) };
@ -63,7 +63,7 @@ macro_rules! quote {
#[unstable(feature = "proc_macro_quote", issue = "54722")]
pub fn quote(stream: TokenStream) -> TokenStream {
if stream.is_empty() {
return quote!(::TokenStream::new());
return quote!(crate::TokenStream::new());
}
let mut after_dollar = false;
let tokens = stream
@ -73,7 +73,7 @@ pub fn quote(stream: TokenStream) -> TokenStream {
after_dollar = false;
match tree {
TokenTree::Ident(_) => {
return Some(quote!(Into::<::TokenStream>::into(
return Some(quote!(Into::<crate::TokenStream>::into(
Clone::clone(&(@ tree))),));
}
TokenTree::Punct(ref tt) if tt.as_char() == '$' => {}
@ -86,33 +86,33 @@ pub fn quote(stream: TokenStream) -> TokenStream {
}
}
Some(quote!(::TokenStream::from((@ match tree {
TokenTree::Punct(tt) => quote!(::TokenTree::Punct(::Punct::new(
Some(quote!(crate::TokenStream::from((@ match tree {
TokenTree::Punct(tt) => quote!(crate::TokenTree::Punct(crate::Punct::new(
(@ TokenTree::from(Literal::character(tt.as_char()))),
(@ match tt.spacing() {
Spacing::Alone => quote!(::Spacing::Alone),
Spacing::Joint => quote!(::Spacing::Joint),
Spacing::Alone => quote!(crate::Spacing::Alone),
Spacing::Joint => quote!(crate::Spacing::Joint),
}),
))),
TokenTree::Group(tt) => quote!(::TokenTree::Group(::Group::new(
TokenTree::Group(tt) => quote!(crate::TokenTree::Group(crate::Group::new(
(@ match tt.delimiter() {
Delimiter::Parenthesis => quote!(::Delimiter::Parenthesis),
Delimiter::Brace => quote!(::Delimiter::Brace),
Delimiter::Bracket => quote!(::Delimiter::Bracket),
Delimiter::None => quote!(::Delimiter::None),
Delimiter::Parenthesis => quote!(crate::Delimiter::Parenthesis),
Delimiter::Brace => quote!(crate::Delimiter::Brace),
Delimiter::Bracket => quote!(crate::Delimiter::Bracket),
Delimiter::None => quote!(crate::Delimiter::None),
}),
(@ quote(tt.stream())),
))),
TokenTree::Ident(tt) => quote!(::TokenTree::Ident(::Ident::new(
TokenTree::Ident(tt) => quote!(crate::TokenTree::Ident(crate::Ident::new(
(@ TokenTree::from(Literal::string(&tt.to_string()))),
(@ quote_span(tt.span())),
))),
TokenTree::Literal(tt) => quote!(::TokenTree::Literal({
TokenTree::Literal(tt) => quote!(crate::TokenTree::Literal({
let mut iter = (@ TokenTree::from(Literal::string(&tt.to_string())))
.parse::<::TokenStream>()
.parse::<crate::TokenStream>()
.unwrap()
.into_iter();
if let (Some(::TokenTree::Literal(mut lit)), None) =
if let (Some(crate::TokenTree::Literal(mut lit)), None) =
(iter.next(), iter.next())
{
lit.set_span((@ quote_span(tt.span())));
@ -129,12 +129,12 @@ pub fn quote(stream: TokenStream) -> TokenStream {
panic!("unexpected trailing `$` in `quote!`");
}
quote!([(@ tokens)].iter().cloned().collect::<::TokenStream>())
quote!([(@ tokens)].iter().cloned().collect::<crate::TokenStream>())
}
/// Quote a `Span` into a `TokenStream`.
/// This is needed to implement a custom quoter.
#[unstable(feature = "proc_macro_quote", issue = "54722")]
pub fn quote_span(_: Span) -> TokenStream {
quote!(::Span::def_site())
quote!(crate::Span::def_site())
}