Skip to content

Commit 2800bc2

Browse files
authored
Rollup merge of rust-lang#65363 - Centril:less-pprust, r=Mark-Simulacrum
Remove implicit dependencies on syntax::pprust Part of rust-lang#65324. The main goal here is to facilitate the eventual move of pprust out from libsyntax and because an AST definition typically should not depend on its pretty printer. r? @estebank
2 parents 66e4288 + ab8105e commit 2800bc2

File tree

18 files changed

+101
-99
lines changed

18 files changed

+101
-99
lines changed

src/librustc/lint/levels.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey, StableHa
1212
use syntax::ast;
1313
use syntax::attr;
1414
use syntax::feature_gate;
15+
use syntax::print::pprust;
1516
use syntax::source_map::MultiSpan;
1617
use syntax::symbol::{Symbol, sym};
1718

@@ -285,7 +286,7 @@ impl<'a> LintLevelsBuilder<'a> {
285286
tool_ident.span,
286287
E0710,
287288
"an unknown tool name found in scoped lint: `{}`",
288-
meta_item.path
289+
pprust::path_to_string(&meta_item.path),
289290
);
290291
continue;
291292
}

src/librustc_lint/builtin.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use syntax::feature_gate::{Stability, deprecated_attributes};
4545
use syntax_pos::{BytePos, Span};
4646
use syntax::symbol::{Symbol, kw, sym};
4747
use syntax::errors::{Applicability, DiagnosticBuilder};
48-
use syntax::print::pprust::expr_to_string;
48+
use syntax::print::pprust::{self, expr_to_string};
4949
use syntax::visit::FnKind;
5050

5151
use rustc::hir::{self, GenericParamKind, PatKind};
@@ -701,7 +701,8 @@ impl EarlyLintPass for DeprecatedAttr {
701701
}
702702
}
703703
if attr.check_name(sym::no_start) || attr.check_name(sym::crate_id) {
704-
let msg = format!("use of deprecated attribute `{}`: no longer used.", attr.path);
704+
let path_str = pprust::path_to_string(&attr.path);
705+
let msg = format!("use of deprecated attribute `{}`: no longer used.", path_str);
705706
lint_deprecated_attr(cx, attr, &msg, None);
706707
}
707708
}

src/librustc_mir/dataflow/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use syntax::ast::{self, MetaItem};
2+
use syntax::print::pprust;
23
use syntax::symbol::{Symbol, sym};
34

45
use rustc_index::bit_set::{BitSet, HybridBitSet};
@@ -159,9 +160,8 @@ where
159160
if let Some(s) = item.value_str() {
160161
return Some(s.to_string())
161162
} else {
162-
sess.span_err(
163-
item.span,
164-
&format!("{} attribute requires a path", item.path));
163+
let path = pprust::path_to_string(&item.path);
164+
sess.span_err(item.span, &format!("{} attribute requires a path", path));
165165
return None;
166166
}
167167
}

src/librustc_passes/ast_validation.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ impl<'a> AstValidator<'a> {
263263
let mut err = self.err_handler().struct_span_err(poly.span,
264264
&format!("`?Trait` is not permitted in {}", where_));
265265
if is_trait {
266-
err.note(&format!("traits are `?{}` by default", poly.trait_ref.path));
266+
let path_str = pprust::path_to_string(&poly.trait_ref.path);
267+
err.note(&format!("traits are `?{}` by default", path_str));
267268
}
268269
err.emit();
269270
}

src/librustc_resolve/build_reduced_graph.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use syntax::ext::expand::AstFragment;
3737
use syntax::ext::hygiene::ExpnId;
3838
use syntax::feature_gate::is_builtin_attr;
3939
use syntax::parse::token::{self, Token};
40+
use syntax::print::pprust;
4041
use syntax::{span_err, struct_span_err};
4142
use syntax::source_map::{respan, Spanned};
4243
use syntax::symbol::{kw, sym};
@@ -228,7 +229,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
228229
.span_suggestion(
229230
path.span,
230231
"try",
231-
format!("crate::{}", path),
232+
format!("crate::{}", pprust::path_to_string(&path)),
232233
Applicability::MaybeIncorrect,
233234
)
234235
.emit();

