Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix various issues with making items reachable through macros
* Allow items to be accessible through private modules and fields when a macro can access them. * Don't mark type-private items as reachable. * Never make items exported/public via macros
- Loading branch information
1 parent
d727071
commit 8ae8bc2
Showing
9 changed files
with
276 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/test/ui/definition-reachable/auxiliary/field-method-macro.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} |
11 changes: 11 additions & 0 deletions
11
src/test/ui/definition-reachable/auxiliary/nested-fn-macro.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#![feature(decl_macro)] | ||
|
||
mod n { | ||
pub(crate) mod p { | ||
pub fn f() -> i32 { 12 } | ||
} | ||
} | ||
|
||
pub macro m() { | ||
n::p::f() | ||
} |
11 changes: 11 additions & 0 deletions
11
src/test/ui/definition-reachable/auxiliary/private-use-macro.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#![feature(decl_macro)] | ||
|
||
mod n { | ||
pub static S: i32 = 57; | ||
} | ||
|
||
use n::S; | ||
|
||
pub macro m() { | ||
S | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |