1
Fork 0

Remove crate visibility usage in compiler

This commit is contained in:
Jacob Pratt 2022-05-20 19:51:09 -04:00
parent 536020c5f9
commit 49c82f31a8
No known key found for this signature in database
GPG key ID: B80E19E4662B5AA4
186 changed files with 865 additions and 800 deletions

View file

@ -28,7 +28,7 @@ use std::iter;
use std::path::PathBuf;
use std::rc::Rc;
crate use rustc_span::hygiene::MacroKind;
pub(crate) use rustc_span::hygiene::MacroKind;
// When adding new variants, make sure to
// adjust the `visit_*` / `flat_map_*` calls in `InvocationCollector`

View file

@ -347,7 +347,7 @@ impl<'a> StripUnconfigured<'a> {
/// Gives a compiler warning when the `cfg_attr` contains no attributes and
/// is in the original source file. Gives a compiler error if the syntax of
/// the attribute is incorrect.
crate fn expand_cfg_attr(&self, attr: Attribute, recursive: bool) -> Vec<Attribute> {
pub(crate) fn expand_cfg_attr(&self, attr: Attribute, recursive: bool) -> Vec<Attribute> {
let Some((cfg_predicate, expanded_attrs)) =
rustc_parse::parse_cfg_attr(&attr, &self.sess.parse_sess) else {
return vec![];
@ -451,7 +451,7 @@ impl<'a> StripUnconfigured<'a> {
attrs.iter().all(|attr| !is_cfg(attr) || self.cfg_true(attr))
}
crate fn cfg_true(&self, attr: &Attribute) -> bool {
pub(crate) fn cfg_true(&self, attr: &Attribute) -> bool {
let meta_item = match validate_attr::parse_meta(&self.sess.parse_sess, attr) {
Ok(meta_item) => meta_item,
Err(mut err) => {
@ -465,7 +465,7 @@ impl<'a> StripUnconfigured<'a> {
}
/// If attributes are not allowed on expressions, emit an error for `attr`
crate fn maybe_emit_expr_attr_err(&self, attr: &Attribute) {
pub(crate) fn maybe_emit_expr_attr_err(&self, attr: &Attribute) {
if !self.features.map_or(true, |features| features.stmt_expr_attributes) {
let mut err = feature_err(
&self.sess.parse_sess,

View file

@ -214,7 +214,7 @@ pub enum SupportsMacroExpansion {
}
impl AstFragmentKind {
crate fn dummy(self, span: Span) -> AstFragment {
pub(crate) fn dummy(self, span: Span) -> AstFragment {
self.make_from(DummyResult::any(span)).expect("couldn't create a dummy AST fragment")
}

View file

@ -1,7 +1,6 @@
#![allow(rustc::potential_query_instability)]
#![feature(associated_type_bounds)]
#![feature(associated_type_defaults)]
#![feature(crate_visibility_modifier)]
#![feature(if_let_guard)]
#![feature(let_chains)]
#![feature(let_else)]
@ -21,7 +20,7 @@ mod placeholders;
mod proc_macro_server;
pub use mbe::macro_rules::compile_declarative_macro;
crate use rustc_span::hygiene;
pub(crate) use rustc_span::hygiene;
pub mod base;
pub mod build;
#[macro_use]
@ -30,7 +29,7 @@ pub mod expand;
pub mod module;
pub mod proc_macro;
crate mod mbe;
pub(crate) mod mbe;
// HACK(Centril, #64197): These shouldn't really be here.
// Rather, they should be with their respective modules which are defined in other crates.

View file

@ -3,12 +3,12 @@
//! why we call this module `mbe`. For external documentation, prefer the
//! official terminology: "declarative macros".
crate mod macro_check;
crate mod macro_parser;
crate mod macro_rules;
crate mod metavar_expr;
crate mod quoted;
crate mod transcribe;
pub(crate) mod macro_check;
pub(crate) mod macro_parser;
pub(crate) mod macro_rules;
pub(crate) mod metavar_expr;
pub(crate) mod quoted;
pub(crate) mod transcribe;
use metavar_expr::MetaVarExpr;
use rustc_ast::token::{Delimiter, NonterminalKind, Token, TokenKind};

View file

@ -70,8 +70,8 @@
//! eof: [a $( a )* a b ·]
//! ```
crate use NamedMatch::*;
crate use ParseResult::*;
pub(crate) use NamedMatch::*;
pub(crate) use ParseResult::*;
use crate::mbe::{KleeneOp, TokenTree};
@ -262,7 +262,7 @@ enum EofMatcherPositions {
}
/// Represents the possible results of an attempted parse.
crate enum ParseResult<T> {
pub(crate) enum ParseResult<T> {
/// Parsed successfully.
Success(T),
/// Arm failed to match. If the second parameter is `token::Eof`, it indicates an unexpected
@ -276,7 +276,7 @@ crate enum ParseResult<T> {
/// A `ParseResult` where the `Success` variant contains a mapping of
/// `MacroRulesNormalizedIdent`s to `NamedMatch`es. This represents the mapping
/// of metavars to the token trees they bind to.
crate type NamedParseResult = ParseResult<FxHashMap<MacroRulesNormalizedIdent, NamedMatch>>;
pub(crate) type NamedParseResult = ParseResult<FxHashMap<MacroRulesNormalizedIdent, NamedMatch>>;
/// Count how many metavars declarations are in `matcher`.
pub(super) fn count_metavar_decls(matcher: &[TokenTree]) -> usize {
@ -340,7 +340,7 @@ pub(super) fn count_metavar_decls(matcher: &[TokenTree]) -> usize {
/// ])
/// ```
#[derive(Debug, Clone)]
crate enum NamedMatch {
pub(crate) enum NamedMatch {
MatchedSeq(Vec<NamedMatch>),
// A metavar match of type `tt`.

View file

@ -33,7 +33,7 @@ use std::collections::hash_map::Entry;
use std::{mem, slice};
use tracing::debug;
crate struct ParserAnyMacro<'a> {
pub(crate) struct ParserAnyMacro<'a> {
parser: Parser<'a>,
/// Span of the expansion site of the macro this parser is for
@ -47,7 +47,7 @@ crate struct ParserAnyMacro<'a> {
is_local: bool,
}
crate fn annotate_err_with_kind(err: &mut Diagnostic, kind: AstFragmentKind, span: Span) {
pub(crate) fn annotate_err_with_kind(err: &mut Diagnostic, kind: AstFragmentKind, span: Span) {
match kind {
AstFragmentKind::Ty => {
err.span_label(span, "this macro call doesn't expand to a type");
@ -113,7 +113,7 @@ fn emit_frag_parse_err(
}
impl<'a> ParserAnyMacro<'a> {
crate fn make(mut self: Box<ParserAnyMacro<'a>>, kind: AstFragmentKind) -> AstFragment {
pub(crate) fn make(mut self: Box<ParserAnyMacro<'a>>, kind: AstFragmentKind) -> AstFragment {
let ParserAnyMacro {
site_span,
macro_ident,

View file

@ -9,7 +9,7 @@ use rustc_span::Span;
/// A meta-variable expression, for expansions based on properties of meta-variables.
#[derive(Debug, Clone, PartialEq, Encodable, Decodable)]
crate enum MetaVarExpr {
pub(crate) enum MetaVarExpr {
/// The number of repetitions of an identifier, optionally limited to a number
/// of outer-most repetition depths. If the depth limit is `None` then the depth is unlimited.
Count(Ident, Option<usize>),
@ -28,7 +28,7 @@ crate enum MetaVarExpr {
impl MetaVarExpr {
/// Attempt to parse a meta-variable expression from a token stream.
crate fn parse<'sess>(
pub(crate) fn parse<'sess>(
input: &TokenStream,
outer_span: Span,
sess: &'sess ParseSess,
@ -62,7 +62,7 @@ impl MetaVarExpr {
Ok(rslt)
}
crate fn ident(&self) -> Option<Ident> {
pub(crate) fn ident(&self) -> Option<Ident> {
match *self {
MetaVarExpr::Count(ident, _) | MetaVarExpr::Ignore(ident) => Some(ident),
MetaVarExpr::Index(..) | MetaVarExpr::Length(..) => None,

View file

@ -26,7 +26,7 @@ pub struct ModulePathSuccess {
pub dir_ownership: DirOwnership,
}
crate struct ParsedExternalMod {
pub(crate) struct ParsedExternalMod {
pub items: Vec<P<Item>>,
pub spans: ModSpans,
pub file_path: PathBuf,
@ -42,7 +42,7 @@ pub enum ModError<'a> {
ParserError(DiagnosticBuilder<'a, ErrorGuaranteed>),
}
crate fn parse_external_mod(
pub(crate) fn parse_external_mod(
sess: &Session,
ident: Ident,
span: Span, // The span to blame on errors.
@ -78,7 +78,7 @@ crate fn parse_external_mod(
ParsedExternalMod { items, spans, file_path, dir_path, dir_ownership }
}
crate fn mod_dir_path(
pub(crate) fn mod_dir_path(
sess: &Session,
ident: Ident,
attrs: &[Attribute],

View file

@ -22,7 +22,7 @@ fn string_to_parser(ps: &ParseSess, source_str: String) -> Parser<'_> {
new_parser_from_source_str(ps, PathBuf::from("bogofile").into(), source_str)
}
crate fn with_error_checking_parse<'a, T, F>(s: String, ps: &'a ParseSess, f: F) -> T
pub(crate) fn with_error_checking_parse<'a, T, F>(s: String, ps: &'a ParseSess, f: F) -> T
where
F: FnOnce(&mut Parser<'a>) -> PResult<'a, T>,
{
@ -33,7 +33,7 @@ where
}
/// Maps a string to tts, using a made-up filename.
crate fn string_to_stream(source_str: String) -> TokenStream {
pub(crate) fn string_to_stream(source_str: String) -> TokenStream {
let ps = ParseSess::new(FilePathMapping::empty());
source_file_to_stream(
&ps,
@ -44,7 +44,7 @@ crate fn string_to_stream(source_str: String) -> TokenStream {
}
/// Parses a string, returns a crate.
crate fn string_to_crate(source_str: String) -> ast::Crate {
pub(crate) fn string_to_crate(source_str: String) -> ast::Crate {
let ps = ParseSess::new(FilePathMapping::empty());
with_error_checking_parse(source_str, &ps, |p| p.parse_crate_mod())
}
@ -53,7 +53,7 @@ crate fn string_to_crate(source_str: String) -> ast::Crate {
/// may be deleted or replaced with other whitespace to match the pattern.
/// This function is relatively Unicode-ignorant; fortunately, the careful design
/// of UTF-8 mitigates this ignorance. It doesn't do NKF-normalization(?).
crate fn matches_codepattern(a: &str, b: &str) -> bool {
pub(crate) fn matches_codepattern(a: &str, b: &str) -> bool {
let mut a_iter = a.chars().peekable();
let mut b_iter = b.chars().peekable();
@ -109,7 +109,7 @@ struct SpanLabel {
label: &'static str,
}
crate struct Shared<T: Write> {
pub(crate) struct Shared<T: Write> {
pub data: Arc<Mutex<T>>,
}