Fix visibilities

This commit is contained in:
Lukas Wirth 2023-03-29 11:32:36 +02:00
parent afe52d270d
commit c4582f6d18
7 changed files with 27 additions and 32 deletions

View file

@ -24,6 +24,8 @@ jobs:
runs-on: ${{ matrix.os }}
env:
CC: deny_c
# we want to build r-a on stable to check that it keeps building on stable,
# but we also want to test our proc-macro-srv which depends on nightly features
RUSTC_BOOTSTRAP: 1
strategy:

View file

@ -13,8 +13,6 @@ use object::Object;
use paths::AbsPath;
use proc_macro_api::{read_dylib_info, ProcMacroKind};
use crate::tt;
const NEW_REGISTRAR_SYMBOL: &str = "_rustc_proc_macro_decls_";
fn invalid_data_err(e: impl Into<Box<dyn std::error::Error + Send + Sync>>) -> io::Error {
@ -152,9 +150,9 @@ impl Expander {
pub fn expand(
&self,
macro_name: &str,
macro_body: &tt::Subtree,
attributes: Option<&tt::Subtree>,
) -> Result<tt::Subtree, String> {
macro_body: &crate::tt::Subtree,
attributes: Option<&crate::tt::Subtree>,
) -> Result<crate::tt::Subtree, String> {
let result = self.inner.proc_macros.expand(macro_name, macro_body, attributes);
result.map_err(|e| e.as_str().unwrap_or_else(|| "<unknown error>".to_string()))
}

View file

@ -13,6 +13,7 @@
#![cfg(feature = "sysroot-abi")]
#![feature(proc_macro_internals, proc_macro_diagnostic, proc_macro_span)]
#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)]
#![allow(unreachable_pub)]
extern crate proc_macro;

View file

@ -25,7 +25,7 @@ impl ProcMacros {
/// *`info` - RustCInfo about the compiler that was used to compile the
/// macro crate. This is the information we use to figure out
/// which ABI to return
pub fn from_lib(
pub(crate) fn from_lib(
lib: &Library,
symbol_name: String,
info: RustCInfo,
@ -37,22 +37,10 @@ impl ProcMacros {
return Ok(Self { exported_macros: macros.to_vec() });
}
// if we reached this point, versions didn't match. in testing, we
// want that to panic - this could mean that the format of `rustc
// --version` no longer matches the format of the version string
// stored in the `.rustc` section, and we want to catch that in-tree
// with `x.py test`
if cfg!(test) {
panic!(
"sysroot ABI mismatch: dylib rustc version (read from .rustc section): {:?} != proc-macro-srv version (read from 'rustc --version'): {:?}",
info.version_string, crate::RUSTC_VERSION_STRING
);
}
Err(LoadProcMacroDylibError::AbiMismatch(info.version_string))
}
pub fn expand(
pub(crate) fn expand(
&self,
macro_name: &str,
macro_body: &tt::Subtree,
@ -107,7 +95,7 @@ impl ProcMacros {
Err(proc_macro::bridge::PanicMessage::String("Nothing to expand".to_string()).into())
}
pub fn list_macros(&self) -> Vec<(String, ProcMacroKind)> {
pub(crate) fn list_macros(&self) -> Vec<(String, ProcMacroKind)> {
self.exported_macros
.iter()
.map(|proc_macro| match proc_macro {
@ -129,5 +117,11 @@ impl ProcMacros {
fn test_version_check() {
let path = paths::AbsPathBuf::assert(crate::proc_macro_test_dylib_path());
let info = proc_macro_api::read_dylib_info(&path).unwrap();
assert_eq!(info.version_string, crate::RUSTC_VERSION_STRING);
assert_eq!(
info.version_string,
crate::RUSTC_VERSION_STRING,
"sysroot ABI mismatch: dylib rustc version (read from .rustc section): {:?} != proc-macro-srv version (read from 'rustc --version'): {:?}",
info.version_string,
crate::RUSTC_VERSION_STRING,
);
}

View file

@ -14,7 +14,7 @@ use proc_macro::{
};
mod token_stream;
pub use token_stream::TokenStream;
pub(crate) use token_stream::TokenStream;
use token_stream::TokenStreamBuilder;
mod symbol;

View file

@ -12,11 +12,11 @@ thread_local! {
pub struct Symbol(u32);
impl Symbol {
pub fn intern(data: &str) -> Symbol {
pub(super) fn intern(data: &str) -> Symbol {
SYMBOL_INTERNER.with(|i| i.borrow_mut().intern(data))
}
pub fn text(&self) -> SmolStr {
pub(super) fn text(&self) -> SmolStr {
SYMBOL_INTERNER.with(|i| i.borrow().get(self).clone())
}
}

View file

@ -4,15 +4,15 @@ use crate::tt::{self, TokenTree};
#[derive(Debug, Default, Clone)]
pub struct TokenStream {
pub token_trees: Vec<TokenTree>,
pub(super) token_trees: Vec<TokenTree>,
}
impl TokenStream {
pub fn new() -> Self {
pub(crate) fn new() -> Self {
TokenStream::default()
}
pub fn with_subtree(subtree: tt::Subtree) -> Self {
pub(crate) fn with_subtree(subtree: tt::Subtree) -> Self {
if subtree.delimiter.kind != tt::DelimiterKind::Invisible {
TokenStream { token_trees: vec![TokenTree::Subtree(subtree)] }
} else {
@ -20,11 +20,11 @@ impl TokenStream {
}
}
pub fn into_subtree(self) -> tt::Subtree {
pub(crate) fn into_subtree(self) -> tt::Subtree {
tt::Subtree { delimiter: tt::Delimiter::UNSPECIFIED, token_trees: self.token_trees }
}
pub fn is_empty(&self) -> bool {
pub(super) fn is_empty(&self) -> bool {
self.token_trees.is_empty()
}
}
@ -78,12 +78,12 @@ impl Extend<TokenStream> for TokenStream {
}
}
pub struct TokenStreamBuilder {
pub(super) struct TokenStreamBuilder {
acc: TokenStream,
}
/// Public implementation details for the `TokenStream` type, such as iterators.
pub mod token_stream {
/// pub(super)lic implementation details for the `TokenStream` type, such as iterators.
pub(super) mod token_stream {
use std::str::FromStr;
use super::{tt, TokenStream, TokenTree};