Skip to content

Commit e233331

Browse files
committed
syntax::print -> new crate rustc_ast_pretty
1 parent 98fd6a5 commit e233331

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+129
-81
lines changed

Cargo.lock

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3093,6 +3093,7 @@ dependencies = [
30933093
"rustc-rayon",
30943094
"rustc-rayon-core",
30953095
"rustc_apfloat",
3096+
"rustc_ast_pretty",
30963097
"rustc_attr",
30973098
"rustc_data_structures",
30983099
"rustc_errors",
@@ -3359,6 +3360,7 @@ version = "0.0.0"
33593360
dependencies = [
33603361
"log",
33613362
"rustc",
3363+
"rustc_ast_pretty",
33623364
"rustc_data_structures",
33633365
"rustc_errors",
33643366
"rustc_hir",
@@ -3375,6 +3377,7 @@ name = "rustc_ast_passes"
33753377
version = "0.0.0"
33763378
dependencies = [
33773379
"log",
3380+
"rustc_ast_pretty",
33783381
"rustc_attr",
33793382
"rustc_data_structures",
33803383
"rustc_errors",
@@ -3385,10 +3388,21 @@ dependencies = [
33853388
"syntax",
33863389
]
33873390

3391+
[[package]]
3392+
name = "rustc_ast_pretty"
3393+
version = "0.0.0"
3394+
dependencies = [
3395+
"log",
3396+
"rustc_data_structures",
3397+
"rustc_span",
3398+
"syntax",
3399+
]
3400+
33883401
[[package]]
33893402
name = "rustc_attr"
33903403
version = "0.0.0"
33913404
dependencies = [
3405+
"rustc_ast_pretty",
33923406
"rustc_data_structures",
33933407
"rustc_errors",
33943408
"rustc_feature",
@@ -3406,6 +3420,7 @@ version = "0.0.0"
34063420
dependencies = [
34073421
"fmt_macros",
34083422
"log",
3423+
"rustc_ast_pretty",
34093424
"rustc_attr",
34103425
"rustc_data_structures",
34113426
"rustc_errors",
@@ -3526,6 +3541,7 @@ dependencies = [
35263541
"lazy_static 1.4.0",
35273542
"log",
35283543
"rustc",
3544+
"rustc_ast_pretty",
35293545
"rustc_codegen_utils",
35303546
"rustc_data_structures",
35313547
"rustc_error_codes",
@@ -3572,6 +3588,7 @@ version = "0.0.0"
35723588
dependencies = [
35733589
"log",
35743590
"rustc_ast_passes",
3591+
"rustc_ast_pretty",
35753592
"rustc_attr",
35763593
"rustc_data_structures",
35773594
"rustc_errors",
@@ -3602,6 +3619,7 @@ version = "0.0.0"
36023619
name = "rustc_hir"
36033620
version = "0.0.0"
36043621
dependencies = [
3622+
"rustc_ast_pretty",
36053623
"rustc_data_structures",
36063624
"rustc_errors",
36073625
"rustc_index",
@@ -3693,6 +3711,7 @@ version = "0.0.0"
36933711
dependencies = [
36943712
"log",
36953713
"rustc",
3714+
"rustc_ast_pretty",
36963715
"rustc_attr",
36973716
"rustc_data_structures",
36983717
"rustc_errors",
@@ -3734,6 +3753,7 @@ dependencies = [
37343753
"log",
37353754
"memmap",
37363755
"rustc",
3756+
"rustc_ast_pretty",
37373757
"rustc_attr",
37383758
"rustc_data_structures",
37393759
"rustc_errors",
@@ -3762,6 +3782,7 @@ dependencies = [
37623782
"polonius-engine",
37633783
"rustc",
37643784
"rustc_apfloat",
3785+
"rustc_ast_pretty",
37653786
"rustc_attr",
37663787
"rustc_data_structures",
37673788
"rustc_errors",
@@ -3805,6 +3826,7 @@ version = "0.0.0"
38053826
dependencies = [
38063827
"bitflags",
38073828
"log",
3829+
"rustc_ast_pretty",
38083830
"rustc_attr",
38093831
"rustc_data_structures",
38103832
"rustc_errors",
@@ -3872,6 +3894,7 @@ dependencies = [
38723894
"log",
38733895
"rustc",
38743896
"rustc_ast_lowering",
3897+
"rustc_ast_pretty",
38753898
"rustc_attr",
38763899
"rustc_data_structures",
38773900
"rustc_errors",
@@ -3893,6 +3916,7 @@ dependencies = [
38933916
"rls-data",
38943917
"rls-span",
38953918
"rustc",
3919+
"rustc_ast_pretty",
38963920
"rustc_codegen_utils",
38973921
"rustc_data_structures",
38983922
"rustc_hir",

src/librustc/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ rustc-rayon = "0.3.0"
2121
rustc-rayon-core = "0.3.0"
2222
polonius-engine = "0.11.0"
2323
rustc_apfloat = { path = "../librustc_apfloat" }
24+
# FIXME(Centril): remove this dependency when stuff is moved to rustc_lint.
25+
rustc_ast_pretty = { path = "../librustc_ast_pretty" }
2426
rustc_attr = { path = "../librustc_attr" }
2527
rustc_feature = { path = "../librustc_feature" }
2628
rustc_hir = { path = "../librustc_hir" }

src/librustc_ast_lowering/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ doctest = false
1212
[dependencies]
1313
log = { version = "0.4", features = ["release_max_level_info", "std"] }
1414
rustc = { path = "../librustc" }
15+
rustc_ast_pretty = { path = "../librustc_ast_pretty" }
1516
rustc_hir = { path = "../librustc_hir" }
1617
rustc_target = { path = "../librustc_target" }
1718
rustc_data_structures = { path = "../librustc_data_structures" }

src/librustc_ast_lowering/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use rustc::dep_graph::DepGraph;
3838
use rustc::hir::map::definitions::{DefKey, DefPathData, Definitions};
3939
use rustc::hir::map::Map;
4040
use rustc::{bug, span_bug};
41+
use rustc_ast_pretty::pprust;
4142
use rustc_data_structures::captures::Captures;
4243
use rustc_data_structures::fx::FxHashSet;
4344
use rustc_data_structures::sync::Lrc;
@@ -60,7 +61,6 @@ use syntax::ast;
6061
use syntax::ast::*;
6162
use syntax::attr;
6263
use syntax::node_id::NodeMap;
63-
use syntax::print::pprust;
6464
use syntax::token::{self, Nonterminal, Token};
6565
use syntax::tokenstream::{TokenStream, TokenTree};
6666
use syntax::visit::{self, Visitor};

src/librustc_ast_passes/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ path = "lib.rs"
1010

1111
[dependencies]
1212
log = "0.4"
13+
rustc_ast_pretty = { path = "../librustc_ast_pretty" }
1314
rustc_attr = { path = "../librustc_attr" }
1415
rustc_data_structures = { path = "../librustc_data_structures" }
1516
rustc_errors = { path = "../librustc_errors" }

src/librustc_ast_passes/ast_validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// This pass is supposed to perform only simple checks not requiring name resolution
77
// or type checking or some other kind of complex analysis.
88

9+
use rustc_ast_pretty::pprust;
910
use rustc_data_structures::fx::FxHashMap;
1011
use rustc_errors::{struct_span_err, Applicability, FatalError};
1112
use rustc_parse::validate_attr;
@@ -19,7 +20,6 @@ use std::mem;
1920
use syntax::ast::*;
2021
use syntax::attr;
2122
use syntax::expand::is_proc_macro_attr;
22-
use syntax::print::pprust;
2323
use syntax::visit::{self, Visitor};
2424
use syntax::walk_list;
2525

src/librustc_ast_pretty/Cargo.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
authors = ["The Rust Project Developers"]
3+
name = "rustc_ast_pretty"
4+
version = "0.0.0"
5+
edition = "2018"
6+
7+
[lib]
8+
name = "rustc_ast_pretty"
9+
path = "lib.rs"
10+
doctest = false
11+
12+
[dependencies]
13+
log = "0.4"
14+
rustc_span = { path = "../librustc_span" }
15+
rustc_data_structures = { path = "../librustc_data_structures" }
16+
syntax = { path = "../libsyntax" }

src/libsyntax/print/helpers.rs renamed to src/librustc_ast_pretty/helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::print::pp::Printer;
1+
use crate::pp::Printer;
22
use std::borrow::Cow;
33

44
impl Printer {

src/librustc_ast_pretty/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![feature(bool_to_option)]
2+
#![feature(crate_visibility_modifier)]
3+
4+
mod helpers;
5+
pub mod pp;
6+
pub mod pprust;
File renamed without changes.

src/libsyntax/print/pprust.rs renamed to src/librustc_ast_pretty/pprust.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
use crate::ast::{self, BlockCheckMode, PatKind, RangeEnd, RangeSyntax};
2-
use crate::ast::{Attribute, GenericArg, MacArgs};
3-
use crate::ast::{GenericBound, SelfKind, TraitBoundModifier};
4-
use crate::attr;
5-
use crate::print::pp::Breaks::{Consistent, Inconsistent};
6-
use crate::print::pp::{self, Breaks};
7-
use crate::ptr::P;
8-
use crate::token::{self, BinOpToken, DelimToken, Nonterminal, Token, TokenKind};
9-
use crate::tokenstream::{self, TokenStream, TokenTree};
10-
use crate::util::classify;
11-
use crate::util::comments;
12-
use crate::util::parser::{self, AssocOp, Fixity};
1+
use crate::pp::Breaks::{Consistent, Inconsistent};
2+
use crate::pp::{self, Breaks};
133

144
use rustc_data_structures::sync::Once;
155
use rustc_span::edition::Edition;
166
use rustc_span::source_map::{dummy_spanned, SourceMap, Spanned};
177
use rustc_span::symbol::{kw, sym, Symbol};
188
use rustc_span::{BytePos, FileName, Span};
9+
use syntax::ast::{self, BlockCheckMode, PatKind, RangeEnd, RangeSyntax};
10+
use syntax::ast::{Attribute, GenericArg, MacArgs};
11+
use syntax::ast::{GenericBound, SelfKind, TraitBoundModifier};
12+
use syntax::attr;
13+
use syntax::ptr::P;
14+
use syntax::token::{self, BinOpToken, DelimToken, Nonterminal, Token, TokenKind};
15+
use syntax::tokenstream::{self, TokenStream, TokenTree};
16+
use syntax::util::parser::{self, AssocOp, Fixity};
17+
use syntax::util::{classify, comments};
1918

2019
use std::borrow::Cow;
2120

src/libsyntax/print/pprust/tests.rs renamed to src/librustc_ast_pretty/pprust/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use super::*;
22

3-
use crate::ast;
4-
use crate::with_default_globals;
53
use rustc_span;
64
use rustc_span::source_map::{dummy_spanned, respan};
5+
use syntax::ast;
6+
use syntax::attr::with_default_globals;
77

88
fn fun_to_string(
99
decl: &ast::FnDecl,

src/librustc_attr/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ path = "lib.rs"
1010
doctest = false
1111

1212
[dependencies]
13+
rustc_ast_pretty = { path = "../librustc_ast_pretty" }
1314
rustc_serialize = { path = "../libserialize", package = "serialize" }
1415
rustc_errors = { path = "../librustc_errors" }
1516
rustc_span = { path = "../librustc_span" }

src/librustc_attr/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use super::{find_by_name, mark_used};
44

5+
use rustc_ast_pretty::pprust;
56
use rustc_errors::{struct_span_err, Applicability, Handler};
67
use rustc_feature::{find_gated_cfg, is_builtin_attr_name, Features, GatedCfg};
78
use rustc_macros::HashStable_Generic;
@@ -10,7 +11,6 @@ use rustc_span::hygiene::Transparency;
1011
use rustc_span::{symbol::sym, symbol::Symbol, Span};
1112
use std::num::NonZeroU32;
1213
use syntax::ast::{self, Attribute, MetaItem, MetaItemKind, NestedMetaItem};
13-
use syntax::print::pprust;
1414

1515
pub fn is_builtin_attr(attr: &Attribute) -> bool {
1616
attr.is_doc_comment() || attr.ident().filter(|ident| is_builtin_attr_name(ident.name)).is_some()

src/librustc_builtin_macros/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ doctest = false
1212
[dependencies]
1313
fmt_macros = { path = "../libfmt_macros" }
1414
log = "0.4"
15+
rustc_ast_pretty = { path = "../librustc_ast_pretty" }
1516
rustc_attr = { path = "../librustc_attr" }
1617
rustc_data_structures = { path = "../librustc_data_structures" }
1718
rustc_errors = { path = "../librustc_errors" }

src/librustc_builtin_macros/assert.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use rustc_errors::{Applicability, DiagnosticBuilder};
22

3+
use rustc_ast_pretty::pprust;
34
use rustc_expand::base::*;
45
use rustc_parse::parser::Parser;
56
use rustc_span::symbol::{sym, Symbol};
67
use rustc_span::{Span, DUMMY_SP};
78
use syntax::ast::{self, *};
8-
use syntax::print::pprust;
99
use syntax::ptr::P;
1010
use syntax::token::{self, TokenKind};
1111
use syntax::tokenstream::{DelimSpan, TokenStream, TokenTree};

src/librustc_builtin_macros/log_syntax.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
use rustc_ast_pretty::pprust;
12
use rustc_expand::base;
23
use rustc_span;
3-
use syntax::print;
44
use syntax::tokenstream::TokenStream;
55

66
pub fn expand_log_syntax<'cx>(
77
_cx: &'cx mut base::ExtCtxt<'_>,
88
sp: rustc_span::Span,
99
tts: TokenStream,
1010
) -> Box<dyn base::MacResult + 'cx> {
11-
println!("{}", print::pprust::tts_to_string(tts));
11+
println!("{}", pprust::tts_to_string(tts));
1212

1313
// any so that `log_syntax` can be invoked as an expression and item.
1414
base::DummyResult::any_valid(sp)

src/librustc_builtin_macros/proc_macro_harness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::mem;
22

3+
use rustc_ast_pretty::pprust;
34
use rustc_expand::base::{ExtCtxt, Resolver};
45
use rustc_expand::expand::{AstFragment, ExpansionConfig};
56
use rustc_session::parse::ParseSess;
@@ -10,7 +11,6 @@ use smallvec::smallvec;
1011
use syntax::ast::{self, Ident};
1112
use syntax::attr;
1213
use syntax::expand::is_proc_macro_attr;
13-
use syntax::print::pprust;
1414
use syntax::ptr::P;
1515
use syntax::visit::{self, Visitor};
1616

src/librustc_builtin_macros/source_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
use rustc_ast_pretty::pprust;
12
use rustc_expand::base::{self, *};
23
use rustc_expand::panictry;
34
use rustc_parse::{self, new_sub_parser_from_file, parser::Parser, DirectoryOwnership};
45
use rustc_session::lint::builtin::INCOMPLETE_INCLUDE;
56
use rustc_span::symbol::Symbol;
67
use rustc_span::{self, Pos, Span};
78
use syntax::ast;
8-
use syntax::print::pprust;
99
use syntax::ptr::P;
1010
use syntax::token;
1111
use syntax::tokenstream::TokenStream;

src/librustc_builtin_macros/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
/// Ideally, this code would be in libtest but for efficiency and error messages it lives here.
33
use crate::util::check_builtin_macro_attribute;
44

5+
use rustc_ast_pretty::pprust;
56
use rustc_expand::base::*;
67
use rustc_span::source_map::respan;
78
use rustc_span::symbol::{sym, Symbol};
89
use rustc_span::Span;
910
use syntax::ast;
1011
use syntax::attr;
11-
use syntax::print::pprust;
1212

1313
use std::iter;
1414

src/librustc_driver/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ lazy_static = "1.0"
1414
log = "0.4"
1515
env_logger = { version = "0.7", default-features = false }
1616
rustc = { path = "../librustc" }
17+
rustc_ast_pretty = { path = "../librustc_ast_pretty" }
1718
rustc_target = { path = "../librustc_target" }
1819
rustc_lint = { path = "../librustc_lint" }
1920
rustc_data_structures = { path = "../librustc_data_structures" }

src/librustc_driver/pretty.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ use rustc::session::config::{Input, PpMode, PpSourceMode};
55
use rustc::session::Session;
66
use rustc::ty::{self, TyCtxt};
77
use rustc::util::common::ErrorReported;
8+
use rustc_ast_pretty::pprust;
89
use rustc_hir as hir;
910
use rustc_hir::def_id::LOCAL_CRATE;
1011
use rustc_hir::print as pprust_hir;
1112
use rustc_mir::util::{write_mir_graphviz, write_mir_pretty};
12-
1313
use rustc_span::FileName;
1414
use syntax::ast;
15-
use syntax::print::pprust;
1615

1716
use std::cell::Cell;
1817
use std::fs::File;

src/librustc_expand/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ doctest = false
1414
rustc_serialize = { path = "../libserialize", package = "serialize" }
1515
log = "0.4"
1616
rustc_span = { path = "../librustc_span" }
17+
rustc_ast_pretty = { path = "../librustc_ast_pretty" }
1718
rustc_ast_passes = { path = "../librustc_ast_passes" }
1819
rustc_attr = { path = "../librustc_attr" }
1920
rustc_data_structures = { path = "../librustc_data_structures" }

0 commit comments

Comments
 (0)