From 64d98f8ee037282c35007b64c2649055c56af1db Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:03 +0200 Subject: Merging upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- .../auxiliary/field-method-macro.rs | 23 ++++++++++++++++++++++ .../auxiliary/nested-fn-macro.rs | 11 +++++++++++ .../auxiliary/private-use-macro.rs | 11 +++++++++++ tests/ui/definition-reachable/field-method.rs | 11 +++++++++++ tests/ui/definition-reachable/nested-fn.rs | 11 +++++++++++ tests/ui/definition-reachable/private-non-types.rs | 21 ++++++++++++++++++++ tests/ui/definition-reachable/private-types.rs | 19 ++++++++++++++++++ tests/ui/definition-reachable/private-use.rs | 10 ++++++++++ 8 files changed, 117 insertions(+) create mode 100644 tests/ui/definition-reachable/auxiliary/field-method-macro.rs create mode 100644 tests/ui/definition-reachable/auxiliary/nested-fn-macro.rs create mode 100644 tests/ui/definition-reachable/auxiliary/private-use-macro.rs create mode 100644 tests/ui/definition-reachable/field-method.rs create mode 100644 tests/ui/definition-reachable/nested-fn.rs create mode 100644 tests/ui/definition-reachable/private-non-types.rs create mode 100644 tests/ui/definition-reachable/private-types.rs create mode 100644 tests/ui/definition-reachable/private-use.rs (limited to 'tests/ui/definition-reachable') diff --git a/tests/ui/definition-reachable/auxiliary/field-method-macro.rs b/tests/ui/definition-reachable/auxiliary/field-method-macro.rs new file mode 100644 index 000000000..30ba70bdf --- /dev/null +++ b/tests/ui/definition-reachable/auxiliary/field-method-macro.rs @@ -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() +} diff --git a/tests/ui/definition-reachable/auxiliary/nested-fn-macro.rs b/tests/ui/definition-reachable/auxiliary/nested-fn-macro.rs new file mode 100644 index 000000000..a39e8c986 --- /dev/null +++ b/tests/ui/definition-reachable/auxiliary/nested-fn-macro.rs @@ -0,0 +1,11 @@ +#![feature(decl_macro)] + +mod n { + pub(crate) mod p { + pub fn f() -> i32 { 12 } + } +} + +pub macro m() { + n::p::f() +} diff --git a/tests/ui/definition-reachable/auxiliary/private-use-macro.rs b/tests/ui/definition-reachable/auxiliary/private-use-macro.rs new file mode 100644 index 000000000..4f283d9c1 --- /dev/null +++ b/tests/ui/definition-reachable/auxiliary/private-use-macro.rs @@ -0,0 +1,11 @@ +#![feature(decl_macro)] + +mod n { + pub static S: i32 = 57; +} + +use n::S; + +pub macro m() { + S +} diff --git a/tests/ui/definition-reachable/field-method.rs b/tests/ui/definition-reachable/field-method.rs new file mode 100644 index 000000000..60e895a2f --- /dev/null +++ b/tests/ui/definition-reachable/field-method.rs @@ -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); +} diff --git a/tests/ui/definition-reachable/nested-fn.rs b/tests/ui/definition-reachable/nested-fn.rs new file mode 100644 index 000000000..b665b049f --- /dev/null +++ b/tests/ui/definition-reachable/nested-fn.rs @@ -0,0 +1,11 @@ +// Check that functions visible to macros through paths with >2 segments 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); +} diff --git a/tests/ui/definition-reachable/private-non-types.rs b/tests/ui/definition-reachable/private-non-types.rs new file mode 100644 index 000000000..a601dabcb --- /dev/null +++ b/tests/ui/definition-reachable/private-non-types.rs @@ -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() {} diff --git a/tests/ui/definition-reachable/private-types.rs b/tests/ui/definition-reachable/private-types.rs new file mode 100644 index 000000000..02c1224f4 --- /dev/null +++ b/tests/ui/definition-reachable/private-types.rs @@ -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() {} diff --git a/tests/ui/definition-reachable/private-use.rs b/tests/ui/definition-reachable/private-use.rs new file mode 100644 index 000000000..02cff0475 --- /dev/null +++ b/tests/ui/definition-reachable/private-use.rs @@ -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); +} -- cgit v1.2.3