Skip to content

Remove implicit dependencies on syntax::pprust #65363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/librustc/lint/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey, StableHa
use syntax::ast;
use syntax::attr;
use syntax::feature_gate;
use syntax::print::pprust;
use syntax::source_map::MultiSpan;
use syntax::symbol::{Symbol, sym};

Expand Down Expand Up @@ -285,7 +286,7 @@ impl<'a> LintLevelsBuilder<'a> {
tool_ident.span,
E0710,
"an unknown tool name found in scoped lint: `{}`",
meta_item.path
pprust::path_to_string(&meta_item.path),
);
continue;
}
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use syntax::feature_gate::{Stability, deprecated_attributes};
use syntax_pos::{BytePos, Span};
use syntax::symbol::{Symbol, kw, sym};
use syntax::errors::{Applicability, DiagnosticBuilder};
use syntax::print::pprust::expr_to_string;
use syntax::print::pprust::{self, expr_to_string};
use syntax::visit::FnKind;

use rustc::hir::{self, GenericParamKind, PatKind};
Expand Down Expand Up @@ -701,7 +701,8 @@ impl EarlyLintPass for DeprecatedAttr {
}
}
if attr.check_name(sym::no_start) || attr.check_name(sym::crate_id) {
let msg = format!("use of deprecated attribute `{}`: no longer used.", attr.path);
let path_str = pprust::path_to_string(&attr.path);
let msg = format!("use of deprecated attribute `{}`: no longer used.", path_str);
lint_deprecated_attr(cx, attr, &msg, None);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/dataflow/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use syntax::ast::{self, MetaItem};
use syntax::print::pprust;
use syntax::symbol::{Symbol, sym};

use rustc_index::bit_set::{BitSet, HybridBitSet};
Expand Down Expand Up @@ -159,9 +160,8 @@ where
if let Some(s) = item.value_str() {
return Some(s.to_string())
} else {
sess.span_err(
item.span,
&format!("{} attribute requires a path", item.path));
let path = pprust::path_to_string(&item.path);
sess.span_err(item.span, &format!("{} attribute requires a path", path));
return None;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_passes/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ impl<'a> AstValidator<'a> {
let mut err = self.err_handler().struct_span_err(poly.span,
&format!("`?Trait` is not permitted in {}", where_));
if is_trait {
err.note(&format!("traits are `?{}` by default", poly.trait_ref.path));
let path_str = pprust::path_to_string(&poly.trait_ref.path);
err.note(&format!("traits are `?{}` by default", path_str));
}
err.emit();
}
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use syntax::ext::expand::AstFragment;
use syntax::ext::hygiene::ExpnId;
use syntax::feature_gate::is_builtin_attr;
use syntax::parse::token::{self, Token};
use syntax::print::pprust;
use syntax::{span_err, struct_span_err};
use syntax::source_map::{respan, Spanned};
use syntax::symbol::{kw, sym};
Expand Down Expand Up @@ -228,7 +229,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
.span_suggestion(
path.span,
"try",
format!("crate::{}", path),
format!("crate::{}", pprust::path_to_string(&path)),
Applicability::MaybeIncorrect,
)
.emit();
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use rustc_metadata::cstore::CStore;
use syntax::ext::hygiene::{ExpnId, Transparency, SyntaxContext};
use syntax::ast::{self, Name, NodeId, Ident, FloatTy, IntTy, UintTy};
use syntax::ext::base::{SyntaxExtension, MacroKind, SpecialDerives};
use syntax::print::pprust;
use syntax::symbol::{kw, sym};

use syntax::visit::{self, Visitor};
Expand Down Expand Up @@ -2011,13 +2012,13 @@ impl<'a> Resolver<'a> {
let mut candidates =
self.lookup_import_candidates(ident, TypeNS, is_mod);
candidates.sort_by_cached_key(|c| {
(c.path.segments.len(), c.path.to_string())
(c.path.segments.len(), pprust::path_to_string(&c.path))
});
if let Some(candidate) = candidates.get(0) {
(
String::from("unresolved import"),
Some((
vec![(ident.span, candidate.path.to_string())],
vec![(ident.span, pprust::path_to_string(&candidate.path))],
String::from("a similar path exists"),
Applicability::MaybeIncorrect,
)),
Expand Down
10 changes: 7 additions & 3 deletions src/librustc_resolve/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use syntax::ext::hygiene::{self, ExpnId, ExpnData, ExpnKind};
use syntax::ext::compile_declarative_macro;
use syntax::feature_gate::{emit_feature_err, is_builtin_attr_name};
use syntax::feature_gate::GateIssue;
use syntax::print::pprust;
use syntax::symbol::{Symbol, kw, sym};
use syntax_pos::{Span, DUMMY_SP};

Expand Down Expand Up @@ -324,7 +325,8 @@ impl<'a> Resolver<'a> {

Ok(if ext.macro_kind() != kind {
let expected = kind.descr_expected();
let msg = format!("expected {}, found {} `{}`", expected, res.descr(), path);
let path_str = pprust::path_to_string(path);
let msg = format!("expected {}, found {} `{}`", expected, res.descr(), path_str);
self.session.struct_span_err(path.span, &msg)
.span_label(path.span, format!("not {} {}", kind.article(), expected))
.emit();
Expand Down Expand Up @@ -805,14 +807,16 @@ impl<'a> Resolver<'a> {
}
}
if let Some(depr) = &stability.rustc_depr {
let (message, lint) = stability::rustc_deprecation_message(depr, &path.to_string());
let path = pprust::path_to_string(path);
let (message, lint) = stability::rustc_deprecation_message(depr, &path);
stability::early_report_deprecation(
self.session, &message, depr.suggestion, lint, span
);
}
}
if let Some(depr) = &ext.deprecation {
let (message, lint) = stability::deprecation_message(depr, &path.to_string());
let path = pprust::path_to_string(&path);
let (message, lint) = stability::deprecation_message(depr, &path);
stability::early_report_deprecation(self.session, &message, None, lint, span);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ use serialize::json::{ToJson, Json, as_json};
use syntax::ast;
use syntax::edition::Edition;
use syntax::ext::base::MacroKind;
use syntax::print::pprust;
use syntax::source_map::FileName;
use syntax::feature_gate::UnstableFeatures;
use syntax::symbol::{Symbol, sym};
Expand Down Expand Up @@ -2957,7 +2958,7 @@ fn item_enum(w: &mut Buffer, cx: &Context, it: &clean::Item, e: &clean::Enum) {
}

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

if attr.is_word() {
Some(path)
Expand Down
54 changes: 6 additions & 48 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pub use crate::util::parser::ExprPrecedence;

use crate::ext::hygiene::ExpnId;
use crate::parse::token::{self, DelimToken};
use crate::print::pprust;
use crate::ptr::P;
use crate::source_map::{dummy_spanned, respan, Spanned};
use crate::symbol::{kw, sym, Symbol};
Expand Down Expand Up @@ -70,7 +69,7 @@ impl fmt::Display for Lifetime {
/// along with a bunch of supporting information.
///
/// E.g., `std::cmp::PartialEq`.
#[derive(Clone, RustcEncodable, RustcDecodable)]
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct Path {
pub span: Span,
/// The segments in the path: the things separated by `::`.
Expand All @@ -86,18 +85,6 @@ impl PartialEq<Symbol> for Path {
}
}

impl fmt::Debug for Path {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "path({})", pprust::path_to_string(self))
}
}

impl fmt::Display for Path {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", pprust::path_to_string(self))
}
}

impl Path {
// Convert a span and an identifier to the corresponding
// one-segment path.
Expand Down Expand Up @@ -507,19 +494,13 @@ pub struct Block {
pub span: Span,
}

#[derive(Clone, RustcEncodable, RustcDecodable)]
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct Pat {
pub id: NodeId,
pub kind: PatKind,
pub span: Span,
}

impl fmt::Debug for Pat {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "pat({}: {})", self.id, pprust::pat_to_string(self))
}
}

impl Pat {
/// Attempt reparsing the pattern as a type.
/// This is intended for use by diagnostics.
Expand Down Expand Up @@ -831,7 +812,7 @@ impl UnOp {
}

/// A statement
#[derive(Clone, RustcEncodable, RustcDecodable)]
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct Stmt {
pub id: NodeId,
pub kind: StmtKind,
Expand Down Expand Up @@ -865,18 +846,7 @@ impl Stmt {
}
}

impl fmt::Debug for Stmt {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"stmt({}: {})",
self.id.to_string(),
pprust::stmt_to_string(self)
)
}
}

#[derive(Clone, RustcEncodable, RustcDecodable)]
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub enum StmtKind {
/// A local (let) binding.
Local(P<Local>),
Expand Down Expand Up @@ -973,7 +943,7 @@ pub struct AnonConst {
}

/// An expression.
#[derive(Clone, RustcEncodable, RustcDecodable)]
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct Expr {
pub id: NodeId,
pub kind: ExprKind,
Expand Down Expand Up @@ -1100,12 +1070,6 @@ impl Expr {
}
}

impl fmt::Debug for Expr {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "expr({}: {})", self.id, pprust::expr_to_string(self))
}
}

/// Limit types of a range (inclusive or exclusive)
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug)]
pub enum RangeLimits {
Expand Down Expand Up @@ -1660,19 +1624,13 @@ pub enum AssocTyConstraintKind {
},
}

#[derive(Clone, RustcEncodable, RustcDecodable)]
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct Ty {
pub id: NodeId,
pub kind: TyKind,
pub span: Span,
}

impl fmt::Debug for Ty {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "type({})", pprust::ty_to_string(self))
}
}

