about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-06-05 04:16:03 +0000
committerbors <bors@rust-lang.org>2022-06-05 04:16:03 +0000
commit656eec8785e25a7fba568dba83190df2b0981daa (patch)
tree8d66b368d4c247998bbe98c9dcb2887d331efb31 /src
parent6dadfc06fe628d7a381a52b07714a7a849a6223d (diff)
parentb76d1125d4f1596e4c4481064fa6342990f1a985 (diff)
downloadrust-656eec8785e25a7fba568dba83190df2b0981daa.tar.gz
rust-656eec8785e25a7fba568dba83190df2b0981daa.zip
Auto merge of #97391 - Urgau:cfg_accessible, r=petrochenkov
Handle more cases in cfg_accessible

This PR tries to handle more cases in the cfg_accessible implementation by only emitting a "not sure" error only if we have partially resolved a path.

This PR also adds many tests for the "not sure" cases and for private items.

r? `@petrochenkov`
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/conditional-compilation/cfg_accessible-bugs.rs18
-rw-r--r--src/test/ui/conditional-compilation/cfg_accessible-bugs.stderr16
-rw-r--r--src/test/ui/conditional-compilation/cfg_accessible-not_sure.edition2015.stderr122
-rw-r--r--src/test/ui/conditional-compilation/cfg_accessible-not_sure.edition2021.stderr122
-rw-r--r--src/test/ui/conditional-compilation/cfg_accessible-not_sure.rs89
-rw-r--r--src/test/ui/conditional-compilation/cfg_accessible-private.rs21
-rw-r--r--src/test/ui/conditional-compilation/cfg_accessible.rs38
-rw-r--r--src/test/ui/conditional-compilation/cfg_accessible.stderr45
8 files changed, 430 insertions, 41 deletions
diff --git a/src/test/ui/conditional-compilation/cfg_accessible-bugs.rs b/src/test/ui/conditional-compilation/cfg_accessible-bugs.rs
new file mode 100644
index 00000000000..ae18bc55c4f
--- /dev/null
+++ b/src/test/ui/conditional-compilation/cfg_accessible-bugs.rs
@@ -0,0 +1,18 @@
+// This test is a collection of test that should pass.
+//
+// check-fail
+
+#![feature(cfg_accessible)]
+#![feature(trait_alias)]
+
+trait TraitAlias = std::fmt::Debug + Send;
+
+// FIXME: Currently shows "cannot determine" but should be `false`
+#[cfg_accessible(unresolved)] //~ ERROR cannot determine
+const C: bool = true;
+
+// FIXME: Currently shows "not sure" but should be `false`
+#[cfg_accessible(TraitAlias::unresolved)] //~ ERROR not sure whether the path is accessible or not
+const D: bool = true;
+
+fn main() {}
diff --git a/src/test/ui/conditional-compilation/cfg_accessible-bugs.stderr b/src/test/ui/conditional-compilation/cfg_accessible-bugs.stderr
new file mode 100644
index 00000000000..81f02387835
--- /dev/null
+++ b/src/test/ui/conditional-compilation/cfg_accessible-bugs.stderr
@@ -0,0 +1,16 @@
+error: not sure whether the path is accessible or not
+  --> $DIR/cfg_accessible-bugs.rs:15:18
+   |
+LL | #[cfg_accessible(TraitAlias::unresolved)]
+   |                  ^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: the type may have associated items, but we are currently not checking them
+
+error: cannot determine whether the path is accessible or not
+  --> $DIR/cfg_accessible-bugs.rs:11:1
+   |
+LL | #[cfg_accessible(unresolved)]
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 2 previous errors
+
diff --git a/src/test/ui/conditional-compilation/cfg_accessible-not_sure.edition2015.stderr b/src/test/ui/conditional-compilation/cfg_accessible-not_sure.edition2015.stderr
new file mode 100644
index 00000000000..7d5dd589027
--- /dev/null
+++ b/src/test/ui/conditional-compilation/cfg_accessible-not_sure.edition2015.stderr
@@ -0,0 +1,122 @@
+error: not sure whether the path is accessible or not
+  --> $DIR/cfg_accessible-not_sure.rs:14:18
+   |
+LL | #[cfg_accessible(Struct::existing)]
+   |                  ^^^^^^^^^^^^^^^^
+   |
+   = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+  --> $DIR/cfg_accessible-not_sure.rs:16:18
+   |
+LL | #[cfg_accessible(Struct::unresolved)]
+   |                  ^^^^^^^^^^^^^^^^^^
+   |
+   = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+  --> $DIR/cfg_accessible-not_sure.rs:25:18
+   |
+LL | #[cfg_accessible(Union::existing)]
+   |                  ^^^^^^^^^^^^^^^
+   |
+   = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+  --> $DIR/cfg_accessible-not_sure.rs:27:18
+   |
+LL | #[cfg_accessible(Union::unresolved)]
+   |                  ^^^^^^^^^^^^^^^^^
+   |
+   = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+  --> $DIR/cfg_accessible-not_sure.rs:36:18
+   |
+LL | #[cfg_accessible(Enum::Existing::existing)]
+   |                  ^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+  --> $DIR/cfg_accessible-not_sure.rs:38:18
+   |
+LL | #[cfg_accessible(Enum::Existing::unresolved)]
+   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+  --> $DIR/cfg_accessible-not_sure.rs:40:18
+   |
+LL | #[cfg_accessible(Enum::unresolved)]
+   |                  ^^^^^^^^^^^^^^^^
+   |
+   = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+  --> $DIR/cfg_accessible-not_sure.rs:50:18
+   |
+LL | #[cfg_accessible(Trait::existing)]
+   |                  ^^^^^^^^^^^^^^^
+   |
+   = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+  --> $DIR/cfg_accessible-not_sure.rs:52:18
+   |
+LL | #[cfg_accessible(Trait::unresolved)]
+   |                  ^^^^^^^^^^^^^^^^^
+   |
+   = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+  --> $DIR/cfg_accessible-not_sure.rs:59:18
+   |
+LL | #[cfg_accessible(TypeAlias::existing)]
+   |                  ^^^^^^^^^^^^^^^^^^^
+   |
+   = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+  --> $DIR/cfg_accessible-not_sure.rs:61:18
+   |
+LL | #[cfg_accessible(TypeAlias::unresolved)]
+   |                  ^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+  --> $DIR/cfg_accessible-not_sure.rs:70:18
+   |
+LL | #[cfg_accessible(ForeignType::unresolved)]
+   |                  ^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+  --> $DIR/cfg_accessible-not_sure.rs:79:18
+   |
+LL | #[cfg_accessible(AssocType::AssocType::unresolved)]
+   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+  --> $DIR/cfg_accessible-not_sure.rs:84:18
+   |
+LL | #[cfg_accessible(u8::unresolved)]
+   |                  ^^^^^^^^^^^^^^
+   |
+   = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+  --> $DIR/cfg_accessible-not_sure.rs:86:18
+   |
+LL | #[cfg_accessible(u8::is_ascii)]
+   |                  ^^^^^^^^^^^^
+   |
+   = note: the type may have associated items, but we are currently not checking them
+
+error: aborting due to 15 previous errors
+
diff --git a/src/test/ui/conditional-compilation/cfg_accessible-not_sure.edition2021.stderr b/src/test/ui/conditional-compilation/cfg_accessible-not_sure.edition2021.stderr
new file mode 100644
index 00000000000..7d5dd589027
--- /dev/null
+++ b/src/test/ui/conditional-compilation/cfg_accessible-not_sure.edition2021.stderr
@@ -0,0 +1,122 @@
+error: not sure whether the path is accessible or not
+  --> $DIR/cfg_accessible-not_sure.rs:14:18
+   |
+LL | #[cfg_accessible(Struct::existing)]
+   |                  ^^^^^^^^^^^^^^^^
+   |
+   = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+  --> $DIR/cfg_accessible-not_sure.rs:16:18
+   |
+LL | #[cfg_accessible(Struct::unresolved)]
+   |                  ^^^^^^^^^^^^^^^^^^
+   |
+   = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+  --> $DIR/cfg_accessible-not_sure.rs:25:18
+   |
+LL | #[cfg_accessible(Union::existing)]
+   |                  ^^^^^^^^^^^^^^^
+   |
+   = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+  --> $DIR/cfg_accessible-not_sure.rs:27:18
+   |
+LL | #[cfg_accessible(Union::unresolved)]
+   |                  ^^^^^^^^^^^^^^^^^
+   |
+   = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+  --> $DIR/cfg_accessible-not_sure.rs:36:18
+   |
+LL | #[cfg_accessible(Enum::Existing::existing)]
+   |                  ^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+  --> $DIR/cfg_accessible-not_sure.rs:38:18
+   |
+LL | #[cfg_accessible(Enum::Existing::unresolved)]
+   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+  --> $DIR/cfg_accessible-not_sure.rs:40:18
+   |
+LL | #[cfg_accessible(Enum::unresolved)]
+   |                  ^^^^^^^^^^^^^^^^
+   |
+   = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+  --> $DIR/cfg_accessible-not_sure.rs:50:18
+   |
+LL | #[cfg_accessible(Trait::existing)]
+   |                  ^^^^^^^^^^^^^^^
+   |
+   = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+  --> $DIR/cfg_accessible-not_sure.rs:52:18
+   |
+LL | #[cfg_accessible(Trait::unresolved)]
+   |                  ^^^^^^^^^^^^^^^^^
+   |
+   = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+  --> $DIR/cfg_accessible-not_sure.rs:59:18
+   |
+LL | #[cfg_accessible(TypeAlias::existing)]
+   |                  ^^^^^^^^^^^^^^^^^^^
+   |
+   = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+  --> $DIR/cfg_accessible-not_sure.rs:61:18
+   |
+LL | #[cfg_accessible(TypeAlias::unresolved)]
+   |                  ^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+  --> $DIR/cfg_accessible-not_sure.rs:70:18
+   |
+LL | #[cfg_accessible(ForeignType::unresolved)]
+   |                  ^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+  --> $DIR/cfg_accessible-not_sure.rs:79:18
+   |
+LL | #[cfg_accessible(AssocType::AssocType::unresolved)]
+   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+  --> $DIR/cfg_accessible-not_sure.rs:84:18
+   |
+LL | #[cfg_accessible(u8::unresolved)]
+   |                  ^^^^^^^^^^^^^^
+   |
+   = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+  --> $DIR/cfg_accessible-not_sure.rs:86:18
+   |
+LL | #[cfg_accessible(u8::is_ascii)]
+   |                  ^^^^^^^^^^^^
+   |
+   = note: the type may have associated items, but we are currently not checking them
+
+error: aborting due to 15 previous errors
+
diff --git a/src/test/ui/conditional-compilation/cfg_accessible-not_sure.rs b/src/test/ui/conditional-compilation/cfg_accessible-not_sure.rs
new file mode 100644
index 00000000000..d68acd2451f
--- /dev/null
+++ b/src/test/ui/conditional-compilation/cfg_accessible-not_sure.rs
@@ -0,0 +1,89 @@
+// revisions: edition2015 edition2021
+// [edition2015]compile-flags: --edition=2015
+// [edition2021]compile-flags: --edition=2021
+
+#![feature(extern_types)]
+#![feature(cfg_accessible)]
+
+// Struct::unresolved - error
+
+struct Struct {
+    existing: u8,
+}
+
+#[cfg_accessible(Struct::existing)] //~ ERROR not sure
+const A: bool = true;
+#[cfg_accessible(Struct::unresolved)] //~ ERROR not sure
+const B: bool = true;
+
+// Union::unresolved - error
+
+struct Union {
+    existing: u8,
+}
+
+#[cfg_accessible(Union::existing)] //~ ERROR not sure
+const A: bool = true;
+#[cfg_accessible(Union::unresolved)] //~ ERROR not sure
+const B: bool = true;
+
+// Enum::unresolved - error
+
+enum Enum {
+    Existing { existing: u8 },
+}
+
+#[cfg_accessible(Enum::Existing::existing)] //~ ERROR not sure
+const A: bool = true;
+#[cfg_accessible(Enum::Existing::unresolved)] //~ ERROR not sure
+const B: bool = true;
+#[cfg_accessible(Enum::unresolved)] //~ ERROR not sure
+const C: bool = true;
+
+// Trait::unresolved - false or error, depending on edition (error if you can write Trait::foo
+// instead of <dyn Trait>::foo for methods like impl dyn Trait { fn foo() {} })
+
+trait Trait {}
+impl dyn Trait { fn existing() {} }
+
+// FIXME: Should be a error for edition > 2015
+#[cfg_accessible(Trait::existing)] //~ ERROR not sure
+const A: bool = true;
+#[cfg_accessible(Trait::unresolved)] //~ ERROR not sure
+const B: bool = true;
+
+// TypeAlias::unresolved - error
+
+type TypeAlias = Struct;
+
+#[cfg_accessible(TypeAlias::existing)] //~ ERROR not sure
+const A: bool = true;
+#[cfg_accessible(TypeAlias::unresolved)] //~ ERROR not sure
+const B: bool = true;
+
+// ForeignType::unresolved - error
+
+extern {
+    type ForeignType;
+}
+
+#[cfg_accessible(ForeignType::unresolved)] //~ ERROR not sure
+const A: bool = true;
+
+// AssocType::unresolved - error
+
+trait AssocType {
+    type AssocType;
+}
+
+#[cfg_accessible(AssocType::AssocType::unresolved)] //~ ERROR not sure
+const A: bool = true;
+
+// PrimitiveType::unresolved - error
+
+#[cfg_accessible(u8::unresolved)] //~ ERROR not sure
+const A: bool = true;
+#[cfg_accessible(u8::is_ascii)] //~ ERROR not sure
+const B: bool = true;
+
+fn main() {}
diff --git a/src/test/ui/conditional-compilation/cfg_accessible-private.rs b/src/test/ui/conditional-compilation/cfg_accessible-private.rs
new file mode 100644
index 00000000000..5b095675c79
--- /dev/null
+++ b/src/test/ui/conditional-compilation/cfg_accessible-private.rs
@@ -0,0 +1,21 @@
+// check-pass
+
+#![feature(cfg_accessible)]
+
+mod private {
+    struct Struct;
+    enum Enum{}
+    union Union{_a:u8}
+}
+
+#[cfg_accessible(private::Struct)]
+const A: bool = true;
+
+#[cfg_accessible(private::Enum)]
+const A: bool = true;
+
+#[cfg_accessible(private::Union)]
+const A: bool = true;
+
+const A: bool = false; // Will conflict if any of those is accessible
+fn main() {}
diff --git a/src/test/ui/conditional-compilation/cfg_accessible.rs b/src/test/ui/conditional-compilation/cfg_accessible.rs
index 07b0be5b1ae..df380d0d16f 100644
--- a/src/test/ui/conditional-compilation/cfg_accessible.rs
+++ b/src/test/ui/conditional-compilation/cfg_accessible.rs
@@ -5,20 +5,35 @@ mod m {
     struct ExistingPrivate;
 }
 
+trait Trait {
+    type Assoc;
+}
+
+enum Enum {
+    Existing,
+}
+
+#[cfg_accessible(Enum)]
+struct ExistingResolved;
+
+#[cfg_accessible(Enum::Existing)]
+struct ExistingResolvedVariant;
+
 #[cfg_accessible(m::ExistingPublic)]
 struct ExistingPublic;
 
-// FIXME: Not implemented yet.
-#[cfg_accessible(m::ExistingPrivate)] //~ ERROR not sure whether the path is accessible or not
+#[cfg_accessible(m::ExistingPrivate)]
 struct ExistingPrivate;
 
-// FIXME: Not implemented yet.
-#[cfg_accessible(m::NonExistent)] //~ ERROR not sure whether the path is accessible or not
-struct ExistingPrivate;
+#[cfg_accessible(m::NonExistent)]
+struct NonExistingPrivate;
 
 #[cfg_accessible(n::AccessibleExpanded)] // OK, `cfg_accessible` can wait and retry.
 struct AccessibleExpanded;
 
+#[cfg_accessible(Trait::Assoc)]
+struct AccessibleTraitAssoc;
+
 macro_rules! generate_accessible_expanded {
     () => {
         mod n {
@@ -29,15 +44,12 @@ macro_rules! generate_accessible_expanded {
 
 generate_accessible_expanded!();
 
-struct S {
-    field: u8,
-}
-
-// FIXME: Not implemented yet.
-#[cfg_accessible(S::field)] //~ ERROR not sure whether the path is accessible or not
-struct Field;
-
 fn main() {
     ExistingPublic;
     AccessibleExpanded;
+    AccessibleTraitAssoc;
+
+    ExistingPrivate; //~ ERROR cannot find
+    NonExistingPrivate; //~ ERROR cannot find
+    NonExistingTraitAlias; //~ ERROR cannot find
 }
diff --git a/src/test/ui/conditional-compilation/cfg_accessible.stderr b/src/test/ui/conditional-compilation/cfg_accessible.stderr
index 167765cd66e..e3731a1ad71 100644
--- a/src/test/ui/conditional-compilation/cfg_accessible.stderr
+++ b/src/test/ui/conditional-compilation/cfg_accessible.stderr
@@ -1,38 +1,27 @@
-error: not sure whether the path is accessible or not
-  --> $DIR/cfg_accessible.rs:12:18
+error[E0425]: cannot find value `ExistingPrivate` in this scope
+  --> $DIR/cfg_accessible.rs:52:5
    |
-LL | #[cfg_accessible(m::ExistingPrivate)]
-   |                  ^^^^^^^^^^^^^^^^^^
+LL |     ExistingPrivate;
+   |     ^^^^^^^^^^^^^^^ not found in this scope
    |
-note: `cfg_accessible` is not fully implemented
-  --> $DIR/cfg_accessible.rs:12:18
+note: unit struct `m::ExistingPrivate` exists but is inaccessible
+  --> $DIR/cfg_accessible.rs:5:5
    |
-LL | #[cfg_accessible(m::ExistingPrivate)]
-   |                  ^^^^^^^^^^^^^^^^^^
+LL |     struct ExistingPrivate;
+   |     ^^^^^^^^^^^^^^^^^^^^^^^ not accessible
 
-error: not sure whether the path is accessible or not
-  --> $DIR/cfg_accessible.rs:16:18
+error[E0425]: cannot find value `NonExistingPrivate` in this scope
+  --> $DIR/cfg_accessible.rs:53:5
    |
-LL | #[cfg_accessible(m::NonExistent)]
-   |                  ^^^^^^^^^^^^^^
-   |
-note: `cfg_accessible` is not fully implemented
-  --> $DIR/cfg_accessible.rs:16:18
-   |
-LL | #[cfg_accessible(m::NonExistent)]
-   |                  ^^^^^^^^^^^^^^
+LL |     NonExistingPrivate;
+   |     ^^^^^^^^^^^^^^^^^^ not found in this scope
 
-error: not sure whether the path is accessible or not
-  --> $DIR/cfg_accessible.rs:37:18
-   |
-LL | #[cfg_accessible(S::field)]
-   |                  ^^^^^^^^
-   |
-note: `cfg_accessible` is not fully implemented
-  --> $DIR/cfg_accessible.rs:37:18
+error[E0425]: cannot find value `NonExistingTraitAlias` in this scope
+  --> $DIR/cfg_accessible.rs:54:5
    |
-LL | #[cfg_accessible(S::field)]
-   |                  ^^^^^^^^
+LL |     NonExistingTraitAlias;
+   |     ^^^^^^^^^^^^^^^^^^^^^ not found in this scope
 
 error: aborting due to 3 previous errors
 
+For more information about this error, try `rustc --explain E0425`.