Skip to content

Commit ab8105e

Browse files
committed
tokenstream: don't depend on pprust
1 parent 742ec4b commit ab8105e

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

src/libsyntax/ext/mbe/macro_rules.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ fn generic_extension<'cx>(
174174
rhses: &[mbe::TokenTree],
175175
) -> Box<dyn MacResult + 'cx> {
176176
if cx.trace_macros() {
177-
trace_macros_note(cx, sp, format!("expanding `{}! {{ {} }}`", name, arg));
177+
let msg = format!("expanding `{}! {{ {} }}`", name, pprust::tts_to_string(arg.clone()));
178+
trace_macros_note(cx, sp, msg);
178179
}
179180

180181
// Which arm's failure should we report? (the one furthest along)
@@ -212,7 +213,8 @@ fn generic_extension<'cx>(
212213
}
213214

214215
if cx.trace_macros() {
215-
trace_macros_note(cx, sp, format!("to `{}`", tts));
216+
let msg = format!("to `{}`", pprust::tts_to_string(tts.clone()));
217+
trace_macros_note(cx, sp, msg);
216218
}
217219

218220
let directory = Directory {

src/libsyntax/ext/proc_macro_server.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::ast;
22
use crate::ext::base::ExtCtxt;
33
use crate::parse::{self, token, ParseSess};
44
use crate::parse::lexer::comments;
5+
use crate::print::pprust;
56
use crate::tokenstream::{self, DelimSpan, IsJoint::*, TokenStream, TreeAndJoint};
67

78
use errors::Diagnostic;
@@ -407,7 +408,7 @@ impl server::TokenStream for Rustc<'_> {
407408
)
408409
}
409410
fn to_string(&mut self, stream: &Self::TokenStream) -> String {
410-
stream.to_string()
411+
pprust::tts_to_string(stream.clone())
411412
}
412413
fn from_token_tree(
413414
&mut self,

src/libsyntax/tokenstream.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
//! ownership of the original.
1515
1616
use crate::parse::token::{self, DelimToken, Token, TokenKind};
17-
use crate::print::pprust;
1817

1918
use syntax_pos::{BytePos, Span, DUMMY_SP};
2019
#[cfg(target_arch = "x86_64")]
@@ -23,7 +22,7 @@ use rustc_data_structures::sync::Lrc;
2322
use rustc_serialize::{Decoder, Decodable, Encoder, Encodable};
2423
use smallvec::{SmallVec, smallvec};
2524

26-
use std::{fmt, iter, mem};
25+
use std::{iter, mem};
2726

2827
#[cfg(test)]
2928
mod tests;
@@ -507,12 +506,6 @@ impl Cursor {
507506
}
508507
}
509508

510-
impl fmt::Display for TokenStream {
511-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
512-
f.write_str(&pprust::tts_to_string(self.clone()))
513-
}
514-
}
515-
516509
impl Encodable for TokenStream {
517510
fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), E::Error> {
518511
self.trees().collect::<Vec<_>>().encode(encoder)

0 commit comments

Comments
 (0)