Rollup merge of #63114 - matthewjasper:hygienic-format-args, r=petrochenkov

Remove gensym in format_args

This also fixes some things to allow us to export opaque macros from libcore:

* Don't consider items that are only reachable through opaque macros as public/exported (so they aren't linted as needing docs)
* Mark private items reachable from the root of libcore as unstable - they are now reachable (in principle) in other crates via macros in libcore

r? @petrochenkov
This commit is contained in:
Mazdak Farrokhzad 2019-08-09 14:07:29 +02:00 committed by GitHub
commit 714c8ea9b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 310 additions and 63 deletions

View file

@ -0,0 +1,23 @@
#![feature(decl_macro)]
mod n {
pub struct B(pub(crate) p::C);
impl B {
pub fn new() -> Self {
B(p::C)
}
}
mod p {
pub struct C;
impl C {
pub fn foo(&self) -> i32 {
33
}
}
}
}
pub macro m() {
n::B::new().0.foo()
}

View file

@ -0,0 +1,11 @@
#![feature(decl_macro)]
mod n {
pub(crate) mod p {
pub fn f() -> i32 { 12 }
}
}
pub macro m() {
n::p::f()
}

View file

@ -0,0 +1,11 @@
#![feature(decl_macro)]
mod n {
pub static S: i32 = 57;
}
use n::S;
pub macro m() {
S
}

View file

@ -0,0 +1,11 @@
// Check that functions accessible through a field visible to a macro are
// considered reachable
// aux-build:nested-fn-macro.rs
// run-pass
extern crate nested_fn_macro;
fn main() {
assert_eq!(nested_fn_macro::m!(), 12);
}

View file

@ -0,0 +1,11 @@
// Check that functions visible to macros through paths with >2 segements are
// considered reachable
// aux-build:field-method-macro.rs
// run-pass
extern crate field_method_macro;
fn main() {
assert_eq!(field_method_macro::m!(), 33);
}

View file

@ -0,0 +1,21 @@
// Check that we don't require stability annotations for private modules,
// imports and fields that are accessible to opaque macros.
// check-pass
#![feature(decl_macro, staged_api)]
#![stable(feature = "test", since = "1.0.0")]
extern crate std as local_std;
use local_std::marker::Copy as LocalCopy;
mod private_mod {
#[stable(feature = "test", since = "1.0.0")]
pub struct A {
pub(crate) f: i32,
}
}
#[stable(feature = "test", since = "1.0.0")]
pub macro m() {}
fn main() {}

View file

@ -0,0 +1,19 @@
// Check that type privacy is taken into account when considering reachability
// check-pass
#![feature(decl_macro, staged_api)]
#![stable(feature = "test", since = "1.0.0")]
// Type privacy should prevent use of these in other crates, so we shouldn't
// need a stability annotation.
fn private_function() {}
struct PrivateStruct { f: () }
enum PrivateEnum { V }
union PrivateUnion { g: () }
trait PrivateTrait {}
#[stable(feature = "test", since = "1.0.0")]
pub macro m() {}
fn main() {}

View file

@ -0,0 +1,10 @@
// Check that private use statements can be used by
// run-pass
// aux-build:private-use-macro.rs
extern crate private_use_macro;
fn main() {
assert_eq!(private_use_macro::m!(), 57);
}

View file

@ -1,8 +0,0 @@
// run-pass
#![allow(non_upper_case_globals)]
pub const arg0: u8 = 1;
pub fn main() {
format!("{}", 1);
}

View file

@ -0,0 +1,12 @@
// check-pass
#![allow(non_upper_case_globals)]
#![feature(format_args_nl)]
static arg0: () = ();
fn main() {
static arg1: () = ();
format_args!("{} {:?}", 0, 1);
format_args_nl!("{} {:?}", 0, 1);
}