diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 734a168b04..6293b11d1e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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: diff --git a/crates/proc-macro-srv/src/dylib.rs b/crates/proc-macro-srv/src/dylib.rs index e644cbe078..dd05e250c2 100644 --- a/crates/proc-macro-srv/src/dylib.rs +++ b/crates/proc-macro-srv/src/dylib.rs @@ -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>) -> io::Error { @@ -152,9 +150,9 @@ impl Expander { pub fn expand( &self, macro_name: &str, - macro_body: &tt::Subtree, - attributes: Option<&tt::Subtree>, - ) -> Result { + macro_body: &crate::tt::Subtree, + attributes: Option<&crate::tt::Subtree>, + ) -> Result { let result = self.inner.proc_macros.expand(macro_name, macro_body, attributes); result.map_err(|e| e.as_str().unwrap_or_else(|| "".to_string())) } diff --git a/crates/proc-macro-srv/src/lib.rs b/crates/proc-macro-srv/src/lib.rs index 3a71b06f84..2aac379031 100644 --- a/crates/proc-macro-srv/src/lib.rs +++ b/crates/proc-macro-srv/src/lib.rs @@ -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; diff --git a/crates/proc-macro-srv/src/proc_macros.rs b/crates/proc-macro-srv/src/proc_macros.rs index 8edf02366b..74be5c7afe 100644 --- a/crates/proc-macro-srv/src/proc_macros.rs +++ b/crates/proc-macro-srv/src/proc_macros.rs @@ -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, + ); } diff --git a/crates/proc-macro-srv/src/server.rs b/crates/proc-macro-srv/src/server.rs index 40526acf6b..b7584e1016 100644 --- a/crates/proc-macro-srv/src/server.rs +++ b/crates/proc-macro-srv/src/server.rs @@ -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; diff --git a/crates/proc-macro-srv/src/server/symbol.rs b/crates/proc-macro-srv/src/server/symbol.rs index 51dfba2ea9..99f8b1efaa 100644 --- a/crates/proc-macro-srv/src/server/symbol.rs +++ b/crates/proc-macro-srv/src/server/symbol.rs @@ -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()) } } diff --git a/crates/proc-macro-srv/src/server/token_stream.rs b/crates/proc-macro-srv/src/server/token_stream.rs index d091d43190..2589d8b64d 100644 --- a/crates/proc-macro-srv/src/server/token_stream.rs +++ b/crates/proc-macro-srv/src/server/token_stream.rs @@ -4,15 +4,15 @@ use crate::tt::{self, TokenTree}; #[derive(Debug, Default, Clone)] pub struct TokenStream { - pub token_trees: Vec, + pub(super) token_trees: Vec, } 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 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};