summaryrefslogtreecommitdiffstats
path: root/src/test/ui/definition-reachable
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/definition-reachable
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/definition-reachable')
-rw-r--r--src/test/ui/definition-reachable/auxiliary/field-method-macro.rs23
-rw-r--r--src/test/ui/definition-reachable/auxiliary/nested-fn-macro.rs11
-rw-r--r--src/test/ui/definition-reachable/auxiliary/private-use-macro.rs11
-rw-r--r--src/test/ui/definition-reachable/field-method.rs11
-rw-r--r--src/test/ui/definition-reachable/nested-fn.rs11
-rw-r--r--src/test/ui/definition-reachable/private-non-types.rs21
-rw-r--r--src/test/ui/definition-reachable/private-types.rs19
-rw-r--r--src/test/ui/definition-reachable/private-use.rs10
8 files changed, 117 insertions, 0 deletions
diff --git a/src/test/ui/definition-reachable/auxiliary/field-method-macro.rs b/src/test/ui/definition-reachable/auxiliary/field-method-macro.rs
new file mode 100644
index 000000000..30ba70bdf
--- /dev/null
+++ b/src/test/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/src/test/ui/definition-reachable/auxiliary/nested-fn-macro.rs b/src/test/ui/definition-reachable/auxiliary/nested-fn-macro.rs
new file mode 100644
index 000000000..a39e8c986
--- /dev/null
+++ b/src/test/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/src/test/ui/definition-reachable/auxiliary/private-use-macro.rs b/src/test/ui/definition-reachable/auxiliary/private-use-macro.rs
new file mode 100644
index 000000000..4f283d9c1
--- /dev/null
+++ b/src/test/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/src/test/ui/definition-reachable/field-method.rs b/src/test/ui/definition-reachable/field-method.rs
new file mode 100644
index 000000000..60e895a2f
--- /dev/null
+++ b/src/test/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/src/test/ui/definition-reachable/nested-fn.rs b/src/test/ui/definition-reachable/nested-fn.rs
new file mode 100644
index 000000000..b665b049f
--- /dev/null
+++ b/src/test/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/src/test/ui/definition-reachable/private-non-types.rs b/src/test/ui/definition-reachable/private-non-types.rs
new file mode 100644
index 000000000..a601dabcb
--- /dev/null
+++ b/src/test/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/src/test/ui/definition-reachable/private-types.rs b/src/test/ui/definition-reachable/private-types.rs
new file mode 100644
index 000000000..02c1224f4
--- /dev/null
+++ b/src/test/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/src/test/ui/definition-reachable/private-use.rs b/src/test/ui/definition-reachable/private-use.rs
new file mode 100644
index 000000000..02cff0475
--- /dev/null
+++ b/src/test/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);
+}