Skip to content

Commit e68df02

Browse files
committed
syntax::print -> new crate rustc_ast_pretty
1 parent 6a6f419 commit e68df02

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

+24
Original file line numberDiff line numberDiff line change
@@ -3091,6 +3091,7 @@ dependencies = [
30913091
"rustc-rayon",
30923092
"rustc-rayon-core",
30933093
"rustc_apfloat",
3094+
"rustc_ast_pretty",
30943095
"rustc_attr",
30953096
"rustc_data_structures",
30963097
"rustc_error_codes",
@@ -3358,6 +3359,7 @@ version = "0.0.0"
33583359
dependencies = [
33593360
"log",
33603361
"rustc",
3362+
"rustc_ast_pretty",
33613363
"rustc_data_structures",
33623364
"rustc_error_codes",
33633365
"rustc_errors",
@@ -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_error_codes",
@@ -3386,10 +3389,21 @@ dependencies = [
33863389
"syntax",
33873390
]
33883391

3392+
[[package]]
3393+
name = "rustc_ast_pretty"
3394+
version = "0.0.0"
3395+
dependencies = [
3396+
"log",
3397+
"rustc_data_structures",
3398+
"rustc_span",
3399+
"syntax",
3400+
]
3401+
33893402
[[package]]
33903403
name = "rustc_attr"
33913404
version = "0.0.0"
33923405
dependencies = [
3406+
"rustc_ast_pretty",
33933407
"rustc_data_structures",
33943408
"rustc_error_codes",
33953409
"rustc_errors",
@@ -3408,6 +3422,7 @@ version = "0.0.0"
34083422
dependencies = [
34093423
"fmt_macros",
34103424
"log",
3425+
"rustc_ast_pretty",
34113426
"rustc_attr",
34123427
"rustc_data_structures",
34133428
"rustc_error_codes",
@@ -3529,6 +3544,7 @@ dependencies = [
35293544
"lazy_static 1.3.0",
35303545
"log",
35313546
"rustc",
3547+
"rustc_ast_pretty",
35323548
"rustc_codegen_utils",
35333549
"rustc_data_structures",
35343550
"rustc_error_codes",
@@ -3575,6 +3591,7 @@ version = "0.0.0"
35753591
dependencies = [
35763592
"log",
35773593
"rustc_ast_passes",
3594+
"rustc_ast_pretty",
35783595
"rustc_attr",
35793596
"rustc_data_structures",
35803597
"rustc_errors",
@@ -3605,6 +3622,7 @@ version = "0.0.0"
36053622
name = "rustc_hir"
36063623
version = "0.0.0"
36073624
dependencies = [
3625+
"rustc_ast_pretty",
36083626
"rustc_data_structures",
36093627
"rustc_errors",
36103628
"rustc_index",
@@ -3696,6 +3714,7 @@ version = "0.0.0"
36963714
dependencies = [
36973715
"log",
36983716
"rustc",
3717+
"rustc_ast_pretty",
36993718
"rustc_attr",
37003719
"rustc_data_structures",
37013720
"rustc_error_codes",
@@ -3738,6 +3757,7 @@ dependencies = [
37383757
"log",
37393758
"memmap",
37403759
"rustc",
3760+
"rustc_ast_pretty",
37413761
"rustc_attr",
37423762
"rustc_data_structures",
37433763
"rustc_error_codes",
@@ -3767,6 +3787,7 @@ dependencies = [
37673787
"polonius-engine",
37683788
"rustc",
37693789
"rustc_apfloat",
3790+
"rustc_ast_pretty",
37703791
"rustc_attr",
37713792
"rustc_data_structures",
37723793
"rustc_error_codes",
@@ -3811,6 +3832,7 @@ version = "0.0.0"
38113832
dependencies = [
38123833
"bitflags",
38133834
"log",
3835+
"rustc_ast_pretty",
38143836
"rustc_attr",
38153837
"rustc_data_structures",
38163838
"rustc_error_codes",
@@ -3882,6 +3904,7 @@ dependencies = [
38823904
"log",
38833905
"rustc",
38843906
"rustc_ast_lowering",
3907+
"rustc_ast_pretty",
38853908
"rustc_attr",
38863909
"rustc_data_structures",
38873910
"rustc_error_codes",
@@ -3904,6 +3927,7 @@ dependencies = [
39043927
"rls-data",
39053928
"rls-span",
39063929
"rustc",
3930+
"rustc_ast_pretty",
39073931
"rustc_codegen_utils",
39083932
"rustc_data_structures",
39093933
"rustc_hir",

src/librustc/Cargo.toml

+2
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

+1
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

+1-1
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;
@@ -61,7 +62,6 @@ use syntax::ast;
6162
use syntax::ast::*;
6263
use syntax::attr;
6364
use syntax::node_id::NodeMap;
64-
use syntax::print::pprust;
6565
use syntax::token::{self, Nonterminal, Token};
6666
use syntax::tokenstream::{TokenStream, TokenTree};
6767
use syntax::visit::{self, Visitor};

src/librustc_ast_passes/Cargo.toml

+1
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

+1-1
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

+16
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

+1-1
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

+6
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

+11-12
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

+2-2
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

+1
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

+1-1
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_error_codes::*;
67
use rustc_errors::{struct_span_err, Applicability, Handler};
78
use rustc_feature::{find_gated_cfg, is_builtin_attr_name, Features, GatedCfg};
@@ -11,7 +12,6 @@ use rustc_span::hygiene::Transparency;
1112
use rustc_span::{symbol::sym, symbol::Symbol, Span};
1213
use std::num::NonZeroU32;
1314
use syntax::ast::{self, Attribute, MetaItem, MetaItemKind, NestedMetaItem};
14-
use syntax::print::pprust;
1515

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

src/librustc_builtin_macros/Cargo.toml

+1
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

+1-1
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

+2-2
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

+1-1
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

+1-1
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

+1-1
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

+1
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

+1-2
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

+1
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)