src/librustc_resolve/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use rustc_metadata::cstore::CStore;
3838
use syntax::ext::hygiene::{ExpnId, Transparency, SyntaxContext};
3939
use syntax::ast::{self, Name, NodeId, Ident, FloatTy, IntTy, UintTy};
4040
use syntax::ext::base::{SyntaxExtension, MacroKind, SpecialDerives};
41+
use syntax::print::pprust;
4142
use syntax::symbol::{kw, sym};
4243

4344
use syntax::visit::{self, Visitor};
@@ -2011,13 +2012,13 @@ impl<'a> Resolver<'a> {
20112012
let mut candidates =
20122013
self.lookup_import_candidates(ident, TypeNS, is_mod);
20132014
candidates.sort_by_cached_key(|c| {
2014-
(c.path.segments.len(), c.path.to_string())
2015+
(c.path.segments.len(), pprust::path_to_string(&c.path))
20152016
});
20162017
if let Some(candidate) = candidates.get(0) {
20172018
(
20182019
String::from("unresolved import"),
20192020
Some((
2020-
vec![(ident.span, candidate.path.to_string())],
2021+
vec![(ident.span, pprust::path_to_string(&candidate.path))],
20212022
String::from("a similar path exists"),
20222023
Applicability::MaybeIncorrect,
20232024
)),

src/librustc_resolve/macros.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use syntax::ext::hygiene::{self, ExpnId, ExpnData, ExpnKind};
2121
use syntax::ext::compile_declarative_macro;
2222
use syntax::feature_gate::{emit_feature_err, is_builtin_attr_name};
2323
use syntax::feature_gate::GateIssue;
24+
use syntax::print::pprust;
2425
use syntax::symbol::{Symbol, kw, sym};
2526
use syntax_pos::{Span, DUMMY_SP};
2627

@@ -324,7 +325,8 @@ impl<'a> Resolver<'a> {
324325

325326
Ok(if ext.macro_kind() != kind {
326327
let expected = kind.descr_expected();
327-
let msg = format!("expected {}, found {} `{}`", expected, res.descr(), path);
328+
let path_str = pprust::path_to_string(path);
329+
let msg = format!("expected {}, found {} `{}`", expected, res.descr(), path_str);
328330
self.session.struct_span_err(path.span, &msg)
329331
.span_label(path.span, format!("not {} {}", kind.article(), expected))
330332
.emit();
@@ -805,14 +807,16 @@ impl<'a> Resolver<'a> {
805807
}
806808
}
807809
if let Some(depr) = &stability.rustc_depr {
808-
let (message, lint) = stability::rustc_deprecation_message(depr, &path.to_string());
810+
let path = pprust::path_to_string(path);
811+
let (message, lint) = stability::rustc_deprecation_message(depr, &path);
809812
stability::early_report_deprecation(
810813
self.session, &message, depr.suggestion, lint, span
811814
);
812815
}
813816
}
814817
if let Some(depr) = &ext.deprecation {
815-
let (message, lint) = stability::deprecation_message(depr, &path.to_string());
818+
let path = pprust::path_to_string(&path);
819+
let (message, lint) = stability::deprecation_message(depr, &path);
816820
stability::early_report_deprecation(self.session, &message, None, lint, span);
817821
}
818822
}

src/librustdoc/html/render.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ use serialize::json::{ToJson, Json, as_json};
4646
use syntax::ast;
4747
use syntax::edition::Edition;
4848
use syntax::ext::base::MacroKind;
49+
use syntax::print::pprust;
4950
use syntax::source_map::FileName;
5051
use syntax::feature_gate::UnstableFeatures;
5152
use syntax::symbol::{Symbol, sym};
@@ -2957,7 +2958,7 @@ fn item_enum(w: &mut Buffer, cx: &Context, it: &clean::Item, e: &clean::Enum) {
29572958
}
29582959

29592960
fn render_attribute(attr: &ast::MetaItem) -> Option<String> {
2960-
let path = attr.path.to_string();
2961+
let path = pprust::path_to_string(&attr.path);
29612962

29622963
if attr.is_word() {
29632964
Some(path)

src/libsyntax/ast.rs

+6-48
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ pub use crate::util::parser::ExprPrecedence;
77

88
use crate::ext::hygiene::ExpnId;
99
use crate::parse::token::{self, DelimToken};
10-
use crate::print::pprust;
1110
use crate::ptr::P;
1211
use crate::source_map::{dummy_spanned, respan, Spanned};
1312
use crate::symbol::{kw, sym, Symbol};
@@ -70,7 +69,7 @@ impl fmt::Display for Lifetime {
7069
/// along with a bunch of supporting information.
7170
///
7271
/// E.g., `std::cmp::PartialEq`.
73-
#[derive(Clone, RustcEncodable, RustcDecodable)]
72+
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
7473
pub struct Path {
7574
pub span: Span,
7675
/// The segments in the path: the things separated by `::`.
@@ -86,18 +85,6 @@ impl PartialEq<Symbol> for Path {
8685
}
8786
}
8887

89-
impl fmt::Debug for Path {
90-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
91-
write!(f, "path({})", pprust::path_to_string(self))
92-
}
93-
}
94-
95-
impl fmt::Display for Path {
96-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
97-
write!(f, "{}", pprust::path_to_string(self))
98-
}
99-
}
100-
10188
impl Path {
10289
// Convert a span and an identifier to the corresponding
10390
// one-segment path.
@@ -507,19 +494,13 @@ pub struct Block {
507494
pub span: Span,
508495
}
509496

510-
#[derive(Clone, RustcEncodable, RustcDecodable)]
497+
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
511498
pub struct Pat {
512499
pub id: NodeId,
513500
pub kind: PatKind,
514501
pub span: Span,
515502
}
516503

517-
impl fmt::Debug for Pat {
518-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
519-
write!(f, "pat({}: {})", self.id, pprust::pat_to_string(self))
520-
}
521-
}
522-
523504
impl Pat {
524505
/// Attempt reparsing the pattern as a type.
525506
/// This is intended for use by diagnostics.
@@ -831,7 +812,7 @@ impl UnOp {
831812
}
832813

833814
/// A statement
834-
#[derive(Clone, RustcEncodable, RustcDecodable)]
815+
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
835816
pub struct Stmt {
836817
pub id: NodeId,
837818
pub kind: StmtKind,
@@ -865,18 +846,7 @@ impl Stmt {
865846
}
866847
}
867848

868-
impl fmt::Debug for Stmt {
869-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
870-
write!(
871-
f,
872-
"stmt({}: {})",
873-
self.id.to_string(),
874-
pprust::stmt_to_string(self)
875-
)
876-
}
877-
}
878-
879-
#[derive(Clone, RustcEncodable, RustcDecodable)]
849+
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
880850
pub enum StmtKind {
881851
/// A local (let) binding.
882852
Local(P<Local>),
@@ -973,7 +943,7 @@ pub struct AnonConst {
973943
}
974944

975945
/// An expression.
976-
#[derive(Clone, RustcEncodable, RustcDecodable)]
946+
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
977947
pub struct Expr {
978948
pub id: NodeId,
979949
pub kind: ExprKind,
@@ -1100,12 +1070,6 @@ impl Expr {
11001070
}
11011071
}
11021072

1103-
impl fmt::Debug for Expr {
1104-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1105-
write!(f, "expr({}: {})", self.id, pprust::expr_to_string(self))
1106-
}
1107-
}
1108-
11091073
/// Limit types of a range (inclusive or exclusive)
11101074
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug)]
11111075
pub enum RangeLimits {
@@ -1660,19 +1624,13 @@ pub enum AssocTyConstraintKind {
16601624
},
16611625
}
16621626

1663-
#[derive(Clone, RustcEncodable, RustcDecodable)]
1627+
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
16641628
pub struct Ty {
16651629
pub id: NodeId,
16661630
pub kind: TyKind,
16671631
pub span: Span,
16681632
}
16691633

1670-
impl fmt::Debug for Ty {
1671-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1672-
write!(f, "type({})", pprust::ty_to_string(self))
1673-
}
1674-
}
1675-
16761634
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
16771635
pub struct BareFnTy {
16781636
pub unsafety: Unsafety,

src/libsyntax/attr/builtin.rs

+25-9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::early_buffered_lints::BufferedEarlyLintId;
55
use crate::ext::base::ExtCtxt;
66
use crate::feature_gate::{Features, GatedCfg};
77
use crate::parse::ParseSess;
8+
use crate::print::pprust;
89

910
use errors::{Applicability, Handler};
1011
use syntax_pos::hygiene::Transparency;
@@ -243,7 +244,11 @@ fn find_stability_generic<'a, I>(sess: &ParseSess,
243244
let meta = meta.as_ref().unwrap();
244245
let get = |meta: &MetaItem, item: &mut Option<Symbol>| {
245246
if item.is_some() {
246-
handle_errors(sess, meta.span, AttrError::MultipleItem(meta.path.to_string()));
247+
handle_errors(
248+
sess,
249+
meta.span,
250+
AttrError::MultipleItem(pprust::path_to_string(&meta.path)),
251+
);
247252
return false
248253
}
249254
if let Some(v) = meta.value_str() {
@@ -271,7 +276,10 @@ fn find_stability_generic<'a, I>(sess: &ParseSess,
271276
handle_errors(
272277
sess,
273278
mi.span,
274-
AttrError::UnknownMetaItem(mi.path.to_string(), expected),
279+
AttrError::UnknownMetaItem(
280+
pprust::path_to_string(&mi.path),
281+
expected,
282+
),
275283
);
276284
continue 'outer
277285
}
@@ -362,7 +370,7 @@ fn find_stability_generic<'a, I>(sess: &ParseSess,
362370
sess,
363371
meta.span(),
364372
AttrError::UnknownMetaItem(
365-
mi.path.to_string(),
373+
pprust::path_to_string(&mi.path),
366374
&["feature", "reason", "issue", "soft"]
367375
),
368376
);
@@ -434,7 +442,8 @@ fn find_stability_generic<'a, I>(sess: &ParseSess,
434442
sess,
435443
meta.span(),
436444
AttrError::UnknownMetaItem(
437-
mi.path.to_string(), &["since", "note"],
445+
pprust::path_to_string(&mi.path),
446+
&["since", "note"],
438447
),
439448
);
440449
continue 'outer
@@ -597,8 +606,11 @@ pub fn eval_condition<F>(cfg: &ast::MetaItem, sess: &ParseSess, eval: &mut F)
597606
!eval_condition(mis[0].meta_item().unwrap(), sess, eval)
598607
},
599608
_ => {
600-
span_err!(sess.span_diagnostic, cfg.span, E0537,
601-
"invalid predicate `{}`", cfg.path);
609+
span_err!(
610+
sess.span_diagnostic, cfg.span, E0537,
611+
"invalid predicate `{}`",
612+
pprust::path_to_string(&cfg.path)
613+
);
602614
false
603615
}
604616
}
@@ -653,7 +665,9 @@ fn find_deprecation_generic<'a, I>(sess: &ParseSess,
653665
let get = |meta: &MetaItem, item: &mut Option<Symbol>| {
654666
if item.is_some() {
655667
handle_errors(
656-
sess, meta.span, AttrError::MultipleItem(meta.path.to_string())
668+
sess,
669+
meta.span,
670+
AttrError::MultipleItem(pprust::path_to_string(&meta.path)),
657671
);
658672
return false
659673
}
@@ -691,8 +705,10 @@ fn find_deprecation_generic<'a, I>(sess: &ParseSess,
691705
handle_errors(
692706
sess,
693707
meta.span(),
694-
AttrError::UnknownMetaItem(mi.path.to_string(),
695-
&["since", "note"]),
708+
AttrError::UnknownMetaItem(
709+
pprust::path_to_string(&mi.path),
710+
&["since", "note"],
711+
),
696712
);
697713
continue 'outer
698714
}

0 commit comments

Comments
 (0)