Skip to content

Commit 645cdca

Browse files
committed
reduce visibility of a bunch of stuff in ext::tt
1 parent 4ff32c0 commit 645cdca

File tree

7 files changed

+50
-58
lines changed

7 files changed

+50
-58
lines changed

src/librustc_resolve/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use syntax::ext::base::{self, InvocationRes, Indeterminate, SpecialDerives};
1818
use syntax::ext::base::{MacroKind, SyntaxExtension};
1919
use syntax::ext::expand::{AstFragment, AstFragmentKind, Invocation, InvocationKind};
2020
use syntax::ext::hygiene::{self, ExpnId, ExpnData, ExpnKind};
21-
use syntax::ext::tt::macro_rules;
21+
use syntax::ext::compile_declarative_macro;
2222
use syntax::feature_gate::{emit_feature_err, is_builtin_attr_name};
2323
use syntax::feature_gate::GateIssue;
2424
use syntax::symbol::{Symbol, kw, sym};
@@ -843,7 +843,7 @@ impl<'a> Resolver<'a> {
843843
/// Compile the macro into a `SyntaxExtension` and possibly replace it with a pre-defined
844844
/// extension partially or entirely for built-in macros and legacy plugin macros.
845845
crate fn compile_macro(&mut self, item: &ast::Item, edition: Edition) -> SyntaxExtension {
846-
let mut result = macro_rules::compile(
846+
let mut result = compile_declarative_macro(
847847
&self.session.parse_sess, self.session.features_untracked(), item, edition
848848
);
849849

src/libsyntax/ext/tt/macro_check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ struct MacroState<'a> {
196196
/// - `node_id` is used to emit lints
197197
/// - `span` is used when no spans are available
198198
/// - `lhses` and `rhses` should have the same length and represent the macro definition
199-
pub fn check_meta_variables(
199+
crate fn check_meta_variables(
200200
sess: &ParseSess,
201201
node_id: NodeId,
202202
span: Span,

src/libsyntax/ext/tt/macro_parser.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@
7070
//! eof: [a $( a )* a b ·]
7171
//! ```
7272
73-
pub use NamedMatch::*;
74-
pub use ParseResult::*;
73+
crate use NamedMatch::*;
74+
crate use ParseResult::*;
7575
use TokenTreeOrTokenTreeSlice::*;
7676

7777
use crate::ast::{Ident, Name};
@@ -267,7 +267,7 @@ impl<'root, 'tt> DerefMut for MatcherPosHandle<'root, 'tt> {
267267
}
268268

269269
/// Represents the possible results of an attempted parse.
270-
pub enum ParseResult<T> {
270+
crate enum ParseResult<T> {
271271
/// Parsed successfully.
272272
Success(T),
273273
/// Arm failed to match. If the second parameter is `token::Eof`, it indicates an unexpected
@@ -279,10 +279,10 @@ pub enum ParseResult<T> {
279279

280280
/// A `ParseResult` where the `Success` variant contains a mapping of `Ident`s to `NamedMatch`es.
281281
/// This represents the mapping of metavars to the token trees they bind to.
282-
pub type NamedParseResult = ParseResult<FxHashMap<Ident, NamedMatch>>;
282+
crate type NamedParseResult = ParseResult<FxHashMap<Ident, NamedMatch>>;
283283

284284
/// Count how many metavars are named in the given matcher `ms`.
285-
pub fn count_names(ms: &[TokenTree]) -> usize {
285+
crate fn count_names(ms: &[TokenTree]) -> usize {
286286
ms.iter().fold(0, |count, elt| {
287287
count + match *elt {
288288
TokenTree::Sequence(_, ref seq) => seq.num_captures,
@@ -352,7 +352,7 @@ fn initial_matcher_pos<'root, 'tt>(ms: &'tt [TokenTree], open: Span) -> MatcherP
352352
/// only on the nesting depth of `ast::TTSeq`s in the originating
353353
/// token tree it was derived from.
354354
#[derive(Debug, Clone)]
355-
pub enum NamedMatch {
355+
crate enum NamedMatch {
356356
MatchedSeq(Lrc<NamedMatchVec>, DelimSpan),
357357
MatchedNonterminal(Lrc<Nonterminal>),
358358
}
@@ -415,7 +415,7 @@ fn nameize<I: Iterator<Item = NamedMatch>>(
415415

416416
/// Generates an appropriate parsing failure message. For EOF, this is "unexpected end...". For
417417
/// other tokens, this is "unexpected token...".
418-
pub fn parse_failure_msg(tok: &Token) -> String {
418+
crate fn parse_failure_msg(tok: &Token) -> String {
419419
match tok.kind {
420420
token::Eof => "unexpected end of macro invocation".to_string(),
421421
_ => format!(
@@ -648,7 +648,7 @@ fn inner_parse_loop<'root, 'tt>(
648648
/// - `directory`: Information about the file locations (needed for the black-box parser)
649649
/// - `recurse_into_modules`: Whether or not to recurse into modules (needed for the black-box
650650
/// parser)
651-
pub fn parse(
651+
crate fn parse(
652652
sess: &ParseSess,
653653
tts: TokenStream,
654654
ms: &[TokenTree],

src/libsyntax/ext/tt/macro_rules.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const VALID_FRAGMENT_NAMES_MSG: &str = "valid fragment specifiers are \
3535
`ident`, `block`, `stmt`, `expr`, `pat`, `ty`, `lifetime`, \
3636
`literal`, `path`, `meta`, `tt`, `item` and `vis`";
3737

38-
pub struct ParserAnyMacro<'a> {
38+
crate struct ParserAnyMacro<'a> {
3939
parser: Parser<'a>,
4040

4141
/// Span of the expansion site of the macro this parser is for
@@ -45,7 +45,11 @@ pub struct ParserAnyMacro<'a> {
4545
arm_span: Span,
4646
}
4747

48-
pub fn annotate_err_with_kind(err: &mut DiagnosticBuilder<'_>, kind: AstFragmentKind, span: Span) {
48+
crate fn annotate_err_with_kind(
49+
err: &mut DiagnosticBuilder<'_>,
50+
kind: AstFragmentKind,
51+
span: Span,
52+
) {
4953
match kind {
5054
AstFragmentKind::Ty => {
5155
err.span_label(span, "this macro call doesn't expand to a type");
@@ -58,7 +62,7 @@ pub fn annotate_err_with_kind(err: &mut DiagnosticBuilder<'_>, kind: AstFragment
5862
}
5963

6064
impl<'a> ParserAnyMacro<'a> {
61-
pub fn make(mut self: Box<ParserAnyMacro<'a>>, kind: AstFragmentKind) -> AstFragment {
65+
crate fn make(mut self: Box<ParserAnyMacro<'a>>, kind: AstFragmentKind) -> AstFragment {
6266
let ParserAnyMacro { site_span, macro_ident, ref mut parser, arm_span } = *self;
6367
let fragment = panictry!(parser.parse_ast_fragment(kind, true).map_err(|mut e| {
6468
if parser.token == token::Eof && e.message().ends_with(", found `<eof>`") {
@@ -284,8 +288,8 @@ fn generic_extension<'cx>(
284288
//
285289
// Holy self-referential!
286290

287-
/// Converts a `macro_rules!` invocation into a syntax extension.
288-
pub fn compile(
291+
/// Converts a macro item into a syntax extension.
292+
pub fn compile_declarative_macro(
289293
sess: &ParseSess,
290294
features: &Features,
291295
def: &ast::Item,

src/libsyntax/ext/tt/quoted.rs

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ use std::iter::Peekable;
1616
/// Contains the sub-token-trees of a "delimited" token tree, such as the contents of `(`. Note
1717
/// that the delimiter itself might be `NoDelim`.
1818
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug)]
19-
pub struct Delimited {
20-
pub delim: token::DelimToken,
21-
pub tts: Vec<TokenTree>,
19+
crate struct Delimited {
20+
crate delim: token::DelimToken,
21+
crate tts: Vec<TokenTree>,
2222
}
2323

2424
impl Delimited {
2525
/// Returns a `self::TokenTree` with a `Span` corresponding to the opening delimiter.
26-
pub fn open_tt(&self, span: Span) -> TokenTree {
26+
crate fn open_tt(&self, span: Span) -> TokenTree {
2727
let open_span = if span.is_dummy() {
2828
span
2929
} else {
@@ -33,7 +33,7 @@ impl Delimited {
3333
}
3434

3535
/// Returns a `self::TokenTree` with a `Span` corresponding to the closing delimiter.
36-
pub fn close_tt(&self, span: Span) -> TokenTree {
36+
crate fn close_tt(&self, span: Span) -> TokenTree {
3737
let close_span = if span.is_dummy() {
3838
span
3939
} else {
@@ -44,33 +44,33 @@ impl Delimited {
4444
}
4545

4646
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug)]
47-
pub struct SequenceRepetition {
47+
crate struct SequenceRepetition {
4848
/// The sequence of token trees
49-
pub tts: Vec<TokenTree>,
49+
crate tts: Vec<TokenTree>,
5050
/// The optional separator
51-
pub separator: Option<Token>,
51+
crate separator: Option<Token>,
5252
/// Whether the sequence can be repeated zero (*), or one or more times (+)
53-
pub kleene: KleeneToken,
53+
crate kleene: KleeneToken,
5454
/// The number of `Match`s that appear in the sequence (and subsequences)
55-
pub num_captures: usize,
55+
crate num_captures: usize,
5656
}
5757

5858
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)]
59-
pub struct KleeneToken {
60-
pub span: Span,
61-
pub op: KleeneOp,
59+
crate struct KleeneToken {
60+
crate span: Span,
61+
crate op: KleeneOp,
6262
}
6363

6464
impl KleeneToken {
65-
pub fn new(op: KleeneOp, span: Span) -> KleeneToken {
65+
crate fn new(op: KleeneOp, span: Span) -> KleeneToken {
6666
KleeneToken { span, op }
6767
}
6868
}
6969

7070
/// A Kleene-style [repetition operator](http://en.wikipedia.org/wiki/Kleene_star)
7171
/// for token sequences.
7272
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
73-
pub enum KleeneOp {
73+
crate enum KleeneOp {
7474
/// Kleene star (`*`) for zero or more repetitions
7575
ZeroOrMore,
7676
/// Kleene plus (`+`) for one or more repetitions
@@ -82,7 +82,7 @@ pub enum KleeneOp {
8282
/// Similar to `tokenstream::TokenTree`, except that `$i`, `$i:ident`, and `$(...)`
8383
/// are "first-class" token trees. Useful for parsing macros.
8484
#[derive(Debug, Clone, PartialEq, RustcEncodable, RustcDecodable)]
85-
pub enum TokenTree {
85+
crate enum TokenTree {
8686
Token(Token),
8787
Delimited(DelimSpan, Lrc<Delimited>),
8888
/// A kleene-style repetition sequence
@@ -99,7 +99,7 @@ pub enum TokenTree {
9999

100100
impl TokenTree {
101101
/// Return the number of tokens in the tree.
102-
pub fn len(&self) -> usize {
102+
crate fn len(&self) -> usize {
103103
match *self {
104104
TokenTree::Delimited(_, ref delimed) => match delimed.delim {
105105
token::NoDelim => delimed.tts.len(),
@@ -110,37 +110,24 @@ impl TokenTree {
110110
}
111111
}
112112

113-
/// Returns `true` if the given token tree contains no other tokens. This is vacuously true for
114-
/// single tokens or metavar/decls, but may be false for delimited trees or sequences.
115-
pub fn is_empty(&self) -> bool {
116-
match *self {
117-
TokenTree::Delimited(_, ref delimed) => match delimed.delim {
118-
token::NoDelim => delimed.tts.is_empty(),
119-
_ => false,
120-
},
121-
TokenTree::Sequence(_, ref seq) => seq.tts.is_empty(),
122-
_ => true,
123-
}
124-
}
125-
126113
/// Returns `true` if the given token tree is delimited.
127-
pub fn is_delimited(&self) -> bool {
114+
crate fn is_delimited(&self) -> bool {
128115
match *self {
129116
TokenTree::Delimited(..) => true,
130117
_ => false,
131118
}
132119
}
133120

134121
/// Returns `true` if the given token tree is a token of the given kind.
135-
pub fn is_token(&self, expected_kind: &TokenKind) -> bool {
122+
crate fn is_token(&self, expected_kind: &TokenKind) -> bool {
136123
match self {
137124
TokenTree::Token(Token { kind: actual_kind, .. }) => actual_kind == expected_kind,
138125
_ => false,
139126
}
140127
}
141128

142129
/// Gets the `index`-th sub-token-tree. This only makes sense for delimited trees and sequences.
143-
pub fn get_tt(&self, index: usize) -> TokenTree {
130+
crate fn get_tt(&self, index: usize) -> TokenTree {
144131
match (self, index) {
145132
(&TokenTree::Delimited(_, ref delimed), _) if delimed.delim == token::NoDelim => {
146133
delimed.tts[index].clone()
@@ -160,7 +147,7 @@ impl TokenTree {
160147
}
161148

162149
/// Retrieves the `TokenTree`'s span.
163-
pub fn span(&self) -> Span {
150+
crate fn span(&self) -> Span {
164151
match *self {
165152
TokenTree::Token(Token { span, .. })
166153
| TokenTree::MetaVar(span, _)
@@ -195,7 +182,7 @@ impl TokenTree {
195182
/// # Returns
196183
///
197184
/// A collection of `self::TokenTree`. There may also be some errors emitted to `sess`.
198-
pub fn parse(
185+
crate fn parse(
199186
input: tokenstream::TokenStream,
200187
expect_matchers: bool,
201188
sess: &ParseSess,

src/libsyntax/lib.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,18 +162,19 @@ pub mod ext {
162162
mod proc_macro_server;
163163

164164
pub use syntax_pos::hygiene;
165+
pub use tt::macro_rules::compile_declarative_macro;
165166
pub mod allocator;
166167
pub mod base;
167168
pub mod build;
168169
pub mod expand;
169170
pub mod proc_macro;
170171

171-
pub mod tt {
172-
pub mod transcribe;
173-
pub mod macro_check;
174-
pub mod macro_parser;
175-
pub mod macro_rules;
176-
pub mod quoted;
172+
crate mod tt {
173+
crate mod transcribe;
174+
crate mod macro_check;
175+
crate mod macro_parser;
176+
crate mod macro_rules;
177+
crate mod quoted;
177178
}
178179
}
179180

src/libsyntax/tokenstream.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ where
6464

6565
impl TokenTree {
6666
/// Use this token tree as a matcher to parse given tts.
67-
pub fn parse(cx: &base::ExtCtxt<'_>, mtch: &[quoted::TokenTree], tts: TokenStream)
67+
crate fn parse(cx: &base::ExtCtxt<'_>, mtch: &[quoted::TokenTree], tts: TokenStream)
6868
-> macro_parser::NamedParseResult {
6969
// `None` is because we're not interpolating
7070
let directory = Directory {

0 commit comments

Comments
 (0)