Skip to content

Commit

Permalink
refactor: use pprust explicitly
Browse files Browse the repository at this point in the history
implicit pprust dependencies were removed and now require explicit usage
rust-lang/rust#65363
  • Loading branch information
calebcartwright committed Jan 15, 2020
1 parent f87fe48 commit 73adbd3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
5 changes: 3 additions & 2 deletions rustfmt-core/rustfmt-lib/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ fn rewrite_macro_name(
// Avoid using pretty-printer in the common case.
format!("{}!", rewrite_ident(context, path.segments[0].ident))
} else {
format!("{}!", path)
format!("{}!", pprust::path_to_string(path))
};
match extra_ident {
Some(ident) if ident.name != kw::Invalid => format!("{} {}", name, ident),
Expand Down Expand Up @@ -1190,7 +1190,8 @@ pub(crate) fn convert_try_mac(mac: &ast::Mac, context: &RewriteContext<'_>) -> O
// `r#try!` must be used in the 2018 Edition.
// https://doc.rust-lang.org/std/macro.try.html
// https://github.com/rust-lang/rust/pull/62672
if &mac.path.to_string() == "try" || &mac.path.to_string() == "r#try" {
let path = &pprust::path_to_string(&mac.path);
if path == "try" || path == "r#try" {
let ts: TokenStream = mac.tts.clone();
let mut parser = new_parser_from_tts(context.parse_sess.inner(), ts.trees().collect());

Expand Down
7 changes: 1 addition & 6 deletions rustfmt-core/rustfmt-lib/src/spanned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ macro_rules! span_with_attrs_lo_hi {
if attrs.is_empty() {
mk_sp($lo, $hi)
} else {
// this path is already gone at latest rust-ap-* 627.0.0
if attrs[0].item.path.to_string() == "warn_directory_ownership" {
mk_sp($lo, $hi)
} else {
mk_sp(attrs[0].span.lo(), $hi)
}
mk_sp(attrs[0].span.lo(), $hi)
}
}};
}
Expand Down
6 changes: 3 additions & 3 deletions rustfmt-core/rustfmt-lib/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use syntax::ast::{
self, Attribute, CrateSugar, MetaItem, MetaItemKind, NestedMetaItem, NodeId, Path, Visibility,
VisibilityKind,
};
use syntax::ptr;
use syntax::{ptr, print::pprust};
use unicode_width::UnicodeWidthStr;

use crate::comment::{filter_normal_code, CharClasses, FullCodeCharKind, LineClasses};
Expand Down Expand Up @@ -42,7 +42,7 @@ pub(crate) fn is_same_visibility(a: &Visibility, b: &Visibility) -> bool {
(
VisibilityKind::Restricted { path: p, .. },
VisibilityKind::Restricted { path: q, .. },
) => p.to_string() == q.to_string(),
) => pprust::path_to_string(p) == pprust::path_to_string(q),
(VisibilityKind::Public, VisibilityKind::Public)
| (VisibilityKind::Inherited, VisibilityKind::Inherited)
| (
Expand Down Expand Up @@ -241,7 +241,7 @@ pub(crate) fn last_line_extendable(s: &str) -> bool {
fn is_skip(meta_item: &MetaItem) -> bool {
match meta_item.kind {
MetaItemKind::Word => {
let path_str = meta_item.path.to_string();
let path_str = pprust::path_to_string(&meta_item.path);
path_str == skip_annotation().as_str() || path_str == depr_skip_annotation().as_str()
}
MetaItemKind::List(ref l) => {
Expand Down

0 comments on commit 73adbd3

Please sign in to comment.