#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct BareFnTy {
pub unsafety: Unsafety,
Expand Down
34 changes: 25 additions & 9 deletions src/libsyntax/attr/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::early_buffered_lints::BufferedEarlyLintId;
use crate::ext::base::ExtCtxt;
use crate::feature_gate::{Features, GatedCfg};
use crate::parse::ParseSess;
use crate::print::pprust;

use errors::{Applicability, Handler};
use syntax_pos::hygiene::Transparency;
Expand Down Expand Up @@ -243,7 +244,11 @@ fn find_stability_generic<'a, I>(sess: &ParseSess,
let meta = meta.as_ref().unwrap();
let get = |meta: &MetaItem, item: &mut Option<Symbol>| {
if item.is_some() {
handle_errors(sess, meta.span, AttrError::MultipleItem(meta.path.to_string()));
handle_errors(
sess,
meta.span,
AttrError::MultipleItem(pprust::path_to_string(&meta.path)),
);
return false
}
if let Some(v) = meta.value_str() {
Expand Down Expand Up @@ -271,7 +276,10 @@ fn find_stability_generic<'a, I>(sess: &ParseSess,
handle_errors(
sess,
mi.span,
AttrError::UnknownMetaItem(mi.path.to_string(), expected),
AttrError::UnknownMetaItem(
pprust::path_to_string(&mi.path),
expected,
),
);
continue 'outer
}
Expand Down Expand Up @@ -362,7 +370,7 @@ fn find_stability_generic<'a, I>(sess: &ParseSess,
sess,
meta.span(),
AttrError::UnknownMetaItem(
mi.path.to_string(),
pprust::path_to_string(&mi.path),
&["feature", "reason", "issue", "soft"]
),
);
Expand Down Expand Up @@ -434,7 +442,8 @@ fn find_stability_generic<'a, I>(sess: &ParseSess,
sess,
meta.span(),
AttrError::UnknownMetaItem(
mi.path.to_string(), &["since", "note"],
pprust::path_to_string(&mi.path),
&["since", "note"],
),
);
continue 'outer
Expand Down Expand Up @@ -597,8 +606,11 @@ pub fn eval_condition<F>(cfg: &ast::MetaItem, sess: &ParseSess, eval: &mut F)
!eval_condition(mis[0].meta_item().unwrap(), sess, eval)
},
_ => {
span_err!(sess.span_diagnostic, cfg.span, E0537,
"invalid predicate `{}`", cfg.path);
span_err!(
sess.span_diagnostic, cfg.span, E0537,
"invalid predicate `{}`",
pprust::path_to_string(&cfg.path)
);
false
}
}
Expand Down Expand Up @@ -653,7 +665,9 @@ fn find_deprecation_generic<'a, I>(sess: &ParseSess,
let get = |meta: &MetaItem, item: &mut Option<Symbol>| {
if item.is_some() {
handle_errors(
sess, meta.span, AttrError::MultipleItem(meta.path.to_string())
sess,
meta.span,
AttrError::MultipleItem(pprust::path_to_string(&meta.path)),
);
return false
}
Expand Down Expand Up @@ -691,8 +705,10 @@ fn find_deprecation_generic<'a, I>(sess: &ParseSess,
handle_errors(
sess,
meta.span(),
AttrError::UnknownMetaItem(mi.path.to_string(),
&["since", "note"]),
AttrError::UnknownMetaItem(
pprust::path_to_string(&mi.path),
&["since", "note"],
),
);
continue 'outer
}
Expand Down
Loading